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


C# IEdmModel.FindDeclaredType方法代码示例

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


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

示例1: ODataComplexTypeSerializerTests

        public ODataComplexTypeSerializerTests()
        {
            _model = SerializationTestsHelpers.SimpleCustomerOrderModel();
            _address = new Address()
            {
                Street = "One Microsoft Way",
                City = "Redmond",
                State = "Washington",
                Country = "United States",
                ZipCode = "98052"
            };

            _addressType = _model.FindDeclaredType("Default.Address") as IEdmComplexType;
            _model.SetAnnotationValue(_addressType, new ClrTypeAnnotation(typeof(Address)));
            _addressTypeRef = _addressType.ToEdmTypeReference(isNullable: false).AsComplex();

            var cnAddressType = _model.FindDeclaredType("Default.CnAddress") as IEdmComplexType;
            _model.SetAnnotationValue(cnAddressType, new ClrTypeAnnotation(typeof(CnAddress)));

            var usAddressType = _model.FindDeclaredType("Default.UsAddress") as IEdmComplexType;
            _model.SetAnnotationValue(usAddressType, new ClrTypeAnnotation(typeof(UsAddress)));

            _locationType = _model.FindDeclaredType("Default.Location") as IEdmComplexType;
            _model.SetAnnotationValue(_locationType, new ClrTypeAnnotation(typeof(Location)));
            _locationTypeRef = _locationType.ToEdmTypeReference(isNullable: false).AsComplex();

            ODataSerializerProvider serializerProvider = new DefaultODataSerializerProvider();
            _serializer = new ODataComplexTypeSerializer(serializerProvider);
            TimeZoneInfoHelper.TimeZone = null;
        }
开发者ID:postoronnimw,项目名称:WebApi,代码行数:30,代码来源:ODataComplexTypeSerializerTests.cs

示例2: Build

        public void Build()
        {
            var builder = new ODataConventionModelBuilder();

            var entity = builder.EntitySet<ODataPackage>("Packages");
            entity.EntityType.HasKey(pkg => pkg.Id);
            entity.EntityType.HasKey(pkg => pkg.Version);

            var searchAction = builder.Action("Search");
            searchAction.Parameter<string>("searchTerm");
            searchAction.Parameter<string>("targetFramework");
            searchAction.Parameter<bool>("includePrerelease");
            searchAction.ReturnsCollectionFromEntitySet<ODataPackage>("Packages");

            var findPackagesAction = builder.Action("FindPackagesById");
            findPackagesAction.Parameter<string>("id");
            findPackagesAction.ReturnsCollectionFromEntitySet<ODataPackage>("Packages");

            var getUpdatesAction = builder.Action("GetUpdates");
            getUpdatesAction.Parameter<string>("packageIds");
            getUpdatesAction.Parameter<bool>("includePrerelease");
            getUpdatesAction.Parameter<bool>("includeAllVersions");
            getUpdatesAction.Parameter<string>("targetFrameworks");
            getUpdatesAction.Parameter<string>("versionConstraints");
            getUpdatesAction.ReturnsCollectionFromEntitySet<ODataPackage>("Packages");

            model = builder.GetEdmModel();
            model.SetHasDefaultStream(model.FindDeclaredType(typeof(ODataPackage).FullName) as IEdmEntityType, hasStream: true);
        }
开发者ID:battenworks,项目名称:NuGet.Lucene,代码行数:29,代码来源:NuGetWebApiODataModelBuilder.cs

示例3: Build

        public void Build()
        {
            var builder = new ODataConventionModelBuilder();

            var entity = builder.EntitySet<ODataPackage>("Packages");
            entity.EntityType.HasKey(pkg => pkg.Id);
            entity.EntityType.HasKey(pkg => pkg.Version);

            var findPackagesAction = builder.Action("FindPackagesById");
            findPackagesAction.Parameter<string>("id");
            findPackagesAction.ReturnsCollectionFromEntitySet<ODataPackage>("Packages");

            model = builder.GetEdmModel();
            model.SetHasDefaultStream(model.FindDeclaredType(typeof(ODataPackage).FullName) as IEdmEntityType, hasStream: true);
        }
开发者ID:Pliner,项目名称:TinyFeed,代码行数:15,代码来源:NuGetWebApiODataModelBuilder.cs

