public GetDataPropertyType ( |
||
type | Entity type for which metadata is being generated | |
propertyInfo | Property being considered | |
return |
/// <summary> /// Make data property metadata for the entity property. /// Attributes one the property are used to set some metadata values. /// </summary> /// <param name="propertyInfo">Property info for the property</param> /// <param name="containingType">Type containing the property</param> /// <param name="isKey">true if this property is part of the key for the entity</param> /// <param name="isVersion">true if this property contains the version of the entity (for a concurrency strategy)</param> /// <returns>Dictionary of metadata for the property</returns> private Dictionary <string, object> MakeDataProperty(Type containingType, PropertyInfo propertyInfo, bool isKey, bool isVersion) { var propType = _describer.GetDataPropertyType(containingType, propertyInfo); if (propType == null) { return(null); // exclude this property } var nullableType = Nullable.GetUnderlyingType(propType); var isNullable = nullableType != null || !propType.IsValueType; propType = nullableType ?? propType; var dmap = new Dictionary <string, object>(); dmap.Add("nameOnServer", propertyInfo.Name); var elementType = GetElementType(propType); if (_describer.IsComplexType(elementType)) { dmap.Add("complexTypeName", elementType.Name + ":#" + elementType.Namespace); } else { dmap.Add("dataType", elementType.Name); } if (elementType != propType) { dmap.Add("isScalar", false); } if (!isNullable) { dmap.Add("isNullable", false); } AddAttributesToDataProperty(propertyInfo, dmap, _describer); if (isKey) { dmap["isPartOfKey"] = true; } if (isVersion) { dmap["concurrencyMode"] = "Fixed"; } if (propType.IsEnum) { dmap["dataType"] = "String"; dmap["enumType"] = propType.Name; } var validators = (List <Dictionary <string, object> >)dmap.Get("validators"); if (validators == null) { validators = new List <Dictionary <string, object> >(); } if (!isNullable) { var already = FindEntry(validators, "name", "required"); if (already == null) { validators.Add(new Dictionary <string, object>() { { "name", "required" } }); } } string validationType; if (ValidationTypeMap.TryGetValue(propType.Name, out validationType)) { validators.Add(new Dictionary <string, object>() { { "name", validationType } }); } if (validators.Any()) { dmap["validators"] = validators; } return(dmap); }