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


C# Providers.ResourceType类代码示例

本文整理汇总了C#中Microsoft.OData.Service.Providers.ResourceType的典型用法代码示例。如果您正苦于以下问题:C# ResourceType类的具体用法?C# ResourceType怎么用?C# ResourceType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ResourceType类属于Microsoft.OData.Service.Providers命名空间,在下文中一共展示了ResourceType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OperationLinkBuilderTests

        public OperationLinkBuilderTests()
        {
            ResourceType intType = ResourceType.GetPrimitiveResourceType(typeof(int));

            var customerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "FQ.NS", "Customer", false);
            customerType.CanReflectOnInstanceType = false;
            customerType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, intType) { CanReflectOnInstanceTypeProperty = false });
            customerType.SetReadOnly();

            var operation = new ServiceAction("Action", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", customerType), new ServiceActionParameter("P2", intType) }, null);
            operation.SetReadOnly();
            this.operationWithParameters = new OperationWrapper(operation);

            var typeWithEscapedName = new ResourceType(typeof(object), ResourceTypeKind.ComplexType, null, "FQ NS", "+ /", false);
            typeWithEscapedName.CanReflectOnInstanceType = false;
            typeWithEscapedName.AddProperty(new ResourceProperty("Number", ResourcePropertyKind.Primitive, intType) { CanReflectOnInstanceTypeProperty = false });
            typeWithEscapedName.SetReadOnly();

            operation = new ServiceAction("Action", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", customerType), new ServiceActionParameter("P2", typeWithEscapedName) }, null);
            operation.SetReadOnly();
            this.operationWithEscapedParameter = new OperationWrapper(operation);

            var bestCustomerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, customerType, "FQ.NS", "BestCustomer", false);
            bestCustomerType.SetReadOnly();

            operation = new ServiceAction("Action", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", customerType) }, null);
            operation.SetReadOnly();
            this.operationBoundToBaseType = new OperationWrapper(operation);

            this.entityToSerialize = EntityToSerialize.CreateFromExplicitValues(new object(), bestCustomerType, new TestSerializedEntityKey("http://odata.org/Service.svc/Customers/", bestCustomerType.FullName));

            var metadataUri = new Uri("http://odata.org/Service.svc/$metadata");
            this.testSubject = new OperationLinkBuilder("MyContainer", metadataUri);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:34,代码来源:OperationLinkBuilderTests.cs

示例2: Init

        public void Init()
        {
            this.baseType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Fake.NS", "BaseType", false) {CanReflectOnInstanceType = false};
            this.baseType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false });
            this.baseType.SetReadOnly();
            
            this.entityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, this.baseType, "Fake.NS", "Type", false) {CanReflectOnInstanceType = false};
            this.entityType.SetReadOnly();

            this.derivedType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, this.entityType, "Fake.NS", "DerivedType", false) { CanReflectOnInstanceType = false };
            this.derivedType.SetReadOnly();

            var resourceSet = new ResourceSet("Set", this.entityType);
            resourceSet.SetReadOnly();
            this.resourceSetWrapper = ResourceSetWrapper.CreateForTests(resourceSet);

            this.action = new ServiceAction("Fake", ResourceType.GetPrimitiveResourceType(typeof(int)), OperationParameterBindingKind.Sometimes, new[] {new ServiceActionParameter("p1", this.entityType)}, null);
            this.action.SetReadOnly();
            this.actionWrapper = new OperationWrapper(action);

            this.derivedAction = new ServiceAction("Fake", ResourceType.GetPrimitiveResourceType(typeof(int)), OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("p1", this.derivedType) }, null);
            this.derivedAction.SetReadOnly();
            this.derivedActionWrapper = new OperationWrapper(derivedAction);

            this.testSubject = new SelectedOperationsCache();
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:26,代码来源:SelectedOperationsCacheTests.cs