示例4: ODataComplexTypeSerializerTests

        public ODataComplexTypeSerializerTests()
        {
            _model = SerializationTestsHelpers.SimpleCustomerOrderModel();
            _address = new Address()
            {
                Street = "One Microsoft Way",
                City = "Redmond",
                State = "Washington",
                Country = "United States",
                ZipCode = "98052"
            };

            _addressType = _model.FindDeclaredType("Default.Address") as IEdmComplexType;

            ODataSerializerProvider serializerProvider = new DefaultODataSerializerProvider();
            _serializer = new ODataComplexTypeSerializer(new EdmComplexTypeReference(_addressType, isNullable: false), serializerProvider);
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:17,代码来源:ODataComplexTypeSerializerTests.cs

示例5: VerifyEntitySetsAndTypes

        private static void VerifyEntitySetsAndTypes(
            IEdmModel annotatedModel, 
            out IEdmEntityContainer customersContainer, 
            out IEdmEntitySet customersSet, 
            out IEdmEntityType customerType)
        {
            customersContainer = annotatedModel.EntityContainer;
            Assert.AreEqual("CustomersContainer", customersContainer.Name);

            Assert.AreEqual(1, customersContainer.EntitySets().Count());
            customersSet = customersContainer.FindEntitySet("Customers");
            Assert.IsNotNull(customersSet);

            IEnumerable<IEdmEntityType> entityTypes = annotatedModel.SchemaElements.OfType<IEdmEntityType>();
            Assert.AreEqual(1, entityTypes.Count());
            customerType = (IEdmEntityType) annotatedModel.FindDeclaredType("MyModel.Customer");
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:17,代码来源:AnnotationsTests.cs

示例6: ParseAtEntity

        /// <summary>
        /// Parses the next OData path segment following an entity.
        /// </summary>
        /// <param name="model">The model to use for path parsing.</param>
        /// <param name="previous">The previous path segment.</param>
        /// <param name="previousEdmType">The EDM type of the OData path up to the previous segment.</param>
        /// <param name="segment">The value of the segment to parse.</param>
        /// <param name="segments">The queue of pending segments.</param>
        /// <returns>A parsed representation of the segment.</returns>
        protected virtual ODataPathSegment ParseAtEntity(IEdmModel model, ODataPathSegment previous,
            IEdmType previousEdmType, string segment, Queue<string> segments)
        {
            if (previous == null)
            {
                throw Error.ArgumentNull("previous");
            }
            if (segments == null)
            {
                throw Error.ArgumentNull("segments");
            }
            if (String.IsNullOrEmpty(segment))
            {
                throw Error.Argument(SRResources.SegmentNullOrEmpty);
            }
            IEdmEntityType previousType = previousEdmType as IEdmEntityType;
            if (previousType == null)
            {
                throw Error.Argument(SRResources.PreviousSegmentMustBeEntityType, previousEdmType);
            }

            if (segment == ODataSegmentKinds.Links)
            {
                return new LinksPathSegment();
            }

            // first look for navigation properties
            IEdmNavigationProperty navigation = previousType.NavigationProperties().SingleOrDefault(np => np.Name == segment);
            if (navigation != null)
            {
                return new NavigationPathSegment(navigation);
            }

            // next look for properties
            IEdmProperty property = previousType.Properties().SingleOrDefault(p => p.Name == segment);
            if (property != null)
            {
                return new PropertyAccessPathSegment(property);
            }

            // next look for type casts
            IEdmEntityType castType = model.FindDeclaredType(segment) as IEdmEntityType;
            if (castType != null)
            {
                if (!castType.IsOrInheritsFrom(previousType) && !previousType.IsOrInheritsFrom(castType))
                {
                    throw new ODataException(Error.Format(SRResources.InvalidCastInPath, castType, previousType));
                }
                return new CastPathSegment(castType);
            }

            // finally look for bindable procedures
            IEdmEntityContainer container = ExtractEntityContainer(model);
            IEdmActionImport action = container.FindAction(segment, previousType);
            if (action != null)
            {
                return new ActionPathSegment(action);
            }

            // Try to match this to a function call
            FunctionPathSegment pathSegment = TryMatchFunctionCall(segment, segments, model, bindingType: previousType);
            if (pathSegment != null)
            {
                return pathSegment;
            }

            // Treating as an open property
            return new UnresolvedPathSegment(segment);
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:78,代码来源:DefaultODataPathHandler.cs

示例7: ParseAtEntityCollection

        /// <summary>
        /// Parses the next OData path segment following an entity collection.
        /// </summary>
        /// <param name="model">The model to use for path parsing.</param>
        /// <param name="previous">The previous path segment.</param>
        /// <param name="previousEdmType">The EDM type of the OData path up to the previous segment.</param>
        /// <param name="segment">The value of the segment to parse.</param>
        /// <param name="segments">The queue of pending segments.</param>
        /// <returns>A parsed representation of the segment.</returns>
        protected virtual ODataPathSegment ParseAtEntityCollection(IEdmModel model, ODataPathSegment previous,
            IEdmType previousEdmType, string segment, Queue<string> segments)
        {
            if (previous == null)
            {
                throw Error.ArgumentNull("previous");
            }
            if (segments == null)
            {
                throw Error.ArgumentNull("segments");
            }
            if (String.IsNullOrEmpty(segment))
            {
                throw Error.Argument(SRResources.SegmentNullOrEmpty);
            }

            if (previousEdmType == null)
            {
                throw Error.InvalidOperation(SRResources.PreviousSegmentEdmTypeCannotBeNull);
            }
            IEdmCollectionType collectionType = previousEdmType as IEdmCollectionType;
            if (collectionType == null)
            {
                throw Error.Argument(SRResources.PreviousSegmentMustBeEntityCollectionType, previousEdmType);
            }
            IEdmEntityType elementType = collectionType.ElementType.Definition as IEdmEntityType;
            if (elementType == null)
            {
                throw Error.Argument(SRResources.PreviousSegmentMustBeEntityCollectionType, previousEdmType);
            }

            // look for keys first.
            if (segment.StartsWith("(", StringComparison.Ordinal) && segment.EndsWith(")", StringComparison.Ordinal))
            {
                Contract.Assert(segment.Length >= 2);
                string value = segment.Substring(1, segment.Length - 2);
                return new KeyValuePathSegment(value);
            }

            // next look for casts
            IEdmEntityType castType = model.FindDeclaredType(segment) as IEdmEntityType;
            if (castType != null)
            {
                IEdmType previousElementType = collectionType.ElementType.Definition;
                if (!castType.IsOrInheritsFrom(previousElementType) && !previousElementType.IsOrInheritsFrom(castType))
                {
                    throw new ODataException(Error.Format(SRResources.InvalidCastInPath, castType, previousElementType));
                }
                return new CastPathSegment(castType);
            }

            // now look for bindable actions
            IEdmEntityContainer container = ExtractEntityContainer(model);
            IEdmActionImport action = container.FindAction(segment, collectionType);
            if (action != null)
            {
                return new ActionPathSegment(action);
            }

            // Try to match this to a function call
            FunctionPathSegment pathSegment = TryMatchFunctionCall(segment, segments, model, bindingType: collectionType);
            if (pathSegment != null)
            {
                return pathSegment;
            }

            throw new ODataException(Error.Format(SRResources.NoActionFoundForCollection, segment, collectionType.ElementType));
        }
开发者ID:quentez,项目名称:aspnetwebstack,代码行数:77,代码来源:DefaultODataPathHandler.cs

示例8: ComputeQueryModelReference

        /// <summary>
        /// This method is called by method call like Where/OfType/SelectMany and so on
        /// to create a model reference for whole function call.
        /// </summary>
        /// <param name="methodCall">
        /// An method call expression node.
        /// </param>
        /// <param name="source">
        /// The parameter model reference.
        /// </param>
        /// <param name="model">
        /// The edm model.
        /// </param>
        /// <returns>
        /// A reference to the model element
        /// that represents the expression node.
        /// </returns>
        private static QueryModelReference ComputeQueryModelReference(
            MethodCallExpression methodCall, QueryModelReference source, IEdmModel model)
        {
            var method = methodCall.Method;

            // source is a sequence of T and output is also a sequence of T
            var sourceType = method.GetParameters()[0].ParameterType.FindGenericType(typeof(IEnumerable<>));
            var resultType = method.ReturnType.FindGenericType(typeof(IEnumerable<>));
            if (sourceType == resultType)
            {
                return new QueryModelReference(source.EntitySet, source.Type);
            }

            Type resultElementType = null;
            if (resultType != null)
            {
                resultElementType = resultType.GenericTypeArguments[0];
            }

            // In case sourceType IEnumerable<Person> and resultType is
            // IEnumerable <SelectExpandBinder.SelectAllAndExpand<Person>>
            // or IEnumerable<SelectExpandBinder.SelectAll<Person>>
            // or IEnumerable<SelectExpandBinder.SelectSome<Person>>
            // or IEnumerable<SelectExpandBinder.SelectSomeAndInheritance<Person>>
            if (sourceType != null && resultType != null)
            {
                var resultGenericType = resultElementType;
                if (resultGenericType.IsGenericType)
                {
                    var resultFinalElementType = resultGenericType.GenericTypeArguments[0];
                    var sourceElementType = sourceType.GenericTypeArguments[0];

                    // Handle source is type of sub class and result is a base class
                    if (resultFinalElementType.IsAssignableFrom(sourceElementType))
                    {
                        return new QueryModelReference(source.EntitySet, source.Type);
                    }
                }
            }

            // In this case, the sourceType is null
            if (method.Name.Equals(MethodNameOfType))
            {
                // Did not consider multiple namespaces have same entity type case or customized namespace
                var edmEntityType = model.FindDeclaredType(resultElementType.FullName);
                var collectionType = new EdmCollectionType(
                    new EdmEntityTypeReference((IEdmEntityType)edmEntityType, false));
                return new QueryModelReference(source.EntitySet, collectionType);
            }

            // Till here, it means the result is not part of previous result and entity set will be null
            // This mean result is a collection as resultType is IEnumerable<>
            if (resultType != null)
            {
                // Did not consider multiple namespaces have same entity type case or customized namespace
                var edmElementType = model.FindDeclaredType(resultElementType.FullName);

                // This means result is collection of Entity/Complex/Enum
                IEdmTypeReference edmTypeReference = null;
                if (edmElementType != null)
                {
                    var edmType = edmElementType as IEdmType;
                    edmTypeReference = edmType.GetTypeReference();

                    if (edmTypeReference != null)
                    {
                        var collectionType = new EdmCollectionType(edmTypeReference);
                        return new QueryModelReference(null, collectionType);
                    }
                }

                // TODO Here means a collection of primitive type
            }

            // TODO Need to handle single result case
            // TODO GitHubIssue#29 : Handle projection operators in query expression
            return null;
        }
开发者ID:chinadragon0515,项目名称:RESTier,代码行数:95,代码来源:QueryExpressionContext.cs

示例9: LookupClrType

        private static Type LookupClrType(IEdmModel model, string name)
        {
            var @namespace = model.DeclaredNamespaces.SingleOrDefault<string>();
            var fullName = (string.IsNullOrEmpty(@namespace) ? "" : @namespace + ".") + name;

            var edmType = model.FindDeclaredType(fullName);
            if (edmType == null)
            {
                throw new Exception("The type was not found for the specified name.");
            }

            var annotation = model.GetAnnotationValue<ClrTypeAnnotation>(edmType);
            if (annotation == null)
            {
                throw new Exception("The CLR type cannot be resolved.");
            }

            return annotation.ClrType;
        }
开发者ID:gitter-badger,项目名称:nuclear-river,代码行数:19,代码来源:QueryExecutionTests.cs

示例10: ToTestDescriptor

            public PayloadReaderTestDescriptor ToTestDescriptor(PayloadReaderTestDescriptor.Settings settings, IEdmModel model, ODataUndeclaredPropertyBehaviorKinds undeclaredPropertyBehaviorKinds)
            {
                var cityType = model.FindDeclaredType("TestModel.CityType").ToTypeReference();
                var cities = model.EntityContainer.FindEntitySet("Cities");
                EntityInstance entity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1)
                    .ExpectedEntityType(cityType, cities)
                    .JsonRepresentation(
                        "{" +
                            "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities()/$entity\"," +
                            "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.CityType\"," +
                            "\"Id\":1," +
                            this.Json +
                        "}");
                foreach (PropertyInstance property in this.ExpectedEntity.Properties)
                {
                    entity.Add(property.DeepCopy());
                }

                ExpectedException expectedException = this.ExpectedException;
                if (this.IsLink && !undeclaredPropertyBehaviorKinds.HasFlag(ODataUndeclaredPropertyBehaviorKinds.ReportUndeclaredLinkProperty))
                {
                    expectedException = ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "UndeclaredProperty", "TestModel.CityType");
                }

                if (this.IsValue && !undeclaredPropertyBehaviorKinds.HasFlag(ODataUndeclaredPropertyBehaviorKinds.IgnoreUndeclaredValueProperty))
                {
                    expectedException = ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "UndeclaredProperty", "TestModel.CityType");
                }

                return new PayloadReaderTestDescriptor(settings)
                {
                    DebugDescription = this.DebugDescription,
                    PayloadElement = entity,
                    PayloadEdmModel = model,
                    ExpectedException = expectedException
                };
            }
