Ejemplo n.º 1
0
        private IEdmTypeReference GetEdmTypeReference(Type clrType, Dictionary <Type, EntityTypeInfo> entityTypeInfos)
        {
            bool nullable = PrimitiveTypeHelper.IsNullable(clrType);

            if (nullable)
            {
                Type underlyingType = Nullable.GetUnderlyingType(clrType);
                if (underlyingType != null)
                {
                    clrType = underlyingType;
                }
            }

            if (entityTypeInfos.TryGetValue(clrType, out EntityTypeInfo entityTypeInfo))
            {
                return(new EdmEntityTypeReference(entityTypeInfo.EdmType, nullable));
            }

            if (_enumTypes.TryGetValue(clrType, out EdmEnumType edmEnumType))
            {
                return(new EdmEnumTypeReference(edmEnumType, nullable));
            }

            if (_complexTypes.TryGetValue(clrType, out EdmComplexType edmComplexType))
            {
                return(new EdmComplexTypeReference(edmComplexType, nullable));
            }

            return(PrimitiveTypeHelper.GetPrimitiveTypeRef(clrType, nullable));
        }
Ejemplo n.º 2
0
        private IEdmTypeReference GetEdmTypeReference(Type clrType, Dictionary <Type, EntityTypeInfo> entityTypeInfos)
        {
            bool nullable = PrimitiveTypeHelper.IsNullable(clrType);

            if (nullable)
            {
                Type underlyingType = Nullable.GetUnderlyingType(clrType);
                if (underlyingType != null)
                {
                    clrType = underlyingType;
                }
            }

            if (entityTypeInfos.TryGetValue(clrType, out EntityTypeInfo entityTypeInfo))
            {
                return(new EdmEntityTypeReference(entityTypeInfo.EdmType, nullable));
            }

            if (_enumTypes.TryGetValue(clrType, out EdmEnumType edmEnumType))
            {
                return(new EdmEnumTypeReference(edmEnumType, nullable));
            }

            if (_complexTypes.TryGetValue(clrType, out EdmComplexType edmComplexType))
            {
                return(new EdmComplexTypeReference(edmComplexType, nullable));
            }

            IEdmTypeReference typeRef = PrimitiveTypeHelper.GetPrimitiveTypeRef(clrType, nullable);

            if (typeRef != null)
            {
                return(typeRef);
            }

            Type itemType = Parsers.OeExpressionHelper.GetCollectionItemType(clrType);

            if (itemType != null)
            {
                typeRef = GetEdmTypeReference(itemType, entityTypeInfos);
                return(new EdmCollectionTypeReference(new EdmCollectionType(typeRef)));
            }

            throw new InvalidOperationException("Not suppoertyed parameter type " + clrType.FullName);
        }
Ejemplo n.º 3
0
        private static EdmMultiplicity GetEdmMultiplicity(Type propertyType, PropertyInfo[] dependentStructuralProperties)
        {
            if (propertyType != null && Parsers.OeExpressionHelper.GetCollectionItemTypeOrNull(propertyType) != null)
            {
                return(EdmMultiplicity.Many);
            }

            if (dependentStructuralProperties.Length == 0)
            {
                return(EdmMultiplicity.Unknown);
            }

            foreach (PropertyInfo clrProperty in dependentStructuralProperties)
            {
                if (PrimitiveTypeHelper.IsNullable(clrProperty.PropertyType))
                {
                    return(EdmMultiplicity.ZeroOrOne);
                }
            }

            return(EdmMultiplicity.One);
        }
Ejemplo n.º 4
0
 public virtual bool IsRequired(PropertyInfo propertyInfo)
 {
     return(!PrimitiveTypeHelper.IsNullable(propertyInfo.PropertyType) ||
            propertyInfo.GetCustomAttribute(typeof(RequiredAttribute)) != null ||
            IsKey(propertyInfo));
 }