示例3: RootProjectionNode

        /// <summary>Creates new root node for the projection tree.</summary>
        /// <param name="resourceSetWrapper">The resource set of the root level of the query.</param>
        /// <param name="orderingInfo">The ordering info for this node. null means no ordering to be applied.</param>
        /// <param name="filter">The filter for this node. null means no filter to be applied.</param>
        /// <param name="skipCount">Number of results to skip. null means no results to be skipped.</param>
        /// <param name="takeCount">Maximum number of results to return. null means return all available results.</param>
        /// <param name="maxResultsExpected">Maximum number of expected results. Hint that the provider should return
        /// at least maxResultsExpected + 1 results (if available).</param>
        /// <param name="expandPaths">The list of expanded paths.</param>
        /// <param name="baseResourceType">The resource type for all entities in this query.</param>
        /// <param name="selectExpandClause">The select expand clause for the current node from the URI Parser.</param>
        internal RootProjectionNode(
            ResourceSetWrapper resourceSetWrapper,
            OrderingInfo orderingInfo,
            Expression filter,
            int? skipCount,
            int? takeCount,
            int? maxResultsExpected,
            List<ExpandSegmentCollection> expandPaths,
            ResourceType baseResourceType,
            SelectExpandClause selectExpandClause)
            : base(
                String.Empty,
                null,
                null,
                resourceSetWrapper,
                orderingInfo,
                filter,
                skipCount,
                takeCount,
                maxResultsExpected,
                selectExpandClause)
        {
            Debug.Assert(baseResourceType != null, "baseResourceType != null");

            this.expandPaths = expandPaths;
            this.baseResourceType = baseResourceType;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:38,代码来源:RootProjectionNode.cs

示例4: OperationSerializerTests

        public OperationSerializerTests()
        {
            ResourceType intType = ResourceType.GetPrimitiveResourceType(typeof(int));

            var customerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "FQ.NS", "Customer", false);
            customerType.CanReflectOnInstanceType = false;
            customerType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, intType) { CanReflectOnInstanceTypeProperty = false });
            customerType.SetReadOnly();

            var operation = new ServiceAction("Action", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", customerType), new ServiceActionParameter("P2", intType) }, null);
            operation.SetReadOnly();
            this.baseTypeOperation = new OperationWrapper(operation);

            var bestCustomerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, customerType, "FQ.NS", "BestCustomer", false);
            bestCustomerType.SetReadOnly();

            operation = new ServiceAction("Action", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", bestCustomerType) }, null);
            operation.SetReadOnly();
            this.derivedTypeOperation = new OperationWrapper(operation);

            operation = new ServiceAction("Unambiguous", intType, OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("P1", customerType) }, null);
            operation.SetReadOnly();
            this.unambiguousOperation = new OperationWrapper(operation);

            this.entityToSerialize = EntityToSerialize.CreateFromExplicitValues(new object(), bestCustomerType, new TestSerializedEntityKey("http://odata.org/Service.svc/Customers(0)/", bestCustomerType.FullName));

            this.testSubject = CreateOperationSerializer(AlwaysAdvertiseActions);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:28,代码来源:OperationSerializerTests.cs

示例5: GetTestInstance

        /// <summary>
        /// Returns a test instance of one of the provider OM types.
        /// </summary>
        /// <param name="type">The type to get instance of.</param>
        /// <returns>The </returns>
        public static object GetTestInstance(Type type)
        {
            if (type == typeof(ResourceType))
            {
                ResourceProperty p = new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false };
                ResourceType resourceType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "NoBaseType", false);
                Assert.IsTrue(resourceType.KeyProperties.Count == 0, "It's okay not to have key properties, since we haven't set this type to readonly yet");
                resourceType.AddProperty(p);
                return resourceType;
            }
            else if (type == typeof(ResourceProperty))
            {
                return new ResourceProperty("NonKeyProperty", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int)));
            }
            else if (type == typeof(ServiceOperation))
            {
                ServiceOperationParameter parameter = new ServiceOperationParameter("o", ResourceType.GetPrimitiveResourceType(typeof(string)));
                ServiceOperation operation = new ServiceOperation("Dummy", ServiceOperationResultKind.Void, null, null, "POST", new ServiceOperationParameter[] { parameter });
                return operation;
            }
            else if (type == typeof(ServiceOperationParameter))
            {
                return new ServiceOperationParameter("o", ResourceType.GetPrimitiveResourceType(typeof(string)));
            }
            else if (type == typeof(ResourceSet))
            {
                ResourceProperty p = new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int)));

                ResourceType resourceType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "NoBaseType", false);
                resourceType.AddProperty(p);
                return new ResourceSet("Customers", resourceType);
            }

            throw new Exception(String.Format("Unexpected type encountered: '{0}'", type.FullName));
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:40,代码来源:ResourceTypeUtils.cs

