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)); }
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); }
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); }
public virtual bool IsRequired(PropertyInfo propertyInfo) { return(!PrimitiveTypeHelper.IsNullable(propertyInfo.PropertyType) || propertyInfo.GetCustomAttribute(typeof(RequiredAttribute)) != null || IsKey(propertyInfo)); }