Пример #1
0
 private void ValidateCollectionResourceType(CollectionResourceType collectionResourceType)
 {
     if ((collectionResourceType.ItemType.ResourceTypeKind == ResourceTypeKind.ComplexType) && this.HasDerivedTypes(collectionResourceType.ItemType))
     {
         throw new DataServiceException(500, System.Data.Services.Strings.DataServiceProviderWrapper_CollectionOfComplexTypeWithDerivedTypes(collectionResourceType.ItemType.FullName));
     }
 }
Пример #2
0
        private IEnumerable <ResourceType> GetResourceTypeAndReachableComplexTypes(ResourceType resourceType, HashSet <ResourceType> visitedTypes)
        {
            resourceType = this.ValidateResourceType(resourceType);
            if (!visitedTypes.Contains(resourceType))
            {
                visitedTypes.Add(resourceType);
                yield return(resourceType);

                foreach (ResourceProperty iteratorVariable0 in resourceType.PropertiesDeclaredOnThisType)
                {
                    ResourceType itemType = iteratorVariable0.ResourceType;
                    if (itemType.ResourceTypeKind == ResourceTypeKind.Collection)
                    {
                        CollectionResourceType collectionResourceType = (CollectionResourceType)itemType;
                        this.ValidateCollectionResourceType(collectionResourceType);
                        itemType = collectionResourceType.ItemType;
                    }
                    if (itemType.ResourceTypeKind == ResourceTypeKind.ComplexType)
                    {
                        foreach (ResourceType iteratorVariable2 in this.GetResourceTypeAndReachableComplexTypes(itemType, visitedTypes))
                        {
                            yield return(iteratorVariable2);
                        }
                    }
                }
            }
        }
Пример #3
0
        private IEdmCollectionType EnsurePrimitiveOrComplexCollectionType(ResourceType resourceType, List <KeyValuePair <string, object> > customAnnotations)
        {
            CollectionResourceType type     = (CollectionResourceType)resourceType;
            ResourceType           itemType = type.ItemType;

            return(this.EnsureCollectionItemTypeIsPrimitiveOrComplex(itemType, customAnnotations));
        }
Пример #4
0
 public void SetReadOnly()
 {
     if (this.ResourceTypeKind == System.Data.Services.Providers.ResourceTypeKind.Collection)
     {
         CollectionResourceType type = this as CollectionResourceType;
         type.ItemType.SetReadOnly();
     }
     if (!this.isReadOnly)
     {
         this.isReadOnly = true;
         if (this.BaseType != null)
         {
             this.BaseType.SetReadOnly();
             if (this.BaseType.IsOpenType && (this.ResourceTypeKind != System.Data.Services.Providers.ResourceTypeKind.ComplexType))
             {
                 this.isOpenType = true;
             }
             if (this.BaseType.IsMediaLinkEntry)
             {
                 this.isMediaLinkEntry = true;
             }
             if (!this.BaseType.CanReflectOnInstanceType)
             {
                 this.canReflectOnInstanceType = false;
             }
         }
         if (this.propertiesDeclaredOnThisType != null)
         {
             foreach (ResourceProperty property in this.propertiesDeclaredOnThisType)
             {
                 property.SetReadOnly();
             }
         }
     }
 }
		internal IEnumerable SerializeDictionary(IDictionary dictionary, CollectionResourceType collectionResourceType, int depth)
		{
			ResourceType itemType = collectionResourceType.ItemType;
			Type[] instanceType = new Type[1];
			instanceType[0] = itemType.InstanceType;
			Type[] typeArray = instanceType;
			Type type = typeof(List<>);
			Type type1 = type.MakeGenericType(typeArray);
			IList lists = (IList)Activator.CreateInstance(type1);
			foreach (object key in dictionary.Keys)
			{
				KeyValuePair<object, object> keyValuePair = new KeyValuePair<object, object>(key, dictionary[key]);
				lists.Add(SerializerBase.SerializeResourceType(keyValuePair, itemType, depth));
			}
			return lists;
		}
		internal IEnumerable SerializeEnumerable(IEnumerable clrObjects, CollectionResourceType collectionResourceType, int depth)
		{
			ResourceType itemType = collectionResourceType.ItemType;
			Type[] instanceType = new Type[1];
			instanceType[0] = itemType.InstanceType;
			Type[] typeArray = instanceType;
			Type type = typeof(List<>);
			Type type1 = type.MakeGenericType(typeArray);
			IList lists = (IList)Activator.CreateInstance(type1);
			if (clrObjects != null)
			{
				foreach (object clrObject in clrObjects)
				{
					lists.Add(SerializerBase.SerializeResourceType(clrObject, itemType, depth));
				}
			}
			return lists;
		}