internal void CheckIfOrderedType(Type clrType) { BaseServiceProvider metadataProvider = this.metadataProvider as BaseServiceProvider; if ((metadataProvider != null) && !metadataProvider.GetTypeIsOrdered(clrType)) { throw DataServiceException.CreateBadRequestError(System.Data.Services.Strings.RequestQueryParser_OrderByDoesNotSupportType(WebUtil.GetTypeName(clrType))); } }
protected override void PopulateMetadataForUserSpecifiedTypes(IEnumerable <Type> userSpecifiedTypes, IDictionary <Type, ResourceType> knownTypes, IDictionary <ResourceType, List <ResourceType> > childTypes, IEnumerable <ResourceSet> entitySets) { Queue <ResourceType> unvisitedTypes = new Queue <ResourceType>(); foreach (Type type in userSpecifiedTypes) { ResourceType type2; if (!BaseServiceProvider.TryGetType(knownTypes, type, out type2) && (IsEntityOrComplexType(type, knownTypes, childTypes, unvisitedTypes) == null)) { throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_InvalidTypeSpecified(type.FullName)); } } PopulateMetadataForTypes(knownTypes, childTypes, unvisitedTypes, entitySets); }
protected override ResourceType PopulateMetadataForType(Type type, IDictionary <Type, ResourceType> knownTypes, IDictionary <ResourceType, List <ResourceType> > childTypes, IEnumerable <ResourceSet> entitySets) { ResourceType type2; Queue <ResourceType> unvisitedTypes = new Queue <ResourceType>(); if (!BaseServiceProvider.TryGetType(knownTypes, type, out type2)) { type2 = IsEntityOrComplexType(type, knownTypes, childTypes, unvisitedTypes); if (type2 != null) { PopulateMetadataForTypes(knownTypes, childTypes, unvisitedTypes, entitySets); } } return(type2); }
/// <summary> /// Returns the resource type for the corresponding clr type. /// If the given clr type is a collection, then resource type describes the element type of the collection. /// </summary> /// <param name="type">clrType whose corresponding resource type needs to be returned</param> /// <returns>Returns the resource type</returns> private ResourceType GetNonPrimitiveType(Type type) { Debug.Assert(type != null, "type != null"); // Check for the type directly first ResourceType resourceType = this.ResolveNonPrimitiveType(type); if (resourceType == null) { // check for ienumerable types Type elementType = BaseServiceProvider.GetIEnumerableElement(type); if (elementType != null) { resourceType = ResourceType.GetPrimitiveResourceType(elementType); if (resourceType == null) { resourceType = this.ResolveNonPrimitiveType(elementType); } } } return(resourceType); }
protected override void PopulateMetadata(IDictionary <Type, ResourceType> knownTypes, IDictionary <ResourceType, List <ResourceType> > childTypes, IDictionary <string, ResourceSet> entitySets) { Queue <ResourceType> unvisitedTypes = new Queue <ResourceType>(); List <string> list = new List <string>(IgnorePropertiesAttribute.GetProperties(base.Type, true, BindingFlags.Public | BindingFlags.Instance)); foreach (PropertyInfo info in base.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if ((!list.Contains(info.Name) && info.CanRead) && (info.GetIndexParameters().Length == 0)) { Type iQueryableElement = BaseServiceProvider.GetIQueryableElement(info.PropertyType); if (iQueryableElement != null) { ResourceType elementType = BuildHierarchyForEntityType(iQueryableElement, knownTypes, childTypes, unvisitedTypes, true); if (elementType == null) { throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_InvalidEntitySetProperty(info.Name, XmlConvert.EncodeName(this.ContainerName))); } foreach (KeyValuePair <string, ResourceSet> pair in entitySets) { Type instanceType = pair.Value.ResourceType.InstanceType; if (instanceType.IsAssignableFrom(iQueryableElement)) { throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_MultipleEntitySetsForSameType(pair.Value.Name, info.Name, instanceType.FullName, elementType.FullName)); } if (iQueryableElement.IsAssignableFrom(instanceType)) { throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_MultipleEntitySetsForSameType(info.Name, pair.Value.Name, elementType.FullName, instanceType.FullName)); } } ResourceSet set = new ResourceSet(info.Name, elementType); entitySets.Add(info.Name, set); } } } PopulateMetadataForTypes(knownTypes, childTypes, unvisitedTypes, entitySets.Values); PopulateMetadataForDerivedTypes(knownTypes, childTypes, unvisitedTypes, entitySets.Values); }
internal bool IsV1ProviderAndImplementsUpdatable() { BaseServiceProvider metadataProvider = this.metadataProvider as BaseServiceProvider; return((metadataProvider != null) && metadataProvider.ImplementsIUpdatable()); }
private static void BuildTypeProperties(ResourceType parentResourceType, IDictionary <Type, ResourceType> knownTypes, IDictionary <ResourceType, List <ResourceType> > childTypes, Queue <ResourceType> unvisitedTypes, IEnumerable <ResourceSet> entitySets) { BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance; if (parentResourceType.BaseType != null) { bindingFlags |= BindingFlags.DeclaredOnly; } HashSet <string> set = new HashSet <string>(IgnorePropertiesAttribute.GetProperties(parentResourceType.InstanceType, false, bindingFlags), StringComparer.Ordinal); HashSet <string> source = new HashSet <string>(LoadETagProperties(parentResourceType), StringComparer.Ordinal); ResourceKeyKind kind = (ResourceKeyKind)0x7fffffff; PropertyInfo[] properties = parentResourceType.InstanceType.GetProperties(bindingFlags); if (!properties.Any <PropertyInfo>() && (parentResourceType.BaseType == null)) { throw new NotSupportedException(System.Data.Services.Strings.ReflectionProvider_ResourceTypeHasNoPublicallyVisibleProperties(parentResourceType.FullName)); } foreach (PropertyInfo info in properties) { if (!set.Contains(info.Name)) { ResourceType collectionResourceType; if (!info.CanRead || (info.GetIndexParameters().Length != 0)) { throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_InvalidProperty(info.Name, parentResourceType.FullName)); } ResourcePropertyKind collection = (ResourcePropertyKind)(-1); Type propertyType = info.PropertyType; bool flag = false; if (!BaseServiceProvider.TryGetType(knownTypes, propertyType, out collectionResourceType)) { Type iEnumerableElement = BaseServiceProvider.GetIEnumerableElement(info.PropertyType); if (iEnumerableElement != null) { BaseServiceProvider.TryGetType(knownTypes, iEnumerableElement, out collectionResourceType); flag = true; propertyType = iEnumerableElement; } } if (collectionResourceType != null) { if (collectionResourceType.ResourceTypeKind == ResourceTypeKind.Primitive) { if (flag) { collection = ResourcePropertyKind.Collection; } else { ResourceKeyKind kind3; if (((parentResourceType.BaseType == null) && (parentResourceType.ResourceTypeKind == ResourceTypeKind.EntityType)) && IsPropertyKeyProperty(info, out kind3)) { if (kind3 < kind) { if (parentResourceType.KeyProperties.Count != 0) { parentResourceType.RemoveKeyProperties(); } kind = kind3; collection = ResourcePropertyKind.Key | ResourcePropertyKind.Primitive; } else if (kind3 == kind) { collection = ResourcePropertyKind.Key | ResourcePropertyKind.Primitive; } else { collection = ResourcePropertyKind.Primitive; } } else { collection = ResourcePropertyKind.Primitive; } } } else if (collectionResourceType.ResourceTypeKind == ResourceTypeKind.ComplexType) { collection = flag ? ResourcePropertyKind.Collection : ResourcePropertyKind.ComplexType; } else if (collectionResourceType.ResourceTypeKind == ResourceTypeKind.EntityType) { collection = flag ? ResourcePropertyKind.ResourceSetReference : ResourcePropertyKind.ResourceReference; } } else { collectionResourceType = IsEntityOrComplexType(propertyType, knownTypes, childTypes, unvisitedTypes); if (collectionResourceType != null) { if (collectionResourceType.ResourceTypeKind == ResourceTypeKind.ComplexType) { if (flag) { if (BaseServiceProvider.GetIEnumerableElement(propertyType) != null) { throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_CollectionOfCollectionProperty(info.Name, parentResourceType.FullName)); } collection = ResourcePropertyKind.Collection; } else { collection = ResourcePropertyKind.ComplexType; } } else { collection = flag ? ResourcePropertyKind.ResourceSetReference : ResourcePropertyKind.ResourceReference; } } } if ((collectionResourceType == null) || ((collectionResourceType.ResourceTypeKind == ResourceTypeKind.EntityType) && (parentResourceType.ResourceTypeKind == ResourceTypeKind.ComplexType))) { if (collectionResourceType != null) { throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_ComplexTypeWithNavigationProperty(info.Name, parentResourceType.FullName)); } if (flag && (BaseServiceProvider.GetIEnumerableElement(propertyType) != null)) { throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_CollectionOfCollectionProperty(info.Name, parentResourceType.FullName)); } if (flag) { throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_CollectionOfUnsupportedTypeProperty(info.Name, parentResourceType.FullName, propertyType)); } if (CommonUtil.IsUnsupportedType(propertyType)) { throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_UnsupportedPropertyType(info.Name, parentResourceType.FullName)); } throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_InvalidProperty(info.Name, parentResourceType.FullName)); } if ((collectionResourceType.ResourceTypeKind == ResourceTypeKind.EntityType) && (InternalGetContainerForResourceType(propertyType, entitySets) == null)) { throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_EntityPropertyWithNoEntitySet(parentResourceType.FullName, info.Name)); } if (collection == ResourcePropertyKind.Collection) { collectionResourceType = ResourceType.GetCollectionResourceType(collectionResourceType); } if (source.Remove(info.Name)) { collection |= ResourcePropertyKind.ETag; } ResourceProperty property = new ResourceProperty(info.Name, collection, collectionResourceType); MimeTypeAttribute mimeTypeAttribute = MimeTypeAttribute.GetMimeTypeAttribute(info); if (mimeTypeAttribute != null) { property.MimeType = mimeTypeAttribute.MimeType; } parentResourceType.AddProperty(property); } } if ((parentResourceType.ResourceTypeKind == ResourceTypeKind.EntityType) && ((parentResourceType.KeyProperties == null) || (parentResourceType.KeyProperties.Count == 0))) { throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_KeyPropertiesCannotBeIgnored(parentResourceType.FullName)); } if (source.Count != 0) { throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_ETagPropertyNameNotValid(source.ElementAt <string>(0), parentResourceType.FullName)); } }
private static ResourceType BuildHierarchyForEntityType(Type type, IDictionary <Type, ResourceType> knownTypes, IDictionary <ResourceType, List <ResourceType> > childTypes, Queue <ResourceType> unvisitedTypes, bool entityTypeCandidate) { List <Type> list = new List <Type>(); if (!type.IsVisible) { return(null); } if (CommonUtil.IsUnsupportedType(type)) { throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_UnsupportedType(type.FullName)); } Type baseType = type; ResourceType resourceType = null; while (baseType != null) { if (BaseServiceProvider.TryGetType(knownTypes, baseType, out resourceType)) { break; } list.Add(baseType); baseType = baseType.BaseType; } if (resourceType == null) { if (!entityTypeCandidate) { return(null); } for (int j = list.Count - 1; j >= 0; j--) { if (CommonUtil.IsUnsupportedType(list[j])) { throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_UnsupportedAncestorType(type.FullName, list[j].FullName)); } if (DoesTypeHaveKeyProperties(list[j], entityTypeCandidate)) { break; } list.RemoveAt(j); } } else { if (resourceType.ResourceTypeKind != ResourceTypeKind.EntityType) { return(null); } if (list.Count == 0) { return(resourceType); } } for (int i = list.Count - 1; i >= 0; i--) { ResourceType item = CreateResourceType(list[i], ResourceTypeKind.EntityType, resourceType, knownTypes, childTypes); unvisitedTypes.Enqueue(item); resourceType = item; } return(resourceType); }