开发者ID:larsenjo,项目名称:odata.net,代码行数:37,代码来源:UndelcaredPropertyReaderJsonLightTests.cs

示例11: RunStreamPropertyTest

        private void RunStreamPropertyTest(IEdmModel model, IEnumerable<StreamPropertyTestCase> testCases)
        {
            var cityType = model.FindDeclaredType("TestModel.CityType").ToTypeReference();
            var cities = model.EntityContainer.FindEntitySet("Cities");
            IEnumerable<PayloadReaderTestDescriptor> testDescriptors = testCases.Select(testCase =>
            {
                IEdmTypeReference entityType = testCase.OwningEntityType ?? cityType;
                EntityInstance entity = PayloadBuilder.Entity(entityType.FullName()).PrimitiveProperty("Id", 1)
                    .JsonRepresentation(
                        "{" +
                            "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities/" + entityType.FullName() + "()/$entity\"," +
                            "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"" + entityType.FullName() + "\"," +
                            "\"Id\": 1," +
                            testCase.Json +
                        "}")
                    .ExpectedEntityType(entityType, cities);
                foreach (NamedStreamInstance streamProperty in testCase.ExpectedEntity.Properties.OfType<NamedStreamInstance>())
                {
                    entity.Add(streamProperty.DeepCopy());
                }

                return new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = testCase.DebugDescription,
                    PayloadEdmModel =  model,
                    PayloadElement = entity,
                    ExpectedException = testCase.ExpectedException,
                    SkipTestConfiguration = tc => testCase.OnlyResponse ? tc.IsRequest : false
                };
            });

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
                {
                    if (testConfiguration.IsRequest)
                    {
                        testDescriptor = new PayloadReaderTestDescriptor(testDescriptor)
                        {
                            ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightEntryAndFeedDeserializer_StreamPropertyInRequest")
                        };
                    }

                    // These descriptors are already tailored specifically for Json Light and 
                    // do not require normalization.
                    testDescriptor.TestDescriptorNormalizers.Clear();
                    var testConfigClone = new ReaderTestConfiguration(testConfiguration);
                    testConfigClone.MessageReaderSettings.BaseUri = null;

                    testDescriptor.RunTest(testConfigClone);
                });
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:53,代码来源:StreamReferenceValueReaderJsonLightTests.cs