示例6: IsAssignableFrom

        /// <summary>
        /// Checks if the given type is assignable to this type. In other words, if this type
        /// is a subtype of the given type or not.
        /// </summary>
        /// <param name="subType">resource type to check.</param>
        /// <returns>true, if the given type is assignable to this type. Otherwise returns false.</returns>
        internal static bool IsAssignableFrom(this ResourceType thisType, ResourceType subType)
        {
            CollectionResourceType thisCollectionType = thisType as CollectionResourceType;
            CollectionResourceType subCollectionType = subType as CollectionResourceType;
            if (thisCollectionType != null && subCollectionType != null)
            {
                return thisCollectionType.ItemType.IsAssignableFrom(subCollectionType.ItemType);
            }

            EntityCollectionResourceType thisEntityCollectionType = thisType as EntityCollectionResourceType;
            EntityCollectionResourceType subEntityCollectionType = subType as EntityCollectionResourceType;
            if (thisEntityCollectionType != null && subEntityCollectionType != null)
            {
                return thisEntityCollectionType.ItemType.IsAssignableFrom(subEntityCollectionType.ItemType);
            }

            while (subType != null)
            {
                if (subType == thisType)
                {
                    return true;
                }

                subType = subType.BaseType;
            }

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

示例7: SetupTestMetadata

 private static void SetupTestMetadata(Type entityClrType, Type[] primitiveTypes, out ResourceType entityResourceType, out ProviderMetadataSimulator workspace, out PrimitiveResourceTypeMap primitiveTypeMap)
 {
     KeyValuePair<Type, string>[] mappedPrimitiveTypes = BuildTypeMap(primitiveTypes);
     primitiveTypeMap = new PrimitiveResourceTypeMap(mappedPrimitiveTypes.ToArray());
     entityResourceType = new ResourceType(entityClrType, ResourceTypeKind.EntityType, null, entityClrType.Namespace, entityClrType.Name, false);
     workspace = new ProviderMetadataSimulator(new List<Type>() { entityClrType });
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:7,代码来源:ObjectContextServiceProvider_MetadataTests.cs

示例8: DataServiceProviderWrapperShouldFailOnMultipleActionsWithSameNameAndBindingType

        public void DataServiceProviderWrapperShouldFailOnMultipleActionsWithSameNameAndBindingType()
        {
            var entityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Fake.NS", "Type", false) { CanReflectOnInstanceType = false };
            entityType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))) {CanReflectOnInstanceTypeProperty = false});
            entityType.SetReadOnly();

            var resourceSet = new ResourceSet("MyEntitySet", entityType);
            resourceSet.SetReadOnly();

            ResourceType stringType = ResourceType.GetPrimitiveResourceType(typeof(string));
            var duplicateAction1 = new ServiceAction("Duplicate", stringType, OperationParameterBindingKind.Always, new[] { new ServiceActionParameter("p1", entityType), new ServiceActionParameter("p2", stringType) }, null);
            duplicateAction1.SetReadOnly();
            var duplicateAction2 = new ServiceAction("Duplicate", ResourceType.GetPrimitiveResourceType(typeof(int)), OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("p1", entityType) }, null);
            duplicateAction2.SetReadOnly();

            var actionProvider = new TestActionProvider
            {
                GetServiceActionsCallback = ctx => new[] { duplicateAction1, duplicateAction2 }
            };

            var providerWrapper = CreateProviderWrapper(actionProvider, p => p.AddResourceSet(resourceSet));

            Action getVisibleOperations = () => providerWrapper.GetVisibleOperations().ToList();
            getVisibleOperations.ShouldThrow<DataServiceException>()
                .WithMessage(ErrorStrings.DataServiceActionProviderWrapper_DuplicateAction("Duplicate"))
                .And.StatusCode.Should().Be(500);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:27,代码来源:DataServiceProviderWrapperTests.cs

