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


C# IEdmModel.FindType方法代码示例

本文整理汇总了C#中IEdmModel.FindType方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmModel.FindType方法的具体用法?C# IEdmModel.FindType怎么用?C# IEdmModel.FindType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEdmModel的用法示例。


在下文中一共展示了IEdmModel.FindType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ODataEntityTypeSerializerTests

        public ODataEntityTypeSerializerTests()
        {
            _model = SerializationTestsHelpers.SimpleCustomerOrderModel();

            _model.SetAnnotationValue<ClrTypeAnnotation>(_model.FindType("Default.Customer"), new ClrTypeAnnotation(typeof(Customer)));
            _model.SetAnnotationValue<ClrTypeAnnotation>(_model.FindType("Default.Order"), new ClrTypeAnnotation(typeof(Order)));

            _customerSet = _model.FindDeclaredEntityContainer("Default.Container").FindEntitySet("Customers");
            _customer = new Customer()
            {
                FirstName = "Foo",
                LastName = "Bar",
                ID = 10,
            };

            ODataSerializerProvider serializerProvider = new DefaultODataSerializerProvider(_model);
            _serializer = new ODataEntityTypeSerializer(new EdmEntityTypeReference(_customerSet.ElementType, isNullable: false), serializerProvider);
            _urlHelper = new Mock<UrlHelper>(new HttpRequestMessage()).Object;
            _writeContext = new ODataSerializerContext() { EntitySet = _customerSet, UrlHelper = _urlHelper };
        }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:20,代码来源:ODataEntityTypeSerializerTests.cs

示例2: ODataEntityTypeSerializerTests

        public ODataEntityTypeSerializerTests()
        {
            _model = SerializationTestsHelpers.SimpleCustomerOrderModel();

            _model.SetAnnotationValue<ClrTypeAnnotation>(_model.FindType("Default.Customer"), new ClrTypeAnnotation(typeof(Customer)));
            _model.SetAnnotationValue<ClrTypeAnnotation>(_model.FindType("Default.Order"), new ClrTypeAnnotation(typeof(Order)));

            _customerSet = _model.FindDeclaredEntityContainer("Default.Container").FindEntitySet("Customers");
            _customer = new Customer()
            {
                FirstName = "Foo",
                LastName = "Bar",
                ID = 10,
            };

            _serializerProvider = new DefaultODataSerializerProvider();
            _customerType = _model.GetEdmTypeReference(typeof(Customer)).AsEntity();
            _serializer = new ODataEntityTypeSerializer(_serializerProvider);
            _writeContext = new ODataSerializerContext() { EntitySet = _customerSet, Model = _model };
            _entityInstanceContext = new EntityInstanceContext(_writeContext, _customerSet.ElementType.AsReference(), _customer);
        }
开发者ID:normalian,项目名称:aspnetwebstack,代码行数:21,代码来源:ODataEntityTypeSerializerTests.cs

