Esempio n. 1
0
        /// <summary>
        /// Gets modifiable properties on DisplayConfig.
        /// </summary>
        /// <param name="queryModifyPermissionLevel">The modification level which we wish to search for</param>
        /// <returns>A collection of property names</returns>
        public IEnumerable <string> GetModifiablePropertyNames(PermissionLevel queryModifyPermissionLevel)
        {
            IEnumerable <PropertyInfo> properties = this.GetType().GetProperties();
            HashSet <string>           modifiablePropertyNames = new HashSet <string>();

            foreach (PropertyInfo prop in properties)
            {
                DisplayConfigModifyPermission[] permissions = (DisplayConfigModifyPermission[])prop.GetCustomAttributes(typeof(DisplayConfigModifyPermission), true);
                if (permissions != null && permissions.Length > 0 && permissions[0].Contains(queryModifyPermissionLevel))
                {
                    modifiablePropertyNames.Add(prop.Name);
                }
            }

            return(modifiablePropertyNames);
        }
Esempio n. 2
0
        /// <summary>
        /// Sets a value on the DisplayConfig.
        ///
        /// Does NOT trigger a state update. Set all your properties, then call LeiaDisplay.UpdateLeiaState.
        /// </summary>
        /// <param name="propertyName">A name of a property on the DisplayConfig</param>
        /// <param name="data">An array of data to be converted into a property on the DisplayConfig</param>
        /// <param name="accessLevel">An edit permission level which is compared to the property's edit permission level</param>
        public void SetPropertyByReflection(string propertyName, Array data, PermissionLevel accessLevel)
        {
            // check property exists
            PropertyInfo propertyInfo = this.GetType().GetProperty(propertyName);

            if (propertyInfo == null)
            {
                LogUtil.Log(LogLevel.Error, "No property {0} on DisplayConfig", propertyName);
                return;
            }

            // check property access level
            DisplayConfigModifyPermission propertyPermissionLevel = (DisplayConfigModifyPermission)propertyInfo.GetCustomAttributes(typeof(DisplayConfigModifyPermission), true)[0];

            if (propertyPermissionLevel == null)
            {
                LogUtil.Log(LogLevel.Error, "Property {0} has no DisplayConfigModifyPermission", propertyName);
                return;
            }

            SetPropertyByContext(propertyInfo, propertyName, data);
        }