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);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Attempts to find either a pre-configured structural type or a primitive type that matches the T.
 /// If no matches are found NULL is returned.
 /// </summary>
 public IEdmTypeConfiguration GetTypeConfigurationOrNull(Type type)
 {
     if (_primitiveTypes.ContainsKey(type))
     {
         return(_primitiveTypes[type]);
     }
     else
     {
         IEdmPrimitiveType          edmType       = EdmLibHelpers.GetEdmPrimitiveTypeOrNull(type);
         PrimitiveTypeConfiguration primitiveType = null;
         if (edmType != null)
         {
             primitiveType         = new PrimitiveTypeConfiguration(this, edmType, type);
             _primitiveTypes[type] = primitiveType;
             return(primitiveType);
         }
         else if (_structuralTypes.ContainsKey(type))
         {
             return(_structuralTypes[type]);
         }
     }
     return(null);
 }