示例12: TryGetEntityType

 private static bool TryGetEntityType(IEdmModel model, Type type, out IEdmEntityType entityType)
 {
     var edmType = model.FindDeclaredType(type.FullName);
     entityType = edmType as IEdmEntityType;
     return entityType != null;
 }
开发者ID:kosinsky,项目名称:RESTier,代码行数:6,代码来源:ConventionBasedOperationProvider.cs

示例13: GetTypeReference

        public static IEdmTypeReference GetTypeReference(this Type type, IEdmModel model)
        {
            Type elementType;
            if (type.TryGetElementType(out elementType))
            {
                return EdmCoreModel.GetCollection(GetTypeReference(elementType, model));
            }

            var edmType = model.FindDeclaredType(type.FullName);

            var enumType = edmType as IEdmEnumType;
            if (enumType != null)
            {
                return new EdmEnumTypeReference(enumType, true);
            }

            var complexType = edmType as IEdmComplexType;
            if (complexType != null)
            {
                return new EdmComplexTypeReference(complexType, true);
            }

            var entityType = edmType as IEdmEntityType;
            if (entityType != null)
            {
                return new EdmEntityTypeReference(entityType, true);
            }

            return type.GetPrimitiveTypeReference();
        }
开发者ID:chinadragon0515,项目名称:RESTier,代码行数:30,代码来源:Extensions.cs


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