示例3: ODataEntityTypeSerializerTests

        public ODataEntityTypeSerializerTests()
        {
            _model = SerializationTestsHelpers.SimpleCustomerOrderModel();

            _model.SetAnnotationValue<ClrTypeAnnotation>(_model.FindType("Default.Customer"), new ClrTypeAnnotation(typeof(Customer)));
            _model.SetAnnotationValue<ClrTypeAnnotation>(_model.FindType("Default.Order"), new ClrTypeAnnotation(typeof(Order)));
            _model.SetAnnotationValue(
                _model.FindType("Default.SpecialCustomer"),
                new ClrTypeAnnotation(typeof(SpecialCustomer)));
            _model.SetAnnotationValue(
                _model.FindType("Default.SpecialOrder"),
                new ClrTypeAnnotation(typeof(SpecialOrder)));

            _customerSet = _model.EntityContainer.FindEntitySet("Customers");
            _customer = new Customer()
            {
                FirstName = "Foo",
                LastName = "Bar",
                ID = 10,
            };

            _orderSet = _model.EntityContainer.FindEntitySet("Orders");
            _order = new Order
            {
                ID = 20,
            };

            _serializerProvider = new DefaultODataSerializerProvider();
            _customerType = _model.GetEdmTypeReference(typeof(Customer)).AsEntity();
            _orderType = _model.GetEdmTypeReference(typeof(Order)).AsEntity();
            _specialCustomerType = _model.GetEdmTypeReference(typeof(SpecialCustomer)).AsEntity();
            _specialOrderType = _model.GetEdmTypeReference(typeof(SpecialOrder)).AsEntity();
            _serializer = new ODataEntityTypeSerializer(_serializerProvider);
            _path = new ODataPath(new EntitySetPathSegment(_customerSet));
            _writeContext = new ODataSerializerContext() { NavigationSource = _customerSet, Model = _model, Path = _path };
            _entityInstanceContext = new EntityInstanceContext(_writeContext, _customerSet.EntityType().AsReference(), _customer);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:37,代码来源:ODataEntityTypeSerializerTests.cs

示例4: ODataCollectionSerializerTests

        public ODataCollectionSerializerTests()
        {
            _model = SerializationTestsHelpers.SimpleCustomerOrderModel();
            _customerSet = _model.FindDeclaredEntityContainer("Default.Container").FindEntitySet("Customers");
            _edmIntType = _model.FindType("Edm.Int32") as IEdmPrimitiveType;
            _customer = new Customer()
            {
                FirstName = "Foo",
                LastName = "Bar",
                ID = 10,
            };

            ODataSerializerProvider serializerProvider = new DefaultODataSerializerProvider();
            _serializer = new ODataCollectionSerializer(
                new EdmCollectionTypeReference(
                    new EdmCollectionType(
                        new EdmPrimitiveTypeReference(_edmIntType, isNullable: false)),
                        isNullable: false), serializerProvider);
        }
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:19,代码来源:ODataCollectionSerializerTests.cs

示例5: CompareMetadata

        public static void CompareMetadata(IEdmModel expectedItems, IEdmModel actualItems, bool isReflectionBasedProvider, string defaultEntityContainerName)
        {
            // Check if the version is equal
            // TODO: Remove old versions of EDM and EDMX
            //AstoriaTestLog.AreEqual(expectedItems.GetEdmVersion(), actualItems.GetEdmVersion(), "Edm version did not match");

            int totalNavProps = 0;
            foreach (var edmType in expectedItems.SchemaElements.OfType<IEdmSchemaType>())
            {
                if (edmType.TypeKind == EdmTypeKind.Primitive)
                {
                    continue;
                }

                IEdmSchemaType dataWebEdmType = null;

                // For reflection based providers, there might be more than one container in the original schema
                // and hence the metadata maynot contain all the types;
                if (null == (dataWebEdmType = actualItems.FindType(edmType.FullName())))
                {
                    if (TypeIsOrphaned(edmType, expectedItems))
                    {
                        // Type is unused, so it's OK if it's not there.
                        continue;
                    }

                    continue;
                }

                int numberOfNavProps = 0;
                CompareEdmType(edmType, dataWebEdmType, isReflectionBasedProvider, out numberOfNavProps);
                totalNavProps += numberOfNavProps;
            }

            if (isReflectionBasedProvider)
            {
                AstoriaTestLog.IsTrue(totalNavProps == actualItems.SchemaElements.OfType<IEdmStructuredType>().SelectMany(t => t.DeclaredProperties).OfType<IEdmNavigationProperty>().Count(),
                    "Number of association must be equal to number of nav properties in the model");
            }

            CompareEntityContainer(expectedItems.EntityContainer, actualItems.EntityContainer);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:42,代码来源:MetadataUtil.cs

示例6: ResolveTypeName

 private static IEdmType ResolveTypeName(IEdmModel model, IEdmType expectedType, string typeName, Func<IEdmType, string, IEdmType> customTypeResolver, ODataVersion version, out EdmTypeKind typeKind)
 {
     IEdmType collectionType = null;
     EdmTypeKind kind;
     string str = (version >= ODataVersion.V3) ? EdmLibraryExtensions.GetCollectionItemTypeName(typeName) : null;
     if (str == null)
     {
         if ((customTypeResolver != null) && model.IsUserModel())
         {
             collectionType = customTypeResolver(expectedType, typeName);
             if (collectionType == null)
             {
                 throw new ODataException(Microsoft.Data.OData.Strings.MetadataUtils_ResolveTypeName(typeName));
             }
         }
         else
         {
             collectionType = model.FindType(typeName);
         }
         if (((version < ODataVersion.V3) && (collectionType != null)) && collectionType.IsSpatial())
         {
             collectionType = null;
         }
         typeKind = (collectionType == null) ? EdmTypeKind.None : collectionType.TypeKind;
         return collectionType;
     }
     typeKind = EdmTypeKind.Collection;
     IEdmType definition = null;
     if (((customTypeResolver != null) && (expectedType != null)) && (expectedType.TypeKind == EdmTypeKind.Collection))
     {
         definition = ((IEdmCollectionType) expectedType).ElementType.Definition;
     }
     IEdmType itemType = ResolveTypeName(model, definition, str, customTypeResolver, version, out kind);
     if (itemType != null)
     {
         collectionType = EdmLibraryExtensions.GetCollectionType(itemType);
     }
     return collectionType;
 }
开发者ID:nickchal,项目名称:pash,代码行数:39,代码来源:MetadataUtils.cs

示例7: ResolveType

        public virtual IEdmSchemaType ResolveType(IEdmModel model, string typeName)
        {
            if (EnableCaseInsensitive)
            {
                var result = model.SchemaElements.OfType<IEdmSchemaType>()
               .Where(_ => string.Equals(typeName, _.FullName(), StringComparison.OrdinalIgnoreCase))
               .ToList();

                if (result.Count == 1)
                {
                    return result.Single();
                }
                else if (result.Count > 1)
                {
                    throw new ODataException(Strings.UriParserMetadata_MultipleMatchingTypesFound(typeName));
                }
            }

            return model.FindType(typeName);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:20,代码来源:ODataUriResolver.cs

示例8: GetExpectedNavigationProperty

            /// <summary>
            /// Returns the navigation property for the given payload element (only for entity reference links).
            /// </summary>
            /// <param name="expectedTypeAnnotation">The expected type annotation.</param>
            /// <param name="model">The model to get the navigation property from.</param>
            /// <returns>The expected navigation property for the specified payload element.</returns>
            private static IEdmNavigationProperty GetExpectedNavigationProperty(ExpectedTypeODataPayloadElementAnnotation expectedTypeAnnotation, IEdmModel model)
            {
                ExceptionUtilities.Assert(model != null, "model != null");

                if (expectedTypeAnnotation != null)
                {
                    if (expectedTypeAnnotation.EdmNavigationProperty != null)
                    {
                        return expectedTypeAnnotation.EdmNavigationProperty as IEdmNavigationProperty;
                    }
                    NavigationProperty expectedNavigationProperty = expectedTypeAnnotation.NavigationProperty;
                    if (expectedNavigationProperty != null)
                    {
                        NamedStructuralType expectedOwningType = expectedTypeAnnotation.OwningType;
                        ExceptionUtilities.Assert(expectedOwningType != null, "Need an owning type if a navigation property is specified.");

                        IEdmEntityType owningEntityType = model.FindType(expectedOwningType.FullName) as IEdmEntityType;
                        ExceptionUtilities.Assert(owningEntityType != null, "Did not find expected entity type in the model.");

                        IEdmNavigationProperty navigationProperty = owningEntityType.FindProperty(expectedNavigationProperty.Name) as IEdmNavigationProperty;
                        ExceptionUtilities.Assert(navigationProperty != null, "Did not find expected navigation property in the model.");

                        return navigationProperty;
                    }
                }

                return null;
            }
开发者ID:larsenjo,项目名称:odata.net,代码行数:34,代码来源:PayloadReaderTestDescriptor.cs

示例9: GetExpectedStructuralProperty

            /// <summary>
            /// Returns the structural property for the given payload element (only for properties).
            /// </summary>
            /// <param name="expectedTypeAnnotation">The expected type annotation.</param>
            /// <param name="model">The model to get the structural property from.</param>
            /// <returns>The expected structural property for the specified payload element.</returns>
            private static IEdmStructuralProperty GetExpectedStructuralProperty(ExpectedTypeODataPayloadElementAnnotation expectedTypeAnnotation, IEdmModel model)
            {
                ExceptionUtilities.Assert(model != null, "model != null");

                if (expectedTypeAnnotation != null)
                {
                    if (expectedTypeAnnotation.EdmProperty != null)
                    {
                        return expectedTypeAnnotation.EdmProperty as IEdmStructuralProperty;
                    }
                    MemberProperty expectedStructuralProperty = expectedTypeAnnotation.MemberProperty;
                    if (expectedStructuralProperty != null)
                    {
                        NamedStructuralType expectedOwningType = expectedTypeAnnotation.OwningType;
                        ExceptionUtilities.Assert(expectedOwningType != null, "Need an owning type if a structural property is specified.");

                        IEdmStructuredType owningType = model.FindType(expectedOwningType.FullName) as IEdmStructuredType;
                        ExceptionUtilities.Assert(owningType != null, "Did not find expected structured type in the model.");

                        IEdmStructuralProperty structuralProperty = owningType.FindProperty(expectedStructuralProperty.Name) as IEdmStructuralProperty;
                        ExceptionUtilities.Assert(structuralProperty != null, "Did not find expected structural property in the model.");

                        return structuralProperty;
                    }
                }

                return null;
            }
开发者ID:larsenjo,项目名称:odata.net,代码行数:34,代码来源:PayloadReaderTestDescriptor.cs

示例10: TryParseEnumMember

        /// <summary>
        /// Try parse enum members specified in a string value from declared schema types
        /// </summary>
        /// <param name="value">Enum value string</param>
        /// <param name="model">The model for resolving enum type.</param>
        /// <param name="location">The location of the enum member in csdl</param>
        /// <param name="result">Parsed enum members</param>
        /// <returns>True for successfully parsed, false for failed</returns>
        internal static bool TryParseEnumMember(string value, IEdmModel model, EdmLocation location, out IEnumerable<IEdmEnumMember> result)
        {
            result = null;
            if (value == null || model == null)
            {
                return false;
            }

            bool isUnresolved = false;
            var enumValues = value.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (!enumValues.Any())
            {
                return false;
            }

            string enumTypeName = enumValues[0].Split('/').FirstOrDefault();
            if (string.IsNullOrEmpty(enumTypeName))
            {
                return false;
            }

            IEdmEnumType enumType = model.FindType(enumTypeName) as IEdmEnumType;

            if (enumType == null)
            {
                enumType = new UnresolvedEnumType(enumTypeName, location);
                isUnresolved = true;
            }
            else if (enumValues.Count() > 1 && (!enumType.IsFlags || !EdmEnumValueParser.IsEnumIntergeType(enumType)))
            {
                return false;
            }

            List<IEdmEnumMember> enumMembers = new List<IEdmEnumMember>();
            foreach (var enumValue in enumValues)
            {
                string[] path = enumValue.Split('/');
                if (path.Count() != 2)
                {
                    return false;
                }

                if (path[0] != enumTypeName)
                {
                    return false;
                }

                if (!isUnresolved)
                {
                    IEdmEnumMember member = enumType.Members.SingleOrDefault(m => m.Name == path[1]);
                    if (member == null)
                    {
                        return false;
                    }

                    enumMembers.Add(member);
                }
                else
                {
                    enumMembers.Add(new UnresolvedEnumMember(path[1], enumType, location));
                }
            }

            result = enumMembers;
            return true;
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:74,代码来源:EdmEnumValueParser.cs

示例11: ResolveTypeName

        /// <summary>
        /// Resolves the name of a primitive, complex, entity or collection type to the respective type.
        /// </summary>
        /// <param name="model">The model to use or null if no model is available.</param>
        /// <param name="expectedType">The expected type for the type name being resolved, or null if none is available.</param>
        /// <param name="typeName">The name of the type to resolve.</param>
        /// <param name="customTypeResolver">Custom type resolver to use, if null the model is used directly.</param>
        /// <param name="version">The version to use when resolving the type name.</param>
        /// <param name="typeKind">The type kind of the type, if it could be determined. This will be None if we couldn't tell. It might be filled
        /// even if the method returns null, for example for Collection types with item types which are not recognized.</param>
        /// <returns>The <see cref="IEdmType"/> representing the type specified by the <paramref name="typeName"/>;
        /// or null if no such type could be found.</returns>
        private static IEdmType ResolveTypeName(
            IEdmModel model,
            IEdmType expectedType,
            string typeName,
            Func<IEdmType, string, IEdmType> customTypeResolver,
            ODataVersion version,
            out EdmTypeKind typeKind)
        {
            Debug.Assert(model != null, "model != null");
            Debug.Assert(typeName != null, "typeName != null");
            IEdmType resolvedType = null;

            // Collection types should only be recognized in V3 and higher.
            string itemTypeName = version >= ODataVersion.V3 ? EdmLibraryExtensions.GetCollectionItemTypeName(typeName) : null;
            if (itemTypeName == null)
            {
                // Note: we require the type resolver or the model to also resolve
                //       primitive types.
                if (customTypeResolver != null && model.IsUserModel())
                {
                    resolvedType = customTypeResolver(expectedType, typeName);
                    if (resolvedType == null)
                    {
                        // If a type resolver is specified it must never return null.
                        throw new ODataException(Strings.MetadataUtils_ResolveTypeName(typeName));
                    }
                }
                else
                {
                    resolvedType = model.FindType(typeName);
                }

                // Spatial types are only recognized in V3 and higher.
                if (version < ODataVersion.V3 && resolvedType != null && resolvedType.IsSpatial())
                {
                    resolvedType = null;
                }

                typeKind = resolvedType == null ? EdmTypeKind.None : resolvedType.TypeKind;
            }
            else
            {
                // Collection
                typeKind = EdmTypeKind.Collection;
                EdmTypeKind itemTypeKind;

                IEdmType expectedItemType = null;
                if (customTypeResolver != null && expectedType != null && expectedType.TypeKind == EdmTypeKind.Collection)
                {
                    expectedItemType = ((IEdmCollectionType)expectedType).ElementType.Definition;
                }

                IEdmType itemType = ResolveTypeName(model, expectedItemType, itemTypeName, customTypeResolver, version, out itemTypeKind);
                if (itemType != null)
                {
                    resolvedType = EdmLibraryExtensions.GetCollectionType(itemType);
                }
            }

            return resolvedType;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:73,代码来源:MetadataUtils.cs

示例12: GetColorFlagsProp

 private IEdmStructuralProperty GetColorFlagsProp(IEdmModel model)
 {
     return (IEdmStructuralProperty)((IEdmStructuredType)model
         .FindType("NS.MyEntityType"))
         .FindProperty("ColorFlags");
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:6,代码来源:EnumFilterFunctionalTests.cs

示例13: GetColorFlagsType

 private IEdmEnumType GetColorFlagsType(IEdmModel model)
 {
     return (IEdmEnumType)model.FindType("NS.ColorFlags");
 }
开发者ID:rossjempson,项目名称:odata.net,代码行数:4,代码来源:EnumFilterFunctionalTests.cs

示例14: GetEntityType

        /// <summary>
        /// Converts an entity data type to a entity type.
        /// </summary>
        /// <param name="entity">The entity data type to convert.</param>
        /// <returns>The corresponding entity type.</returns>
        private static IEdmEntityTypeReference GetEntityType(IEdmModel model, EntityDataType entityDataType)
        {
            Debug.Assert(entityDataType != null, "entityDataType != null");

            IEdmSchemaType edmType = model.FindType(entityDataType.Definition.FullName);
            ExceptionUtilities.Assert(
                edmType != null,
                "The expected entity type '{0}' was not found in the entity model for this test.",
                entityDataType.Definition.FullName);

            IEdmEntityType entityType = edmType as IEdmEntityType;
            ExceptionUtilities.Assert(
                entityType != null,
                "The expected entity type '{0}' is not defined as entity type in the test's metadata.",
                entityDataType.Definition.FullName);
            return (IEdmEntityTypeReference)entityType.ToTypeReference(entityDataType.IsNullable);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:22,代码来源:EdmModelUtils.cs

示例15: GetModel

 private static void GetModel(out IEdmModel model, out IEdmEntityTypeReference reference)
 {
     ODataModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock<ODataConventionModelBuilder>();
     EntityTypeConfiguration<TestEntity> entity = builder.EntityType<TestEntity>();
     entity.Namespace = "Test";
     entity.Name = "Entity";
     NavigationPropertyConfiguration property = entity.HasOptional(p => p.Property);
     property.Name = "Alias";
     model = builder.GetEdmModel();
     reference = new EdmEntityTypeReference((IEdmEntityType)model.FindType("Test.Entity"), false);
 }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:11,代码来源:EdmEntityObjectTest.cs


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