public void CtorPropertyName() { var e = new IgnorePropertiesAttribute("tag"); Assert.AreEqual(1, e.PropertyNames.Count); Assert.AreEqual("tag", e.PropertyNames.First()); }
public void CtorPropertyNames() { var e = new IgnorePropertiesAttribute (new[] { "foo", "bar" }); Assert.AreEqual (2, e.PropertyNames.Count); Assert.AreEqual ("foo", e.PropertyNames[0]); Assert.AreEqual ("bar", e.PropertyNames[1]); }
public void CtorPropertyNames() { var e = new IgnorePropertiesAttribute(new[] { "foo", "bar" }); Assert.AreEqual(2, e.PropertyNames.Count); Assert.AreEqual("foo", e.PropertyNames[0]); Assert.AreEqual("bar", e.PropertyNames[1]); }
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); }
public void CtorPropertyName() { var e = new IgnorePropertiesAttribute ("tag"); Assert.AreEqual (1, e.PropertyNames.Count); Assert.AreEqual ("tag", e.PropertyNames.First()); }
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)); } }