/// <summary> /// Adds a primitive property to this edm type. /// </summary> /// <param name="propertyInfo">The property being added.</param> /// <returns>The <see cref="PrimitivePropertyConfiguration"/> so that the property can be configured further.</returns> public virtual PrimitivePropertyConfiguration AddProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.ReflectedType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } ValidatePropertyNotAlreadyDefinedInBaseTypes(propertyInfo); ValidatePropertyNotAlreadyDefinedInDerivedTypes(propertyInfo); // Remove from the ignored properties if (RemovedProperties.Any(prop => prop.Name.Equals(propertyInfo.Name))) { RemovedProperties.Remove(RemovedProperties.First(prop => prop.Name.Equals(propertyInfo.Name))); } PrimitivePropertyConfiguration propertyConfiguration = ValidatePropertyNotAlreadyDefinedOtherTypes <PrimitivePropertyConfiguration>(propertyInfo, SRResources.MustBePrimitiveProperty); if (propertyConfiguration == null) { propertyConfiguration = new PrimitivePropertyConfiguration(propertyInfo, this); ExplicitProperties[propertyInfo] = propertyConfiguration; } return(propertyConfiguration); }
/// <summary> /// Adds the property info of the instanceannotation to this structural type. /// </summary> /// <param name="propertyInfo">The property being added.</param> public virtual void AddInstanceAnnotationContainer(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } TypeHelper.ValidateAssignableFromForArgument(typeof(IODataInstanceAnnotationContainer), propertyInfo.PropertyType, "IODataInstanceAnnotationContainer"); if (!propertyInfo.DeclaringType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType); } // Remove from the ignored properties if (IgnoredProperties.Contains(propertyInfo)) { RemovedProperties.Remove(propertyInfo); } if (_instanceAnnotationContainer != null) { throw Error.Argument("propertyInfo", SRResources.MoreThanOneAnnotationPropertyContainerFound, ClrType.Name); } _instanceAnnotationContainer = propertyInfo; }
/// <summary> /// Removes the given property. /// </summary> /// <param name="propertyInfo">The property being removed.</param> public virtual void RemoveProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.DeclaringType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } if (ExplicitProperties.ContainsKey(propertyInfo)) { ExplicitProperties.Remove(propertyInfo); } if (!RemovedProperties.Contains(propertyInfo)) { RemovedProperties.Add(propertyInfo); } if (_dynamicPropertyDictionary == propertyInfo) { _dynamicPropertyDictionary = null; } }
/// <summary> /// Adds the property info of the dynamic properties to this structural type. /// </summary> /// <param name="propertyInfo">The property being added.</param> public virtual void AddDynamicPropertyDictionary(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!typeof(IDictionary <string, object>).IsAssignableFrom(propertyInfo.PropertyType)) { throw Error.Argument("propertyInfo", SRResources.ArgumentMustBeOfType, "IDictionary<string, object>"); } if (!propertyInfo.DeclaringType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType); } // Remove from the ignored properties if (IgnoredProperties.Contains(propertyInfo)) { RemovedProperties.Remove(propertyInfo); } if (_dynamicPropertyDictionary != null) { throw Error.Argument("propertyInfo", SRResources.MoreThanOneDynamicPropertyContainerFound, ClrType.Name); } _dynamicPropertyDictionary = propertyInfo; }
/// <summary> /// Removes the given property. /// </summary> /// <param name="propertyInfo">The property being removed.</param> public virtual void RemoveProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.ReflectedType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } if (ExplicitProperties.Keys.Any(key => key.Name.Equals(propertyInfo.Name))) { ExplicitProperties.Remove(ExplicitProperties.Keys.First(key => key.Name.Equals(propertyInfo.Name))); } if (!RemovedProperties.Any(prop => prop.Name.Equals(propertyInfo.Name))) { RemovedProperties.Add(propertyInfo); } if (_dynamicPropertyDictionary == propertyInfo) { _dynamicPropertyDictionary = null; } }
/// <summary> /// Adds a collection property to this edm type. /// </summary> /// <param name="propertyInfo">The property being added.</param> /// <returns>The <see cref="CollectionPropertyConfiguration"/> so that the property can be configured further.</returns> public virtual CollectionPropertyConfiguration AddCollectionProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.DeclaringType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType); } ValidatePropertyNotAlreadyDefinedInBaseTypes(propertyInfo); ValidatePropertyNotAlreadyDefinedInDerivedTypes(propertyInfo); // Remove from the ignored properties if (IgnoredProperties.Contains(propertyInfo)) { RemovedProperties.Remove(propertyInfo); } CollectionPropertyConfiguration propertyConfiguration; if (ExplicitProperties.ContainsKey(propertyInfo)) { propertyConfiguration = ExplicitProperties[propertyInfo] as CollectionPropertyConfiguration; if (propertyConfiguration == null) { throw Error.Argument("propertyInfo", SRResources.MustBeCollectionProperty, propertyInfo.Name, propertyInfo.DeclaringType.FullName); } } else { propertyConfiguration = new CollectionPropertyConfiguration(propertyInfo, this); ExplicitProperties[propertyInfo] = propertyConfiguration; // If the ElementType is the same as this type this is recursive complex type nesting if (propertyConfiguration.ElementType == ClrType) { throw Error.Argument("propertyInfo", SRResources.RecursiveComplexTypesNotAllowed, ClrType.Name, propertyConfiguration.Name); } // If the ElementType is not primitive or enum treat as a ComplexType and Add to the model. IEdmPrimitiveTypeReference edmType = EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(propertyConfiguration.ElementType); if (edmType == null) { if (!TypeHelper.IsEnum(propertyConfiguration.ElementType)) { ModelBuilder.AddComplexType(propertyConfiguration.ElementType); } } } return(propertyConfiguration); }
public virtual ComplexPropertyConfiguration AddComplexProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.ReflectedType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } if (propertyInfo.PropertyType == ClrType) { throw Error.Argument("propertyInfo", SRResources.RecursiveComplexTypesNotAllowed, ClrType.FullName, propertyInfo.Name); } if (propertyInfo.PropertyType == typeof(DateTime) || propertyInfo.PropertyType == typeof(DateTime?)) { throw Error.Argument("propertyInfo", SRResources.DateTimeTypePropertyNotSupported, propertyInfo.PropertyType.FullName, propertyInfo.Name, propertyInfo.DeclaringType.FullName, typeof(DateTimeOffset).FullName, typeof(ODataModelBuilder).FullName); } ValidatePropertyNotAlreadyDefinedInBaseTypes(propertyInfo); ValidatePropertyNotAlreadyDefinedInDerivedTypes(propertyInfo); // Remove from the ignored properties if (RemovedProperties.Contains(propertyInfo)) { RemovedProperties.Remove(propertyInfo); } ComplexPropertyConfiguration propertyConfiguration = null; if (ExplicitProperties.ContainsKey(propertyInfo)) { propertyConfiguration = ExplicitProperties[propertyInfo] as ComplexPropertyConfiguration; if (propertyConfiguration == null) { throw Error.Argument("propertyInfo", SRResources.MustBeComplexProperty, propertyInfo.Name, ClrType.FullName); } } else { propertyConfiguration = new ComplexPropertyConfiguration(propertyInfo, this); ExplicitProperties[propertyInfo] = propertyConfiguration; // Make sure the complex type is in the model. ModelBuilder.AddComplexType(propertyInfo.PropertyType); } return propertyConfiguration; }
/// <summary> /// Adds a primitive property to this edm type. /// </summary> /// <param name="propertyInfo">The property being added.</param> /// <returns>The <see cref="PrimitivePropertyConfiguration"/> so that the property can be configured further.</returns> public virtual PrimitivePropertyConfiguration AddProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.ReflectedType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } ValidatePropertyNotAlreadyDefinedInBaseTypes(propertyInfo); //I comment this validity check due to perfomanse issue https://github.com/OData/WebApi/issues/876 //ValidatePropertyNotAlreadyDefinedInDerivedTypes(propertyInfo); // Remove from the ignored properties if (RemovedProperties.Any(prop => prop.Name.Equals(propertyInfo.Name))) { RemovedProperties.Remove(RemovedProperties.First(prop => prop.Name.Equals(propertyInfo.Name))); } PrimitivePropertyConfiguration propertyConfiguration = ValidatePropertyNotAlreadyDefinedOtherTypes <PrimitivePropertyConfiguration>(propertyInfo, SRResources.MustBePrimitiveProperty); if (propertyConfiguration == null) { propertyConfiguration = new PrimitivePropertyConfiguration(propertyInfo, this); var primitiveType = EdmLibHelpers.GetEdmPrimitiveTypeOrNull(propertyInfo.PropertyType); if (primitiveType != null) { if (primitiveType.PrimitiveKind == EdmPrimitiveTypeKind.Decimal) { propertyConfiguration = new DecimalPropertyConfiguration(propertyInfo, this); } else if (EdmLibHelpers.HasLength(primitiveType.PrimitiveKind)) { propertyConfiguration = new LengthPropertyConfiguration(propertyInfo, this); } else if (EdmLibHelpers.HasPrecision(primitiveType.PrimitiveKind)) { propertyConfiguration = new PrecisionPropertyConfiguration(propertyInfo, this); } } ExplicitProperties[propertyInfo] = propertyConfiguration; } return(propertyConfiguration); }
/// <summary> /// Adds a primitive property to this edm type. /// </summary> /// <param name="propertyInfo">The property being added.</param> /// <returns>The <see cref="PrimitivePropertyConfiguration"/> so that the property can be configured further.</returns> public virtual PrimitivePropertyConfiguration AddProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!TypeHelper.GetReflectedType(propertyInfo).IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } ValidatePropertyNotAlreadyDefinedInBaseTypes(propertyInfo); ValidatePropertyNotAlreadyDefinedInDerivedTypes(propertyInfo); // Remove from the ignored properties if (RemovedProperties.Any(prop => prop.Name.Equals(propertyInfo.Name, StringComparison.Ordinal))) { RemovedProperties.Remove(RemovedProperties.First(prop => prop.Name.Equals(propertyInfo.Name, StringComparison.Ordinal))); } PrimitivePropertyConfiguration propertyConfiguration = ValidatePropertyNotAlreadyDefinedOtherTypes <PrimitivePropertyConfiguration>(propertyInfo, SRResources.MustBePrimitiveProperty); if (propertyConfiguration == null) { propertyConfiguration = new PrimitivePropertyConfiguration(propertyInfo, this); var primitiveType = EdmLibHelpers.GetEdmPrimitiveTypeOrNull(propertyInfo.PropertyType); if (primitiveType != null) { if (primitiveType.PrimitiveKind == EdmPrimitiveTypeKind.Decimal) { propertyConfiguration = new DecimalPropertyConfiguration(propertyInfo, this); } else if (EdmLibHelpers.HasLength(primitiveType.PrimitiveKind)) { propertyConfiguration = new LengthPropertyConfiguration(propertyInfo, this); } else if (EdmLibHelpers.HasPrecision(primitiveType.PrimitiveKind)) { propertyConfiguration = new PrecisionPropertyConfiguration(propertyInfo, this); } } ExplicitProperties[propertyInfo] = propertyConfiguration; } return(propertyConfiguration); }
/// <summary> /// Adds a collection property to this edm type. /// </summary> /// <param name="propertyInfo">The property being added.</param> /// <returns>The <see cref="CollectionPropertyConfiguration"/> so that the property can be configured further.</returns> public virtual CollectionPropertyConfiguration AddCollectionProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.DeclaringType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType); } ValidatePropertyNotAlreadyDefinedInBaseTypes(propertyInfo); ValidatePropertyNotAlreadyDefinedInDerivedTypes(propertyInfo); // Remove from the ignored properties if (RemovedProperties.Any(prop => prop.Name.Equals(propertyInfo.Name, StringComparison.Ordinal))) { RemovedProperties.Remove(RemovedProperties.First(prop => prop.Name.Equals(propertyInfo.Name, StringComparison.Ordinal))); } CollectionPropertyConfiguration propertyConfiguration = ValidatePropertyNotAlreadyDefinedOtherTypes <CollectionPropertyConfiguration>(propertyInfo, SRResources.MustBeCollectionProperty); if (propertyConfiguration == null) { propertyConfiguration = new CollectionPropertyConfiguration(propertyInfo, this); ExplicitProperties[propertyInfo] = propertyConfiguration; // If the ElementType is not primitive or enum treat as a ComplexType and Add to the model. IEdmPrimitiveTypeReference edmType = EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(propertyConfiguration.ElementType); if (edmType == null) { if (!TypeHelper.IsEnum(propertyConfiguration.ElementType)) { ModelBuilder.AddComplexType(propertyConfiguration.ElementType); } } } return(propertyConfiguration); }
public virtual ComplexPropertyConfiguration AddComplexProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.ReflectedType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } if (propertyInfo.PropertyType == ClrType) { throw Error.Argument("propertyInfo", SRResources.RecursiveComplexTypesNotAllowed, ClrType.FullName, propertyInfo.Name); } // Remove from the ignored properties if (RemovedProperties.Contains(propertyInfo)) { RemovedProperties.Remove(propertyInfo); } ComplexPropertyConfiguration propertyConfiguration = null; if (ExplicitProperties.ContainsKey(propertyInfo)) { propertyConfiguration = ExplicitProperties[propertyInfo] as ComplexPropertyConfiguration; if (propertyConfiguration == null) { throw Error.Argument("propertyInfo", SRResources.MustBeComplexProperty, propertyInfo.Name, ClrType.FullName); } } else { propertyConfiguration = new ComplexPropertyConfiguration(propertyInfo, this); ExplicitProperties[propertyInfo] = propertyConfiguration; // Make sure the complex type is in the model. ModelBuilder.AddComplexType(propertyInfo.PropertyType); } return(propertyConfiguration); }
/// <summary> /// Adds an enum property to this edm type. /// </summary> /// <param name="propertyInfo">The property being added.</param> /// <returns>The <see cref="EnumPropertyConfiguration"/> so that the property can be configured further.</returns> public virtual EnumPropertyConfiguration AddEnumProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.ReflectedType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } if (!TypeHelper.IsEnum(propertyInfo.PropertyType)) { throw Error.Argument("propertyInfo", SRResources.MustBeEnumProperty, propertyInfo.Name, ClrType.FullName); } ValidatePropertyNotAlreadyDefinedInBaseTypes(propertyInfo); ValidatePropertyNotAlreadyDefinedInDerivedTypes(propertyInfo); // Remove from the ignored properties if (RemovedProperties.Contains(propertyInfo)) { RemovedProperties.Remove(propertyInfo); } EnumPropertyConfiguration propertyConfiguration; if (ExplicitProperties.ContainsKey(propertyInfo)) { propertyConfiguration = ExplicitProperties[propertyInfo] as EnumPropertyConfiguration; if (propertyConfiguration == null) { throw Error.Argument("propertyInfo", SRResources.MustBeEnumProperty, propertyInfo.Name, ClrType.FullName); } } else { propertyConfiguration = new EnumPropertyConfiguration(propertyInfo, this); ExplicitProperties[propertyInfo] = propertyConfiguration; } return(propertyConfiguration); }
/// <summary> /// Adds a primitive property to this edm type. /// </summary> /// <param name="propertyInfo">The property being added.</param> /// <returns>The <see cref="PrimitivePropertyConfiguration"/> so that the property can be configured further.</returns> public virtual PrimitivePropertyConfiguration AddProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.ReflectedType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } if (propertyInfo.PropertyType == typeof(DateTime) || propertyInfo.PropertyType == typeof(DateTime?)) { throw Error.Argument("propertyInfo", SRResources.DateTimeTypePropertyNotSupported, propertyInfo.PropertyType.FullName, propertyInfo.Name, propertyInfo.DeclaringType.FullName, typeof(DateTimeOffset).FullName, typeof(ODataModelBuilder).FullName); } // Remove from the ignored properties if (RemovedProperties.Contains(propertyInfo)) { RemovedProperties.Remove(propertyInfo); } PrimitivePropertyConfiguration propertyConfiguration = null; if (ExplicitProperties.ContainsKey(propertyInfo)) { propertyConfiguration = ExplicitProperties[propertyInfo] as PrimitivePropertyConfiguration; if (propertyConfiguration == null) { throw Error.Argument("propertyInfo", SRResources.MustBePrimitiveProperty, propertyInfo.Name, ClrType.FullName); } } else { propertyConfiguration = new PrimitivePropertyConfiguration(propertyInfo, this); ExplicitProperties[propertyInfo] = propertyConfiguration; } return(propertyConfiguration); }
public virtual ComplexPropertyConfiguration AddComplexProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.ReflectedType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } if (propertyInfo.PropertyType == ClrType) { throw Error.Argument("propertyInfo", SRResources.RecursiveComplexTypesNotAllowed, ClrType.FullName, propertyInfo.Name); } ValidatePropertyNotAlreadyDefinedInBaseTypes(propertyInfo); ValidatePropertyNotAlreadyDefinedInDerivedTypes(propertyInfo); // Remove from the ignored properties if (RemovedProperties.Any(prop => prop.Name.Equals(propertyInfo.Name))) { RemovedProperties.Remove(RemovedProperties.First(prop => prop.Name.Equals(propertyInfo.Name))); } ComplexPropertyConfiguration propertyConfiguration = ValidatePropertyNotAlreadyDefinedOtherTypes <ComplexPropertyConfiguration>(propertyInfo, SRResources.MustBeComplexProperty); if (propertyConfiguration == null) { propertyConfiguration = new ComplexPropertyConfiguration(propertyInfo, this); ExplicitProperties[propertyInfo] = propertyConfiguration; // Make sure the complex type is in the model. ModelBuilder.AddComplexType(propertyInfo.PropertyType); } return(propertyConfiguration); }
/// <summary> /// Removes the given property. /// </summary> /// <param name="propertyInfo">The property being removed.</param> public virtual void RemoveProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.ReflectedType.IsAssignableFrom(ClrType)) { throw Error.InvalidOperation(SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } if (ExplicitProperties.ContainsKey(propertyInfo)) { ExplicitProperties.Remove(propertyInfo); } if (!RemovedProperties.Contains(propertyInfo)) { RemovedProperties.Add(propertyInfo); } }
/// <summary> /// Adds an enum property to this edm type. /// </summary> /// <param name="propertyInfo">The property being added.</param> /// <returns>The <see cref="EnumPropertyConfiguration"/> so that the property can be configured further.</returns> public virtual EnumPropertyConfiguration AddEnumProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!TypeHelper.GetReflectedType(propertyInfo).IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } if (!TypeHelper.IsEnum(propertyInfo.PropertyType)) { throw Error.Argument("propertyInfo", SRResources.MustBeEnumProperty, propertyInfo.Name, ClrType.FullName); } ValidatePropertyNotAlreadyDefinedInBaseTypes(propertyInfo); ValidatePropertyNotAlreadyDefinedInDerivedTypes(propertyInfo); // Remove from the ignored properties if (RemovedProperties.Any(prop => prop.Name.Equals(propertyInfo.Name, StringComparison.Ordinal))) { RemovedProperties.Remove(RemovedProperties.First(prop => prop.Name.Equals(propertyInfo.Name, StringComparison.Ordinal))); } EnumPropertyConfiguration propertyConfiguration = ValidatePropertyNotAlreadyDefinedOtherTypes <EnumPropertyConfiguration>(propertyInfo, SRResources.MustBeEnumProperty); if (propertyConfiguration == null) { propertyConfiguration = new EnumPropertyConfiguration(propertyInfo, this); ExplicitProperties[propertyInfo] = propertyConfiguration; } return(propertyConfiguration); }
/// <summary> /// Adds the property info of the dynamic properties to this structural type. /// </summary> /// <param name="propertyInfo">The property being added.</param> public virtual void AddDynamicPropertyDictionary(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!typeof(IDictionary <string, object>).IsAssignableFrom(propertyInfo.PropertyType)) { throw Error.Argument("propertyInfo", SRResources.ArgumentMustBeOfType, "IDictionary<string, object>"); } if (!propertyInfo.DeclaringType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType); } // Throws NotSupported exception if attempting to add a dynamic property dictionary property // on open entity type. Please remove this block after supporting the open entity type. if (Kind == EdmTypeKind.Entity) { throw Error.NotSupported(SRResources.OpenEntityTypeNotSupported, propertyInfo.Name, Name); } // Remove from the ignored properties if (IgnoredProperties.Contains(propertyInfo)) { RemovedProperties.Remove(propertyInfo); } if (_dynamicPropertyDictionary != null) { throw Error.Argument("propertyInfo", SRResources.MoreThanOneDynamicPropertyContainerFound, ClrType.Name); } _dynamicPropertyDictionary = propertyInfo; }
/// <summary> /// Adds a primitive property to this edm type. /// </summary> /// <param name="propertyInfo">The property being added.</param> /// <returns>The <see cref="PrimitivePropertyConfiguration"/> so that the property can be configured further.</returns> public virtual PrimitivePropertyConfiguration AddProperty(PropertyInfo propertyInfo) { if (propertyInfo == null) { throw Error.ArgumentNull("propertyInfo"); } if (!propertyInfo.ReflectedType.IsAssignableFrom(ClrType)) { throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType, propertyInfo.Name, ClrType.FullName); } // Remove from the ignored properties if (RemovedProperties.Contains(propertyInfo)) { RemovedProperties.Remove(propertyInfo); } PrimitivePropertyConfiguration propertyConfiguration = null; if (ExplicitProperties.ContainsKey(propertyInfo)) { propertyConfiguration = ExplicitProperties[propertyInfo] as PrimitivePropertyConfiguration; if (propertyConfiguration == null) { throw Error.Argument("propertyInfo", SRResources.MustBePrimitiveProperty, propertyInfo.Name, ClrType.FullName); } } else { propertyConfiguration = new PrimitivePropertyConfiguration(propertyInfo, this); ExplicitProperties[propertyInfo] = propertyConfiguration; } return(propertyConfiguration); }