예제 #1
0
        private static TData GetEntityData <TData>(object entity, System.Type entityType, Action <TData, string, object> action) where TData : class, new()
        {
            TData result;

            if (entity == null)
            {
                result = default(TData);
            }
            else
            {
                TData tData = System.Activator.CreateInstance <TData>();
                EntityClassAttribute             entityClassAttribute = JavaScriptSerializer.GetEntityClassAttribute(entityType);
                System.Reflection.PropertyInfo[] properties           = entityType.GetProperties();
                System.Reflection.PropertyInfo[] array = properties;
                for (int i = 0; i < array.Length; i++)
                {
                    System.Reflection.PropertyInfo propertyInfo = array[i];
                    string propertyKey = JavaScriptSerializer.GetPropertyKey(propertyInfo, entityClassAttribute);
                    object value       = propertyInfo.GetValue(entity, null);
                    if (value == null)
                    {
                        action(tData, propertyKey, value);
                    }
                    else
                    {
                        System.Type propertyType = propertyInfo.PropertyType;
                        if (propertyType.IsGenericType)
                        {
                            if (EntityFactory.IsIList(propertyType))
                            {
                                System.Type type = propertyType.GetGenericArguments()[0];
                                if (type.IsClass)
                                {
                                    System.Collections.IList entites = value as System.Collections.IList;
                                    System.Collections.Generic.IList <TData> entityDatas = EntityFactory.GetEntityDatas <TData>(entites, type, action);
                                    action(tData, propertyKey, entityDatas);
                                }
                            }
                        }
                        else if (!EntityFactory.IsPrimitiveType(propertyInfo.PropertyType))
                        {
                            action(tData, propertyKey, EntityFactory.GetEntityData <TData>(value, propertyInfo.PropertyType, action));
                        }
                        else
                        {
                            action(tData, propertyKey, value);
                        }
                    }
                }
                result = tData;
            }
            return(result);
        }
예제 #2
0
 internal static bool IsPrimitiveType(System.Type type)
 {
     System.Type type2;
     return(EntityFactory.IsPrimitiveType(type, out type2));
 }
예제 #3
0
 public T ToEntity <T>() where T : class, new()
 {
     return(EntityFactory.GetEntity <T, IHashMap>(this, (IHashMap ho, string key) => ho.GetValue <object>(key)));
 }