private static bool IsUsedBy(
			StructuralTypeConfiguration toCheckFor,
			IEdmTypeConfiguration toCheckIn,
			List<IEdmTypeConfiguration> typesChecked)
		{
			if (typesChecked.Contains(toCheckIn))
			{
				return false;
			}
			typesChecked.Add(toCheckIn);
			if (toCheckIn == toCheckFor)
			{
				return true;
			}
			var toCheckInStructural = toCheckIn as StructuralTypeConfiguration;
			if (toCheckInStructural != null)
			{
				foreach (var property in toCheckInStructural.Properties
					.Where(p => !p.IsIgnored))
				{
					var propertyType = toCheckFor.ModelBuilder.GetTypeConfigurationOrNull(property.RelatedClrType);
					if (IsUsedBy(toCheckFor, propertyType, typesChecked))
					{
						return true;
					}
				}
			}
			typesChecked.Add(toCheckIn);
			return false;
		}
 public void Apply(IEdmTypeConfiguration edmTypeConfiguration, ODataConventionModelBuilder model)
 {
     StructuralTypeConfiguration structuralType = edmTypeConfiguration as StructuralTypeConfiguration;
     if (structuralType != null && structuralType.IsAbstract == null)
     {
         structuralType.IsAbstract = structuralType.ClrType.GetTypeInfo().IsAbstract;
     }
 }
 public void Apply(IEdmTypeConfiguration edmTypeConfiguration, ODataModelBuilder model)
 {
     IEntityTypeConfiguration entity = edmTypeConfiguration as IEntityTypeConfiguration;
     if (entity != null)
     {
         Apply(entity, model);
     }
 }
 /// <summary>
 /// Constructs a collection that contains elements of the specified ElementType
 /// and that is represented in CLR using the specified clrType.
 /// </summary>
 /// <param name="elementType">The EdmTypeConfiguration of the elements in the collection</param>
 /// <param name="clrType">The type of this collection when manifested in CLR.</param>
 public CollectionTypeConfiguration(IEdmTypeConfiguration elementType, Type clrType)
 {
     if (elementType == null)
     {
         throw Error.ArgumentNull("elementType");
     }
     if (clrType == null)
     {
         throw Error.ArgumentNull("clrType");
     }
     _elementType = elementType;
     _clrType = clrType;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ParameterConfiguration"/> class.
 /// </summary>
 /// <param name="name">The name of the parameter.</param>
 /// <param name="parameterType">The EDM type of the paramter.</param>
 protected ParameterConfiguration(string name, IEdmTypeConfiguration parameterType)
 {
     if (name == null)
     {
         throw Error.ArgumentNull("name");
     }
     if (parameterType == null)
     {
         throw Error.ArgumentNull("bindingParameterType");
     }
     Name = name;
     TypeConfiguration = parameterType;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NonbindingParameterConfiguration"/> class.
 /// </summary>
 /// <param name="name">The name of the parameter.</param>
 /// <param name="parameterType">The EDM type of the parameter.</param>
 public NonbindingParameterConfiguration(string name, IEdmTypeConfiguration parameterType)
     : base(name, parameterType)
 {
     EdmTypeKind kind = parameterType.Kind;
     if (kind == EdmTypeKind.Collection)
     {
         kind = (parameterType as CollectionTypeConfiguration).ElementType.Kind;
     }
     if (kind == EdmTypeKind.Entity)
     {
         throw Error.Argument("parameterType", SRResources.InvalidParameterType, parameterType.FullName);
     }
 }
 /// <summary>
 /// Create a BindingParameterConfiguration
 /// </summary>
 /// <param name="name">The name of the Binding Parameter</param>
 /// <param name="parameterType">The type of the Binding Parameter</param>
 /// <param name="alwaysBindable">Whether the action can always be bound to instances of the binding parameter.</param>
 public BindingParameterConfiguration(string name, IEdmTypeConfiguration parameterType, bool alwaysBindable)
     : base(name, parameterType)
 {
     EdmTypeKind kind = parameterType.Kind;
     if (kind == EdmTypeKind.Collection)
     {
         kind = (parameterType as ICollectionTypeConfiguration).ElementType.Kind;
     }
     if (kind != EdmTypeKind.Entity)
     {
         throw Error.Argument("parameterType", SRResources.InvalidBindingParameterType, parameterType.FullName);
     }
     _alwaysBindable = alwaysBindable;
 }
        private void CreateEdmTypeHeader(IEdmTypeConfiguration config)
        {
            if (GetEdmType(config.ClrType) == null)
            {
                if (config.Kind == EdmTypeKind.Complex)
                {
                    ComplexTypeConfiguration complex = (ComplexTypeConfiguration)config;

                    EdmComplexType complexType = new EdmComplexType(config.Namespace, config.Name, 
                        null, false, complex.IsOpen);

                    _types.Add(config.ClrType, complexType);

                    if (complex.IsOpen)
                    {
                        // add a mapping between the open complex type and its dynamic property dictionary.
                        _openTypes.Add(complexType, complex.DynamicPropertyDictionary);
                    }
                }
                else if (config.Kind == EdmTypeKind.Entity)
                {
                    EntityTypeConfiguration entity = config as EntityTypeConfiguration;
                    Contract.Assert(entity != null);

                    IEdmEntityType baseType = null;

                    if (entity.BaseType != null)
                    {
                        CreateEdmTypeHeader(entity.BaseType);
                        baseType = GetEdmType(entity.BaseType.ClrType) as IEdmEntityType;

                        Contract.Assert(baseType != null);
                    }

                    _types.Add(config.ClrType, new EdmEntityType(config.Namespace, config.Name, baseType, entity.IsAbstract ?? false, isOpen: false));
                }
                else
                {
                    EnumTypeConfiguration enumTypeConfiguration = config as EnumTypeConfiguration;

                    // The config has to be enum.
                    Contract.Assert(enumTypeConfiguration != null);

                    _types.Add(enumTypeConfiguration.ClrType, new EdmEnumType(enumTypeConfiguration.Namespace, enumTypeConfiguration.Name, GetTypeKind(enumTypeConfiguration.UnderlyingType), enumTypeConfiguration.IsFlags));
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterConfiguration"/> class.
        /// </summary>
        /// <param name="name">The name of the parameter.</param>
        /// <param name="parameterType">The EDM type of the parameter.</param>
        protected ParameterConfiguration(string name, IEdmTypeConfiguration parameterType)
        {
            if (name == null)
            {
                throw Error.ArgumentNull("name");
            }
            if (parameterType == null)
            {
                throw Error.ArgumentNull("parameterType");
            }

            Name = name;
            TypeConfiguration = parameterType;

            Type elementType;
            OptionalParameter = parameterType.ClrType.IsCollection(out elementType)
                ? EdmLibHelpers.IsNullable(elementType)
                : EdmLibHelpers.IsNullable(parameterType.ClrType);
        }
        private void CreateEdmTypeHeader(IEdmTypeConfiguration config)
        {
            if (GetEdmType(config.ClrType) == null)
            {
                if (config.Kind == EdmTypeKind.Complex)
                {
                    _types.Add(config.ClrType, new EdmComplexType(config.Namespace, config.Name));
                }
                else if (config.Kind == EdmTypeKind.Entity)
                {
                    EntityTypeConfiguration entity = config as EntityTypeConfiguration;
                    Contract.Assert(entity != null);

                    IEdmEntityType baseType = null;

                    if (entity.BaseType != null)
                    {
                        CreateEdmTypeHeader(entity.BaseType);
                        baseType = GetEdmType(entity.BaseType.ClrType) as IEdmEntityType;

                        Contract.Assert(baseType != null);
                    }

                    _types.Add(config.ClrType, new EdmEntityType(config.Namespace, config.Name, baseType, entity.IsAbstract ?? false, isOpen: false));
                }
                else
                {
                    EnumTypeConfiguration enumTypeConfiguration = config as EnumTypeConfiguration;

                    // The config has to be enum.
                    Contract.Assert(enumTypeConfiguration != null);

                    _types.Add(enumTypeConfiguration.ClrType, new EdmEnumType(enumTypeConfiguration.Namespace, enumTypeConfiguration.Name, GetTypeKind(enumTypeConfiguration.UnderlyingType), enumTypeConfiguration.IsFlags));
                }
            }
        }
        private void CreateEdmTypeBody(IEdmTypeConfiguration config)
        {
            IEdmType edmType = GetEdmType(config.ClrType);

            if (edmType.TypeKind == EdmTypeKind.Complex)
            {
                CreateComplexTypeBody((EdmComplexType)edmType, (ComplexTypeConfiguration)config);
            }
            else if (edmType.TypeKind == EdmTypeKind.Entity)
            {
                CreateEntityTypeBody((EdmEntityType)edmType, (EntityTypeConfiguration)config);
            }
            else
            {
                Contract.Assert(edmType.TypeKind == EdmTypeKind.Enum);
                CreateEnumTypeBody((EdmEnumType)edmType, (EnumTypeConfiguration)config);
            }
        }
        public InstanceAnnotation(Lazy <Func <object, object> > accessor, string qualifiedName, IEdmTypeConfiguration annotationType)
        {
            Arg.NotNull(accessor, nameof(accessor));
            Arg.NotNull(annotationType, nameof(annotationType));

            this.accessor       = accessor;
            this.qualifiedName  = qualifiedName;
            this.annotationType = annotationType;
        }
 /// <summary>
 /// Specifies the bindingParameter name, type and whether it is alwaysBindable, use only if the Action "isBindable".
 /// </summary>
 public ActionConfiguration SetBindingParameter(string name, IEdmTypeConfiguration bindingParameterType, bool alwaysBindable)
 {
     _bindingParameter = new BindingParameterConfiguration(name, bindingParameterType, alwaysBindable);
     return(this);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NonbindingParameterConfiguration"/> class.
 /// </summary>
 /// <param name="name">The name of the parameter.</param>
 /// <param name="parameterType">The EDM type of the parameter.</param>
 public NonbindingParameterConfiguration(string name, IEdmTypeConfiguration parameterType)
     : base(name, parameterType)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="NonbindingParameterConfiguration"/> class.
 /// </summary>
 /// <param name="name">The name of the parameter.</param>
 /// <param name="parameterType">The EDM type of the parameter.</param>
 public NonbindingParameterConfiguration(string name, IEdmTypeConfiguration parameterType)
     : base(name, parameterType)
 {
 }
        private static IEdmTypeReference GetEdmTypeReference(Dictionary<Type, IEdmType> availableTypes, IEdmTypeConfiguration configuration, bool nullable)
        {
            Contract.Assert(availableTypes != null);

            if (configuration == null)
            {
                return null;
            }

            EdmTypeKind kind = configuration.Kind;
            if (kind == EdmTypeKind.Collection)
            {
                CollectionTypeConfiguration collectionType = (CollectionTypeConfiguration)configuration;
                EdmCollectionType edmCollectionType =
                    new EdmCollectionType(GetEdmTypeReference(availableTypes, collectionType.ElementType, nullable));
                return new EdmCollectionTypeReference(edmCollectionType);
            }
            else
            {
                Type configurationClrType = TypeHelper.GetUnderlyingTypeOrSelf(configuration.ClrType);

                if (!configurationClrType.GetTypeInfo().IsEnum)
                {
                    configurationClrType = configuration.ClrType;
                }

                IEdmType type;

                if (availableTypes.TryGetValue(configurationClrType, out type))
                {
                    if (kind == EdmTypeKind.Complex)
                    {
                        return new EdmComplexTypeReference((IEdmComplexType)type, nullable);
                    }
                    else if (kind == EdmTypeKind.Entity)
                    {
                        return new EdmEntityTypeReference((IEdmEntityType)type, nullable);
                    }
                    else if (kind == EdmTypeKind.Enum)
                    {
                        return new EdmEnumTypeReference((IEdmEnumType)type, nullable);
                    }
                    else
                    {
                        throw Error.InvalidOperation(SRResources.UnsupportedEdmTypeKind, kind.ToString());
                    }
                }
                else if (configuration.Kind == EdmTypeKind.Primitive)
                {
                    PrimitiveTypeConfiguration primitiveTypeConfiguration = configuration as PrimitiveTypeConfiguration;
                    return new EdmPrimitiveTypeReference(primitiveTypeConfiguration.EdmPrimitiveType, nullable);
                }
                else
                {
                    throw Error.InvalidOperation(SRResources.NoMatchingIEdmTypeFound, configuration.FullName);
                }
            }
        }
 /// <summary>
 /// Specifies the bindingParameter name, type and whether it is alwaysBindable, use only if the operation "isBindable".
 /// </summary>
 internal void SetBindingParameterImplementation(string name, IEdmTypeConfiguration bindingParameterType)
 {
     this._bindingParameter = new BindingParameterConfiguration(name, bindingParameterType);
 }
Exemple #18
0
 /// <summary>
 /// Constructs a collection that contains elements of the specified ElementType
 /// and that is represented in CLR using the specified clrType.
 /// </summary>
 /// <param name="elementType">The EdmTypeConfiguration of the elements in the collection</param>
 /// <param name="clrType">The type of this collection when manifested in CLR.</param>
 public CollectionTypeConfiguration(IEdmTypeConfiguration elementType, Type clrType)
 {
     ElementType = elementType ?? throw new ArgumentNullException(nameof(elementType));
     ClrType     = clrType ?? throw new ArgumentNullException(nameof(clrType));
 }
        // the convention model builder MapTypes() method might have went through deep object graphs and added a bunch of types
        // only to realise after applying the conventions that the user has ignored some of the properties. So, prune the unreachable stuff.
        private void PruneUnreachableTypes()
        {
            Contract.Assert(_explicitlyAddedTypes != null);

            // Do a BFS starting with the types the user has explicitly added to find out the unreachable nodes.
            Queue <StructuralTypeConfiguration>   reachableTypes = new Queue <StructuralTypeConfiguration>(_explicitlyAddedTypes);
            HashSet <StructuralTypeConfiguration> visitedTypes   = new HashSet <StructuralTypeConfiguration>();

            while (reachableTypes.Count != 0)
            {
                StructuralTypeConfiguration currentType = reachableTypes.Dequeue();

                // go visit other end of each of this node's edges.
                foreach (PropertyConfiguration property in currentType.Properties.Where(property => property.Kind != PropertyKind.Primitive))
                {
                    if (property.Kind == PropertyKind.Collection)
                    {
                        // if the elementType is primitive we don't need to do anything.
                        CollectionPropertyConfiguration colProperty = property as CollectionPropertyConfiguration;
                        if (EdmLibHelpers.GetEdmPrimitiveTypeOrNull(colProperty.ElementType) != null)
                        {
                            continue;
                        }
                    }

                    IEdmTypeConfiguration propertyType = GetStructuralTypeOrNull(property.RelatedClrType);
                    Contract.Assert(propertyType != null, "we should already have seen this type");

                    var structuralTypeConfiguration = propertyType as StructuralTypeConfiguration;
                    if (structuralTypeConfiguration != null && !visitedTypes.Contains(propertyType))
                    {
                        reachableTypes.Enqueue(structuralTypeConfiguration);
                    }
                }

                // all derived types and the base type are also reachable
                if (currentType.Kind == EdmTypeKind.Entity)
                {
                    EntityTypeConfiguration currentEntityType = (EntityTypeConfiguration)currentType;
                    if (currentEntityType.BaseType != null && !visitedTypes.Contains(currentEntityType.BaseType))
                    {
                        reachableTypes.Enqueue(currentEntityType.BaseType);
                    }

                    foreach (EntityTypeConfiguration derivedType in this.DerivedTypes(currentEntityType))
                    {
                        if (!visitedTypes.Contains(derivedType))
                        {
                            reachableTypes.Enqueue(derivedType);
                        }
                    }
                }
                else if (currentType.Kind == EdmTypeKind.Complex)
                {
                    ComplexTypeConfiguration currentComplexType = (ComplexTypeConfiguration)currentType;
                    if (currentComplexType.BaseType != null && !visitedTypes.Contains(currentComplexType.BaseType))
                    {
                        reachableTypes.Enqueue(currentComplexType.BaseType);
                    }

                    foreach (ComplexTypeConfiguration derivedType in this.DerivedTypes(currentComplexType))
                    {
                        if (!visitedTypes.Contains(derivedType))
                        {
                            reachableTypes.Enqueue(derivedType);
                        }
                    }
                }

                visitedTypes.Add(currentType);
            }

            StructuralTypeConfiguration[] allConfiguredTypes = StructuralTypes.ToArray();
            foreach (StructuralTypeConfiguration type in allConfiguredTypes)
            {
                if (!visitedTypes.Contains(type))
                {
                    // we don't have to fix up any properties because this type is unreachable and cannot be a property of any reachable type.
                    RemoveStructuralType(type.ClrType);
                }
            }
        }
        private bool TryGetPropertyTypeKind(Type propertyType, out IEdmTypeConfiguration mappedType, out PropertyKind propertyKind)
        {
            Contract.Assert(propertyType != null);

            if (EdmLibHelpers.GetEdmPrimitiveTypeOrNull(propertyType) != null)
            {
                mappedType   = null;
                propertyKind = PropertyKind.Primitive;
                return(true);
            }

            mappedType = GetStructuralTypeOrNull(propertyType);
            if (mappedType != null)
            {
                if (mappedType is ComplexTypeConfiguration)
                {
                    propertyKind = PropertyKind.Complex;
                }
                else if (mappedType is EnumTypeConfiguration)
                {
                    propertyKind = PropertyKind.Enum;
                }
                else
                {
                    propertyKind = PropertyKind.Navigation;
                }

                return(true);
            }

            // If one of the base types is configured as complex type, the type of this property
            // should be configured as complex type too.
            Type baseType = propertyType.BaseType;

            while (baseType != null && baseType != typeof(object))
            {
                IEdmTypeConfiguration baseMappedType = GetStructuralTypeOrNull(baseType);
                if (baseMappedType != null)
                {
                    if (baseMappedType is ComplexTypeConfiguration)
                    {
                        propertyKind = PropertyKind.Complex;
                        return(true);
                    }
                }

                baseType = baseType.BaseType;
            }

            // refer the Edm type from the derived types
            PropertyKind referedPropertyKind = PropertyKind.Navigation;

            if (InferEdmTypeFromDerivedTypes(propertyType, ref referedPropertyKind))
            {
                if (referedPropertyKind == PropertyKind.Complex)
                {
                    ReconfigInferedEntityTypeAsComplexType(propertyType);
                }

                propertyKind = referedPropertyKind;
                return(true);
            }

            if (TypeHelper.IsEnum(propertyType))
            {
                propertyKind = PropertyKind.Enum;
                return(true);
            }

            propertyKind = PropertyKind.Navigation;
            return(false);
        }
        // figures out the type of the property (primitive, complex, navigation) and the corresponding edm type if we have seen this type
        // earlier or the user told us about it.
        private PropertyKind GetPropertyType(PropertyInfo property, out bool isCollection, out IEdmTypeConfiguration mappedType)
        {
            Contract.Assert(property != null);

            // IDictionary<string, object> is used as a container to save/retrieve dynamic properties for an open type.
            // It is different from other collections (for example, IEnumerable<T> or IDictionary<string, int>)
            // which are used as navigation properties.
            if (typeof(IDictionary <string, object>).IsAssignableFrom(property.PropertyType))
            {
                mappedType   = null;
                isCollection = false;
                return(PropertyKind.Dynamic);
            }

            PropertyKind propertyKind;

            if (TryGetPropertyTypeKind(property.PropertyType, out mappedType, out propertyKind))
            {
                isCollection = false;
                return(propertyKind);
            }

            Type elementType;

            if (property.PropertyType.IsCollection(out elementType))
            {
                isCollection = true;
                if (TryGetPropertyTypeKind(elementType, out mappedType, out propertyKind))
                {
                    return(propertyKind);
                }

                // if we know nothing about this type we assume it to be collection of entities
                // and patch up later
                return(PropertyKind.Navigation);
            }

            // if we know nothing about this type we assume it to be an entity
            // and patch up later
            isCollection = false;
            return(PropertyKind.Navigation);
        }
Exemple #22
0
        private static IEdmTypeReference GetEdmTypeReference(Dictionary <Type, IEdmType> availableTypes, IEdmTypeConfiguration configuration, bool nullable)
        {
            Contract.Assert(availableTypes != null);

            if (configuration == null)
            {
                return(null);
            }

            EdmTypeKind kind = configuration.Kind;

            if (kind == EdmTypeKind.Collection)
            {
                CollectionTypeConfiguration collectionType = configuration as CollectionTypeConfiguration;
                bool elementNullable = EdmLibHelpers.IsNullable(collectionType.ElementType.ClrType);
                EdmCollectionType edmCollectionType =
                    new EdmCollectionType(GetEdmTypeReference(availableTypes, collectionType.ElementType, elementNullable));
                return(new EdmCollectionTypeReference(edmCollectionType));
            }
            else
            {
                Type configurationClrType = TypeHelper.GetUnderlyingTypeOrSelf(configuration.ClrType);

                if (!configurationClrType.IsEnum)
                {
                    configurationClrType = configuration.ClrType;
                }

                IEdmType type;

                if (availableTypes.TryGetValue(configurationClrType, out type))
                {
                    if (kind == EdmTypeKind.Complex)
                    {
                        return(new EdmComplexTypeReference((IEdmComplexType)type, nullable));
                    }
                    else if (kind == EdmTypeKind.Entity)
                    {
                        return(new EdmEntityTypeReference((IEdmEntityType)type, nullable));
                    }
                    else if (kind == EdmTypeKind.Enum)
                    {
                        return(new EdmEnumTypeReference((IEdmEnumType)type, nullable));
                    }
                    else
                    {
                        throw Error.InvalidOperation(SRResources.UnsupportedEdmTypeKind, kind.ToString());
                    }
                }
                else if (configuration.Kind == EdmTypeKind.Primitive)
                {
                    PrimitiveTypeConfiguration primitiveTypeConfiguration = configuration as PrimitiveTypeConfiguration;
                    return(new EdmPrimitiveTypeReference(primitiveTypeConfiguration.EdmPrimitiveType, nullable));
                }
                else
                {
                    throw Error.InvalidOperation(SRResources.NoMatchingIEdmTypeFound, configuration.FullName);
                }
            }
        }
Exemple #23
0
        private void CreateEdmTypeHeader(IEdmTypeConfiguration config)
        {
            IEdmType edmType = GetEdmType(config.ClrType);

            if (edmType == null)
            {
                if (config.Kind == EdmTypeKind.Complex)
                {
                    ComplexTypeConfiguration complex  = (ComplexTypeConfiguration)config;
                    IEdmComplexType          baseType = null;
                    if (complex.BaseType != null)
                    {
                        CreateEdmTypeHeader(complex.BaseType);
                        baseType = GetEdmType(complex.BaseType.ClrType) as IEdmComplexType;

                        Contract.Assert(baseType != null);
                    }

                    EdmComplexType complexType = new EdmComplexType(config.Namespace, config.Name,
                                                                    baseType, complex.IsAbstract ?? false, complex.IsOpen);

                    _types.Add(config.ClrType, complexType);

                    if (complex.IsOpen)
                    {
                        // add a mapping between the open complex type and its dynamic property dictionary.
                        _openTypes.Add(complexType, complex.DynamicPropertyDictionary);
                    }
                    edmType = complexType;
                }
                else if (config.Kind == EdmTypeKind.Entity)
                {
                    EntityTypeConfiguration entity = config as EntityTypeConfiguration;
                    Contract.Assert(entity != null);

                    IEdmEntityType baseType = null;
                    if (entity.BaseType != null)
                    {
                        CreateEdmTypeHeader(entity.BaseType);
                        baseType = GetEdmType(entity.BaseType.ClrType) as IEdmEntityType;

                        Contract.Assert(baseType != null);
                    }

                    EdmEntityType entityType = new EdmEntityType(config.Namespace, config.Name, baseType,
                                                                 entity.IsAbstract ?? false, entity.IsOpen, entity.HasStream);
                    _types.Add(config.ClrType, entityType);

                    if (entity.IsOpen)
                    {
                        // add a mapping between the open entity type and its dynamic property dictionary.
                        _openTypes.Add(entityType, entity.DynamicPropertyDictionary);
                    }
                    edmType = entityType;
                }
                else
                {
                    EnumTypeConfiguration enumTypeConfiguration = config as EnumTypeConfiguration;

                    // The config has to be enum.
                    Contract.Assert(enumTypeConfiguration != null);

                    _types.Add(enumTypeConfiguration.ClrType,
                               new EdmEnumType(enumTypeConfiguration.Namespace, enumTypeConfiguration.Name,
                                               GetTypeKind(enumTypeConfiguration.UnderlyingType), enumTypeConfiguration.IsFlags));
                }
            }

            IEdmStructuredType          structuredType = edmType as IEdmStructuredType;
            StructuralTypeConfiguration structuralTypeConfiguration = config as StructuralTypeConfiguration;

            if (structuredType != null && structuralTypeConfiguration != null &&
                !_structuredTypeQuerySettings.ContainsKey(structuredType))
            {
                //ModelBoundQuerySettings querySettings =
                //    structuralTypeConfiguration.QueryConfiguration.ModelBoundQuerySettings;
                //if (querySettings != null)
                //{
                //    _structuredTypeQuerySettings.Add(structuredType,
                //        structuralTypeConfiguration.QueryConfiguration.ModelBoundQuerySettings);
                //}
            }
        }
        private static IEdmTypeReference GetEdmTypeReference(Dictionary<Type, IEdmStructuredType> availableTypes, IEdmTypeConfiguration configuration, bool nullable)
        {
            Contract.Assert(availableTypes != null);

            if (configuration == null)
            {
                return null;
            }

            EdmTypeKind kind = configuration.Kind;
            if (kind == EdmTypeKind.Collection)
            {
                CollectionTypeConfiguration collectionType = configuration as CollectionTypeConfiguration;
                EdmCollectionType edmCollectionType = new EdmCollectionType(GetEdmTypeReference(availableTypes, collectionType.ElementType, false));
                return new EdmCollectionTypeReference(edmCollectionType, nullable);
            }
            else if (availableTypes.ContainsKey(configuration.ClrType))
            {
                IEdmStructuredType structuralType = availableTypes[configuration.ClrType];
                if (kind == EdmTypeKind.Complex)
                {
                    return new EdmComplexTypeReference(structuralType as IEdmComplexType, nullable);
                }
                else if (kind == EdmTypeKind.Entity)
                {
                    return new EdmEntityTypeReference(structuralType as IEdmEntityType, nullable);
                }
                else
                {
                    throw Error.InvalidOperation(SRResources.UnsupportedEdmTypeKind, kind.ToString());
                }
            }
            else if (configuration.Kind == EdmTypeKind.Primitive)
            {
                PrimitiveTypeConfiguration primitiveTypeConfiguration = configuration as PrimitiveTypeConfiguration;
                return new EdmPrimitiveTypeReference(primitiveTypeConfiguration.EdmPrimitiveType, nullable);
            }
            else
            {
                throw Error.InvalidOperation(SRResources.NoMatchingIEdmTypeFound, configuration.FullName);
            }
        }
Exemple #25
0
        private void CreateEdmTypeHeader(IEdmTypeConfiguration config)
        {
            if (GetEdmType(config.ClrType) == null)
            {
                if (config.Kind == EdmTypeKind.Complex)
                {
                    ComplexTypeConfiguration complex  = (ComplexTypeConfiguration)config;
                    IEdmComplexType          baseType = null;
                    if (complex.BaseType != null)
                    {
                        CreateEdmTypeHeader(complex.BaseType);
                        baseType = GetEdmType(complex.BaseType.ClrType) as IEdmComplexType;

                        Contract.Assert(baseType != null);
                    }

                    EdmComplexType complexType = new EdmComplexType(config.Namespace, config.Name,
                                                                    baseType, complex.IsAbstract ?? false, complex.IsOpen);

                    _types.Add(config.ClrType, complexType);

                    if (complex.IsOpen)
                    {
                        // add a mapping between the open complex type and its dynamic property dictionary.
                        _openTypes.Add(complexType, complex.DynamicPropertyDictionary);
                    }
                }
                else if (config.Kind == EdmTypeKind.Entity)
                {
                    EntityTypeConfiguration entity = config as EntityTypeConfiguration;
                    Contract.Assert(entity != null);

                    IEdmEntityType baseType = null;
                    if (entity.BaseType != null)
                    {
                        CreateEdmTypeHeader(entity.BaseType);
                        baseType = GetEdmType(entity.BaseType.ClrType) as IEdmEntityType;

                        Contract.Assert(baseType != null);
                    }

                    EdmEntityType entityType = new EdmEntityType(config.Namespace, config.Name, baseType,
                                                                 entity.IsAbstract ?? false, entity.IsOpen);
                    _types.Add(config.ClrType, entityType);

                    if (entity.IsOpen)
                    {
                        // add a mapping between the open entity type and its dynamic property dictionary.
                        _openTypes.Add(entityType, entity.DynamicPropertyDictionary);
                    }
                }
                else
                {
                    EnumTypeConfiguration enumTypeConfiguration = config as EnumTypeConfiguration;

                    // The config has to be enum.
                    Contract.Assert(enumTypeConfiguration != null);

                    _types.Add(enumTypeConfiguration.ClrType,
                               new EdmEnumType(enumTypeConfiguration.Namespace, enumTypeConfiguration.Name,
                                               GetTypeKind(enumTypeConfiguration.UnderlyingType), enumTypeConfiguration.IsFlags));
                }
            }
        }
 /// <summary>
 /// Specifies the bindingParameter name, type and whether it is alwaysBindable, use only if the Function "isBindable".
 /// </summary>
 public FunctionConfiguration SetBindingParameter(string name, IEdmTypeConfiguration bindingParameterType, bool alwaysBindable)
 {
     SetBindingParameterImplementation(name, bindingParameterType, alwaysBindable);
     return(this);
 }
 /// <summary>
 /// Specifies the bindingParameter name, type and whether it is alwaysBindable, use only if the Action "isBindable".
 /// </summary>
 public ActionConfiguration SetBindingParameter(string name, IEdmTypeConfiguration bindingParameterType)
 {
     SetBindingParameterImplementation(name, bindingParameterType);
     return(this);
 }