Example #1
0
        protected void SetDescription(string property, string value)
        {
            PropertyDescriptor   descriptor    = TypeDescriptor.GetProperties(this.GetType())[property];
            DescriptionAttribute attribute     = (DescriptionAttribute)descriptor.Attributes[typeof(DescriptionAttribute)];
            FieldInfo            fieldToChange = attribute.GetType().GetField("description", BindingFlags.NonPublic | BindingFlags.Instance);

            fieldToChange.SetValue(attribute, value);
        }
Example #2
0
        protected void SetDescription(string property, string value)
        {
            PropertyDescriptor   descriptor = TypeDescriptor.GetProperties(this.GetType())[property];
            DescriptionAttribute attribute  = (DescriptionAttribute)descriptor.Attributes[typeof(DescriptionAttribute)];

            FieldInfo[] fields = attribute.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
            Debug.Assert(fields.Length == 1);
            FieldInfo fieldToChange = fields[0];

            fieldToChange.SetValue(attribute, value);
        }
Example #3
0
        private void ChangePropertyDescription(string property, string description)
        {
            PropertyDescriptor descriptor =
                TypeDescriptor.GetProperties(this.GetType())[property];
            DescriptionAttribute attrib =
                (DescriptionAttribute)descriptor.Attributes[typeof(DescriptionAttribute)];
            FieldInfo isBrow =
                attrib.GetType().GetField("description", BindingFlags.NonPublic | BindingFlags.Instance);

            if (isBrow != null)
            {
                isBrow.SetValue(attrib, description);
            }
        }
        public void DisplayNameGridProperty(object obj, string propertyName, string displayName)
        {
            PropertyDescriptor   descriptor = TypeDescriptor.GetProperties(obj.GetType())[propertyName];
            DescriptionAttribute attribute  = (DescriptionAttribute)
                                              descriptor.Attributes[typeof(DescriptionAttribute)];

            System.Reflection.FieldInfo fieldToChange = attribute.GetType().GetField("description",
                                                                                     System.Reflection.BindingFlags.NonPublic |
                                                                                     System.Reflection.BindingFlags.Instance);

            if (fieldToChange != null)
            {
                fieldToChange.SetValue(attribute, displayName);
            }
            // propertyGrid1.Refresh();
        }
Example #5
0
        /// <summary>
        /// Set all properties to readonly (recursive through to the base classes)
        /// </summary>
        public void UpdateTypeDescriptions(Type type, Dictionary <UInt16, MXFEntryPrimer> allPrimerKeys)
        {
            if (type != null && allPrimerKeys != null)
            {
                if (type.BaseType != null)
                {
                    UpdateTypeDescriptions(type.BaseType, allPrimerKeys);
                }

                foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(type))
                {
                    DescriptionAttribute attr = prop.Attributes[typeof(DescriptionAttribute)] as DescriptionAttribute;
                    if (attr != null)
                    {
                        if (!string.IsNullOrEmpty(attr.Description) && attr.Description.Length == 4)
                        {
                            string newDescription = "";

                            // Get the local tag
                            try
                            {
                                UInt16 localTag = (UInt16)Convert.ToInt32(attr.Description, 16);

                                // Find the local tag in the primer pack
                                if (allPrimerKeys.ContainsKey(localTag))
                                {
                                    MXFEntryPrimer prime = allPrimerKeys[localTag];
                                    newDescription = prime.AliasUID.Key.Name;
                                }

                                FieldInfo fi = attr.GetType().GetField("description", BindingFlags.NonPublic | BindingFlags.Instance);
                                if (fi != null)
                                {
                                    fi.SetValue(attr, newDescription);
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }
            }
        }