本文整理汇总了C#中ODataMetadataLevel类的典型用法代码示例。如果您正苦于以下问题:C# ODataMetadataLevel类的具体用法?C# ODataMetadataLevel怎么用?C# ODataMetadataLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataMetadataLevel类属于命名空间,在下文中一共展示了ODataMetadataLevel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AddTypeNameAnnotationAsNeeded
internal static void AddTypeNameAnnotationAsNeeded(ODataPrimitiveValue primitive,
ODataMetadataLevel metadataLevel)
{
Contract.Assert(primitive != null);
object value = primitive.Value;
// Don't add a type name annotation for Atom or JSON verbose.
if (metadataLevel != ODataMetadataLevel.Default)
{
string typeName;
if (ShouldSuppressTypeNameSerialization(value, metadataLevel))
{
typeName = null;
}
else
{
typeName = GetTypeName(value);
}
primitive.SetAnnotation<SerializationTypeNameAnnotation>(new SerializationTypeNameAnnotation
{
TypeName = typeName
});
}
}
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:27,代码来源:ODataPrimitiveSerializer.cs
示例2: AddTypeNameAnnotationAsNeeded
internal static void AddTypeNameAnnotationAsNeeded(ODataComplexValue value, ODataMetadataLevel metadataLevel)
{
// ODataLib normally has the caller decide whether or not to serialize properties by leaving properties
// null when values should not be serialized. The TypeName property is different and should always be
// provided to ODataLib to enable model validation. A separate annotation is used to decide whether or not
// to serialize the type name (a null value prevents serialization).
// Note that this annotation should not be used for Atom or JSON verbose formats, as it will interfere with
// the correct default behavior for those formats.
Contract.Assert(value != null);
// Only add an annotation if we want to override ODataLib's default type name serialization behavior.
if (ShouldAddTypeNameAnnotation(metadataLevel))
{
string typeName;
// Provide the type name to serialize (or null to force it not to serialize).
if (ShouldSuppressTypeNameSerialization(metadataLevel))
{
typeName = null;
}
else
{
typeName = value.TypeName;
}
value.SetAnnotation<SerializationTypeNameAnnotation>(new SerializationTypeNameAnnotation
{
TypeName = typeName
});
}
}
开发者ID:Rhombulus,项目名称:aspnetwebstack,代码行数:33,代码来源:ODataComplexTypeSerializer.cs
示例3: BuildEntitySelfLinks
public virtual EntitySelfLinks BuildEntitySelfLinks(EntityInstanceContext instanceContext, ODataMetadataLevel metadataLevel)
{
EntitySelfLinks selfLinks = new EntitySelfLinks();
selfLinks.IdLink = BuildIdLink(instanceContext, metadataLevel);
selfLinks.EditLink = BuildEditLink(instanceContext, metadataLevel, selfLinks.IdLink);
selfLinks.ReadLink = BuildReadLink(instanceContext, metadataLevel, selfLinks.EditLink);
return selfLinks;
}
开发者ID:sujiantao,项目名称:aspnetwebstack,代码行数:8,代码来源:EntitySetLinkBuilderAnnotation.cs
示例4: ShouldAddTypeNameAnnotation
private static bool ShouldAddTypeNameAnnotation(ODataMetadataLevel metadataLevel)
{
// Don't interfere with the correct default behavior in non-JSON light formats.
// In all JSON light modes, take control of type name serialization.
// For primitives (unlike other types), the default behavior does not matches the requirements for minimal
// metadata mode, so the annotation is needed even in minimal metadata mode.
return metadataLevel != ODataMetadataLevel.Default;
}
开发者ID:Rhombulus,项目名称:aspnetwebstack,代码行数:8,代码来源:ODataPrimitiveSerializer.cs
示例5: BuildNavigationLink
public override Uri BuildNavigationLink(EntityInstanceContext context, IEdmNavigationProperty navigationProperty, ODataMetadataLevel metadataLevel)
{
if (NavigationLinkBuilder != null)
{
return NavigationLinkBuilder(context, navigationProperty, metadataLevel);
}
return null;
}
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:9,代码来源:MockEntitySetLinkBuilderAnnotation.cs
示例6: BuildReadLink
public override Uri BuildReadLink(EntityInstanceContext instanceContext, ODataMetadataLevel metadataLevel, Uri editLink)
{
if (ReadLinkBuilder != null)
{
return ReadLinkBuilder.Factory(instanceContext);
}
return null;
}
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:9,代码来源:MockEntitySetLinkBuilderAnnotation.cs
示例7: BuildIdLink
public override string BuildIdLink(EntityInstanceContext instanceContext, ODataMetadataLevel metadataLevel)
{
if (IdLinkBuilder != null)
{
return IdLinkBuilder.Factory(instanceContext);
}
return null;
}
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:9,代码来源:MockEntitySetLinkBuilderAnnotation.cs
示例8: BuildEditLink
public override Uri BuildEditLink(EntityInstanceContext instanceContext, ODataMetadataLevel metadataLevel, string idLink)
{
if (EditLinkBuilder != null)
{
return EditLinkBuilder.Factory(instanceContext);
}
return null;
}
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:9,代码来源:MockEntitySetLinkBuilderAnnotation.cs
示例9: BuildIdLink_Throws_IfIdLinkBuilderIsNull
public void BuildIdLink_Throws_IfIdLinkBuilderIsNull(ODataMetadataLevel metadataLevel)
{
// Arrange
NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(_entitySet);
// Act & Assert
Assert.Throws<InvalidOperationException>(
() => linkBuilder.BuildIdLink(new EntityInstanceContext(), (ODataMetadataLevel)metadataLevel),
"No IdLink factory was found. Try calling HasIdLink on the NavigationSourceConfiguration for 'Customers'.");
}
开发者ID:richarddwelsh,项目名称:aspnetwebstack,代码行数:10,代码来源:NavigationSourceLinkBuilderAnnotationTest.cs
示例10: CreatePrimitive
internal static ODataValue CreatePrimitive(object value, ODataMetadataLevel metadataLevel)
{
if (value == null)
{
return new ODataNullValue();
}
object supportedValue = ConvertUnsupportedPrimitives(value);
ODataPrimitiveValue primitive = new ODataPrimitiveValue(supportedValue);
AddTypeNameAnnotationAsNeeded(primitive, metadataLevel);
return primitive;
}
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:12,代码来源:ODataPrimitiveSerializer.cs
示例11: AddTypeNameAnnotationAsNeeded_DoesNotAddAnnotation
public void AddTypeNameAnnotationAsNeeded_DoesNotAddAnnotation(ODataMetadataLevel metadataLevel)
{
// Arrange
ODataEnumValue enumValue = new ODataEnumValue("value");
IEdmEnumTypeReference enumType = new EdmEnumTypeReference(
new EdmEnumType("TestModel", "EnumType"), isNullable: false);
// Act
ODataEnumSerializer.AddTypeNameAnnotationAsNeeded(enumValue, enumType, metadataLevel);
// Assert
SerializationTypeNameAnnotation annotation = enumValue.GetAnnotation<SerializationTypeNameAnnotation>();
Assert.Null(annotation);
}
开发者ID:richarddwelsh,项目名称:aspnetwebstack,代码行数:14,代码来源:ODataEnumTypeSerializerTests.cs
示例12: BuildIdLink
public void BuildIdLink(bool followsConventions, ODataMetadataLevel metadataLevel, bool linkEmitted)
{
// Arrange
_entitySet.HasIdLink(new SelfLinkBuilder<Uri>((context) => new Uri("http://selflink"), followsConventions));
NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(_entitySet);
// Act
Uri generatedIdLink = linkBuilder.BuildIdLink(new EntityInstanceContext(), (ODataMetadataLevel)metadataLevel);
// Assert
if (linkEmitted)
{
Assert.Equal(new Uri("http://selflink"), generatedIdLink);
}
else
{
Assert.Null(generatedIdLink);
}
}
开发者ID:shailendra9,项目名称:WebApi,代码行数:19,代码来源:NavigationSourceLinkBuilderAnnotationTest.cs
示例13: BuildIdLink
public virtual string BuildIdLink(EntityInstanceContext instanceContext, ODataMetadataLevel metadataLevel)
{
if (instanceContext == null)
{
throw Error.ArgumentNull("instanceContext");
}
if (_idLinkBuilder == null)
{
throw Error.InvalidOperation(SRResources.NoIdLinkFactoryFound, _entitySet.Name);
}
if (IsDefaultOrFull(metadataLevel) || (IsMinimal(metadataLevel) && !_idLinkBuilder.FollowsConventions))
{
return _idLinkBuilder.Factory(instanceContext);
}
else
{
// client can infer it and didn't ask for it.
return null;
}
}
开发者ID:sujiantao,项目名称:aspnetwebstack,代码行数:22,代码来源:EntitySetLinkBuilderAnnotation.cs
示例14: AddTypeNameAnnotationAsNeeded
internal static void AddTypeNameAnnotationAsNeeded(ODataPrimitiveValue primitive, IEdmPrimitiveTypeReference primitiveType,
ODataMetadataLevel metadataLevel)
{
// ODataLib normally has the caller decide whether or not to serialize properties by leaving properties
// null when values should not be serialized. The TypeName property is different and should always be
// provided to ODataLib to enable model validation. A separate annotation is used to decide whether or not
// to serialize the type name (a null value prevents serialization).
Contract.Assert(primitive != null);
object value = primitive.Value;
string typeName = null; // Set null to force the type name not to serialize.
// Provide the type name to serialize.
if (!ShouldSuppressTypeNameSerialization(value, metadataLevel))
{
typeName = primitiveType.FullName();
}
primitive.SetAnnotation<SerializationTypeNameAnnotation>(new SerializationTypeNameAnnotation
{
TypeName = typeName
});
}
开发者ID:billwaddyjr,项目名称:WebApi,代码行数:24,代码来源:ODataPrimitiveSerializer.cs
示例15: ShouldSuppressTypeNameSerialization
internal static bool ShouldSuppressTypeNameSerialization(ODataEntry entry, IEdmEntityType edmType,
ODataMetadataLevel metadataLevel)
{
Contract.Assert(entry != null);
switch (metadataLevel)
{
case ODataMetadataLevel.NoMetadata:
return true;
case ODataMetadataLevel.FullMetadata:
return false;
case ODataMetadataLevel.MinimalMetadata:
default: // All values already specified; just keeping the compiler happy.
string pathTypeName = null;
if (edmType != null)
{
pathTypeName = edmType.FullName();
}
string entryTypeName = entry.TypeName;
return String.Equals(entryTypeName, pathTypeName, StringComparison.Ordinal);
}
}
开发者ID:BarclayII,项目名称:WebApi,代码行数:22,代码来源:ODataEntityTypeSerializer.cs
示例16: ShouldOmitAction
internal static bool ShouldOmitAction(IEdmAction action, ActionLinkBuilder builder,
ODataMetadataLevel metadataLevel)
{
Contract.Assert(builder != null);
switch (metadataLevel)
{
case ODataMetadataLevel.MinimalMetadata:
case ODataMetadataLevel.NoMetadata:
return action.IsBound && builder.FollowsConventions;
case ODataMetadataLevel.FullMetadata:
default: // All values already specified; just keeping the compiler happy.
return false;
}
}
开发者ID:BarclayII,项目名称:WebApi,代码行数:16,代码来源:ODataEntityTypeSerializer.cs
示例17: AddTypeNameAnnotationAsNeeded
internal static void AddTypeNameAnnotationAsNeeded(ODataEntry entry, IEdmEntityType odataPathType,
ODataMetadataLevel metadataLevel)
{
// ODataLib normally has the caller decide whether or not to serialize properties by leaving properties
// null when values should not be serialized. The TypeName property is different and should always be
// provided to ODataLib to enable model validation. A separate annotation is used to decide whether or not
// to serialize the type name (a null value prevents serialization).
// Note: In the current version of ODataLib the default behavior likely now matches the requirements for
// minimal metadata mode. However, there have been behavior changes/bugs there in the past, so the safer
// option is for this class to take control of type name serialization in minimal metadata mode.
Contract.Assert(entry != null);
string typeName = null; // Set null to force the type name not to serialize.
// Provide the type name to serialize.
if (!ShouldSuppressTypeNameSerialization(entry, odataPathType, metadataLevel))
{
typeName = entry.TypeName;
}
entry.SetAnnotation<SerializationTypeNameAnnotation>(new SerializationTypeNameAnnotation
{
TypeName = typeName
});
}
开发者ID:BarclayII,项目名称:WebApi,代码行数:27,代码来源:ODataEntityTypeSerializer.cs
示例18: ShouldSuppressTypeNameSerialization
private static bool ShouldSuppressTypeNameSerialization(ODataMetadataLevel metadataLevel)
{
Contract.Assert(metadataLevel != ODataMetadataLevel.MinimalMetadata);
switch (metadataLevel)
{
case ODataMetadataLevel.NoMetadata:
return true;
case ODataMetadataLevel.FullMetadata:
default:
return false;
}
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:13,代码来源:ODataEnumSerializer.cs
示例19: ShouldAddTypeNameAnnotation
private static bool ShouldAddTypeNameAnnotation(ODataMetadataLevel metadataLevel)
{
switch (metadataLevel)
{
case ODataMetadataLevel.MinimalMetadata:
return false;
case ODataMetadataLevel.FullMetadata:
case ODataMetadataLevel.NoMetadata:
default:
return true;
}
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:12,代码来源:ODataEnumSerializer.cs
示例20: AddTypeNameAnnotationAsNeeded
internal static void AddTypeNameAnnotationAsNeeded(ODataEnumValue enumValue, IEdmEnumTypeReference enumType, ODataMetadataLevel metadataLevel)
{
// ODataLib normally has the caller decide whether or not to serialize properties by leaving properties
// null when values should not be serialized. The TypeName property is different and should always be
// provided to ODataLib to enable model validation. A separate annotation is used to decide whether or not
// to serialize the type name (a null value prevents serialization).
Contract.Assert(enumValue != null);
// Only add an annotation if we want to override ODataLib's default type name serialization behavior.
if (ShouldAddTypeNameAnnotation(metadataLevel))
{
string typeName;
// Provide the type name to serialize (or null to force it not to serialize).
if (ShouldSuppressTypeNameSerialization(metadataLevel))
{
typeName = null;
}
else
{
typeName = enumType.FullName();
}
enumValue.SetAnnotation(new SerializationTypeNameAnnotation
{
TypeName = typeName
});
}
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:30,代码来源:ODataEnumSerializer.cs
注:本文中的ODataMetadataLevel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论