示例9: ServiceActionResolverArgs

        /// <summary>
        /// Initializes a new instance of <see cref="ServiceActionResolverArgs"/>.
        /// </summary>
        /// <param name="serviceActionName"> The service action name taken from the URI.</param>
        /// <param name="bindingType">The binding type based on interpreting the URI preceeding the action, or null if the action is being invoked from the root of the service.</param>
        public ServiceActionResolverArgs(string serviceActionName, ResourceType bindingType)
        {
            WebUtil.CheckStringArgumentNullOrEmpty(serviceActionName, "serviceActionName");
            this.ServiceActionName = serviceActionName;

            // binding type is explicitly allowed to be null.
            this.BindingType = bindingType;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:13,代码来源:IDataServiceActionResolver.cs

示例10: DSPResource

 /// <summary>Constructor, creates a new resource with preinitialized properties.</summary>
 /// <param name="resourceType">The type of the resource to create.</param>
 /// <param name="values">The properties to initialize.</param>
 public DSPResource(ResourceType resourceType, IEnumerable<KeyValuePair<string, object>> values)
     : this(resourceType)
 {
     foreach (var value in values)
     {
         this.properties.Add(value.Key, value.Value);
     }
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:11,代码来源:DSPResource.cs

示例11: MetadataProviderEdmCollectionType

        /// <summary>
        /// Initializes a new instance of <see cref="MetadataProviderEdmCollectionType"/>.
        /// </summary>
        /// <param name="collectionResourceType">The collection resource type this edm collection type is being created for.</param>
        /// <param name="elementType">The element type of the collection.</param>
        public MetadataProviderEdmCollectionType(ResourceType collectionResourceType, IEdmTypeReference elementType)
            : base(elementType)
        {
            Debug.Assert(collectionResourceType != null, "collectionResourceType != null");
            Debug.Assert(collectionResourceType is CollectionResourceType || collectionResourceType is EntityCollectionResourceType, "resource type must represent a collection.");

            this.ResourceType = collectionResourceType;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:13,代码来源:MetadataProviderEdmCollectionType.cs

示例12: ServiceOperationParameter

 /// <summary>Creates a new instance of <see cref="T:Microsoft.OData.Service.Providers.ServiceOperationParameter" />.</summary>
 /// <param name="name">Name of parameter.</param>
 /// <param name="parameterType">Data type of parameter.</param>
 public ServiceOperationParameter(string name, ResourceType parameterType)
     : base(name, parameterType)
 {
     WebUtil.CheckArgumentNull(parameterType, "parameterType");
     if (parameterType.ResourceTypeKind != ResourceTypeKind.Primitive)
     {
         throw new ArgumentException(Strings.ServiceOperationParameter_TypeNotSupported(name, parameterType.FullName), "parameterType");
     }
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:12,代码来源:ServiceOperationParameter.cs

示例13: GetServiceActionsByBindingParameterType

        public IEnumerable<ServiceAction> GetServiceActionsByBindingParameterType(DataServiceOperationContext operationContext, ResourceType bindingParameterType)
        {
            if (this.GetByBindingTypeCallback != null)
            {
                return this.GetByBindingTypeCallback(operationContext, bindingParameterType);
            }

            throw new NotImplementedException();
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:9,代码来源:TestActionProvider.cs

示例14: EntityToSerialize

        /// <summary>
        /// Initializes a new instance of the <see cref="EntityToSerialize"/> class.
        /// </summary>
        /// <param name="entity">The entity itself.</param>
        /// <param name="resourceType">The type of the entity.</param>
        /// <param name="serializedKey">The serialized entity key for the instance.</param>
        private EntityToSerialize(object entity, ResourceType resourceType, SerializedEntityKey serializedKey)
        {
            Debug.Assert(entity != null, "resource != null");
            Debug.Assert(resourceType != null && resourceType.ResourceTypeKind == ResourceTypeKind.EntityType, "resourceType != null && resourceType.ResourceTypeKind == ResourceTypeKind.EntityType");
            Debug.Assert(serializedKey != null, "serializedKey != null");

            this.entity = entity;
            this.resourceType = resourceType;
            this.serializedEntityKey = serializedKey;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:16,代码来源:EntityToSerialize.cs

示例15: GetCacheKey

        /// <summary>
        /// Creates a cache-key from the operation name and binding parameter type.
        /// </summary>
        /// <param name="operationName">The operation name.</param>
        /// <param name="bindingType">The binding parameter type.</param>
        /// <returns>The cache-key.</returns>
        private static string GetCacheKey(string operationName, ResourceType bindingType)
        {
            var cacheKey = operationName;
            if (bindingType != null)
            {
                cacheKey += "_" + bindingType.FullName;
            }

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


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