/// <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);
        }
Example #2
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);
        }
Example #3
0
		private OP.IRole CastRole(PC.SchemaObjectBase obj, OP.IApplication app)
		{
			OP.RoleImpl role = Util.GetPermissionObjectFactory().CreateObject(typeof(OP.IRole)) as OP.RoleImpl;
			var wrapper = role as OP.IApplicationMemberPropertyAccessible;

			if (wrapper == null)
				throw new InvalidCastException("工厂创建的对象应实现IApplicationMemberPropertyAccessible,否则无法适用此工厂。");

			wrapper.CodeName = obj.Properties.GetValue<string>("CodeName", string.Empty);
			wrapper.Description = obj.Properties.GetValue<string>("Description", string.Empty);
			wrapper.ID = obj.ID;
			wrapper.Name = obj.Properties.GetValue<string>("Name", string.Empty);
			wrapper.Application = app;

			return role;
		}
        /// <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;
        }