当前位置: 首页>>代码示例>>C#>>正文


C# ODataMetadataLevel类代码示例

本文整理汇总了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
                });
            }
        }
开发者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


注:本文中的ODataMetadataLevel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。