public static object ConvertStringToPropertyTypeValue(object @object, string key, Type propertyInfoPropertyType) { NameValueCollection nameValueCollection = @object as NameValueCollection; if (nameValueCollection == null) { return(null); } string keyValue = nameValueCollection.Get(key); object value = CovertFromPrimitiveType(keyValue, propertyInfoPropertyType); if (value != null) { return(value); } dynamic childJObject = JsonConvert.DeserializeObject(keyValue); if (childJObject != null) { MetaShare.Common.Core.Entities.Common relatedEntity = Activator.CreateInstance(propertyInfoPropertyType) as MetaShare.Common.Core.Entities.Common; if (relatedEntity != null) { ICollection <string> keys = GetJsonKeys(childJObject); UpdateEntityValue(relatedEntity, childJObject, keys, new GetPropertyValueByRequestKey(ConvertJTokenToPropertyTypeValue)); return(relatedEntity); } } return(null); }
internal static List <string> GetColumnStrings(MetaShare.Common.Core.Entities.Common newEntity, ICollection <string> keys) { List <string> allKeys = new List <string>(); if (newEntity != null) { Type type = newEntity.GetType(); PropertyInfo[] propertyInfos = type.GetProperties(BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public); foreach (string key in keys) { string newKey = string.Empty; foreach (PropertyInfo propertyInfo in propertyInfos) { if (propertyInfo.Name.ToLower().Equals(key.ToLower())) { newKey = key; if (!propertyInfo.PropertyType.IsPrimitive && propertyInfo.PropertyType != typeof(string) && !propertyInfo.PropertyType.IsEnum) { MetaShare.Common.Core.Entities.Common relatedEntity = Activator.CreateInstance(propertyInfo.PropertyType) as MetaShare.Common.Core.Entities.Common; if (relatedEntity != null) { newKey = key + "Id"; } } } } if (!string.IsNullOrEmpty(newKey)) { allKeys.Add(newKey); } } } return(allKeys); }
internal static MetaShare.Common.Core.Entities.Common GetEntityFromRequest(MetaShare.Common.Core.Entities.Common newEntity, NameValueCollection nameValueCollection) { if (newEntity == null) throw new Exception("Entity can not be null."); ICollection<string> keys = nameValueCollection.AllKeys; UpdateEntityValue(newEntity, nameValueCollection, keys, ConvertStringToPropertyTypeValue); return newEntity; }