예제 #1
0
        public static List <T> ConvertDataToObject <T>(DataTable dataTable, Dictionary <string, string> mapping)
        {
            List <T>     list        = new List <T>(dataTable.Rows.Count);
            IEntityProxy entityProxy = EntityProxyManager.Instance.GetEntityProxyFromType(typeof(T));

            if (mapping == null || mapping.Count == 0)
            {
                foreach (DataRow row in dataTable.Rows)
                {
                    T obj = (T)entityProxy.CreateInstance();

                    foreach (DataColumn column in row.Table.Columns)
                    {
                        entityProxy.SetPropertyValue(obj, column.ColumnName, row[column]);
                    }

                    list.Add(obj);
                }
            }
            else
            {
                foreach (DataRow row in dataTable.Rows)
                {
                    T obj = (T)entityProxy.CreateInstance();

                    foreach (DataColumn column in row.Table.Columns)
                    {
                        string columnName = column.ColumnName;
                        if (mapping.ContainsKey(columnName))
                        {
                            entityProxy.SetPropertyValue(obj, mapping[columnName], row[column]);
                        }
                        else
                        {
                            entityProxy.SetPropertyValue(obj, columnName, row[column]);
                        }
                    }

                    list.Add(obj);
                }
            }

            return(list);
        }
예제 #2
0
        public ControllerInfo(Type type)
        {
            try
            {
                this.Type = type;
                this.Name = GetControllerName();

                entityProxy = EntityProxyManager.Instance.GetEntityProxyFromType(type);

                BeeControllerAttribute beeControllerAttribute = entityProxy.GetCustomerAttribute <BeeControllerAttribute>();
                if (beeControllerAttribute != null)
                {
                    DefaultFlag = beeControllerAttribute.DefaultFlag;

                    if (!string.IsNullOrEmpty(beeControllerAttribute.ControllerName))
                    {
                        if (!string.IsNullOrEmpty(beeControllerAttribute.AreaName))
                        {
                            this.Name = "{0}|{1}".FormatWith(beeControllerAttribute.AreaName, beeControllerAttribute.ControllerName);
                        }
                        else
                        {
                            this.Name = beeControllerAttribute.ControllerName;
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(beeControllerAttribute.AreaName))
                        {
                            this.Name = "{0}|{1}".FormatWith(beeControllerAttribute.AreaName, this.Name);
                        }
                    }
                }

                this.LowerName = Name.ToLower();

                DefaultAction = "Index";
                foreach (MethodSchema item in entityProxy.GetMethodList())
                {
                    ActionAttribute actionAttribute = item.GetCustomerAttribute <ActionAttribute>();
                    if (actionAttribute != null && actionAttribute.DefaultFlag)
                    {
                        DefaultAction = item.Name;
                        break;
                    }
                }

                // 构造一个Controller实例, 以初始化类静态构造函数。
                //ReflectionUtil.CreateInstance(type);
                entityProxy.CreateInstance();
            }
            catch (Exception e)
            {
                throw new CoreException("type:{0}".FormatWith(type), e);
            }
        }
예제 #3
0
 internal static MvcRouteDispatcher CreateMvcDispatcher()
 {
     if (mvcDispatchType == typeof(MvcRouteDispatcher))
     {
         return(new MvcRouteDispatcher());
     }
     else
     {
         IEntityProxy entityProxy = EntityProxyManager.Instance.GetEntityProxyFromType(mvcDispatchType);
         return(entityProxy.CreateInstance() as MvcRouteDispatcher);
     }
 }
예제 #4
0
 internal object CreateInstance()
 {
     return(entityProxy.CreateInstance());
 }