Exemplo n.º 1
0
        private static PermissionObjBaseImpl CreateObjectByType(System.Type type)
        {
            PermissionObjBaseImpl result = null;

            if (type == typeof(IApplication))
            {
                result = new ApplicationImpl();
            }
            else
            if (type == typeof(IRole))
            {
                result = new RoleImpl();
            }
            else
            if (type == typeof(IPermission))
            {
                result = new PermissionImpl();
            }
            else
            {
                throw new InvalidOperationException(string.Format(Resource.InvalidObjectTypeCreation, type.ToString()));
            }

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="type">授权对象的接口类型</param>
        /// <returns>授权对象</returns>
        public IPermissionObject CreateObject(System.Type type)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(type != null, "type");

            PermissionObjBaseImpl result = null;

            if (type == typeof(IApplication))
            {
                result = new ApplicationImpl();
            }
            else
            if (type == typeof(IRole))
            {
                result = new RoleImpl();
            }
            else
            if (type == typeof(IPermission))
            {
                result = new PermissionImpl();
            }
            else
            {
                throw new InvalidOperationException(string.Format(Resource.InvalidObjectTypeCreation, type.ToString()));
            }

            return(result);
        }
Exemplo n.º 3
0
        private static List <T> BuildObjectsFromTable <T>(DataTable table) where T : IPermissionObject
        {
            List <T> list = new List <T>();

            foreach (DataRow row in table.Rows)
            {
                IPermissionObject baseObject = OguPermissionSettings.GetConfig().PermissionObjectFactory.CreateObject(typeof(T));

                if (baseObject is PermissionObjBaseImpl)
                {
                    PermissionObjBaseImpl oBase = (PermissionObjBaseImpl)baseObject;
                    oBase.InitProperties(row);

                    list.Add((T)(oBase as object));
                }
            }

            return(list);
        }