本文整理汇总了C#中ODataMetadataLevel类的典型用法代码示例。如果您正苦于以下问题:C# ODataMetadataLevel类的具体用法?C# ODataMetadataLevel怎么用?C# ODataMetadataLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataMetadataLevel类属于命名空间,在下文中一共展示了ODataMetadataLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
});
}
}
示例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
});
}
}
示例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;
}
示例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;
}
示例5: BuildNavigationLink
public override Uri BuildNavigationLink(EntityInstanceContext context, IEdmNavigationProperty navigationProperty, ODataMetadataLevel metadataLevel)
{
if (NavigationLinkBuilder != null)
{
return NavigationLinkBuilder(context, navigationProperty, metadataLevel);
}
return null;
}
示例6: BuildReadLink
public override Uri BuildReadLink(EntityInstanceContext instanceContext, ODataMetadataLevel metadataLevel, Uri editLink)
{
if (ReadLinkBuilder != null)
{
return ReadLinkBuilder.Factory(instanceContext);
}
return null;
}
示例7: BuildIdLink
public override string BuildIdLink(EntityInstanceContext instanceContext, ODataMetadataLevel metadataLevel)
{
if (IdLinkBuilder != null)
{
return IdLinkBuilder.Factory(instanceContext);
}
return null;
}
示例8: BuildEditLink
public override Uri BuildEditLink(EntityInstanceContext instanceContext, ODataMetadataLevel metadataLevel, string idLink)
{
if (EditLinkBuilder != null)
{
return EditLinkBuilder.Factory(instanceContext);
}
return null;
}
示例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'.");
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
}
示例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
});
}
示例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);
}
}