Exemplo n.º 1
0
        public static string ToDisplay <T, TProp>(Expression <Func <T, TProp> > propertyExpression, DisplayProperty property = DisplayProperty.Name)
        {
            PropertyInfo         propInfo = propertyExpression.GetPropInfo();
            DisplayNameAttribute attr     = propInfo.GetAttribute <DisplayNameAttribute>(false);

            return(attr.GetType().GetProperty(property.ToString()).GetValue(attr, null) as string ?? propInfo.Name);
        }
Exemplo n.º 2
0
        protected void SetTitle(string property, string value)
        {
            PropertyDescriptor   descriptor    = TypeDescriptor.GetProperties(this.GetType())[property];
            DisplayNameAttribute attribute     = (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)];
            FieldInfo            fieldToChange = attribute.GetType().GetField("_displayName", BindingFlags.NonPublic | BindingFlags.Instance);

            fieldToChange.SetValue(attribute, value);
        }
Exemplo n.º 3
0
        private string GetPropertyDisplayName(string property)
        {
            PropertyDescriptor descriptor =
                TypeDescriptor.GetProperties(this.GetType())[property];
            DisplayNameAttribute attrib =
                (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)];

            return((string)attrib.GetType().GetField("_displayName", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(attrib));
        }
Exemplo n.º 4
0
        protected void SetTitle(string property, string value)
        {
            PropertyDescriptor   descriptor = TypeDescriptor.GetProperties(this.GetType())[property];
            DisplayNameAttribute attribute  = (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)];

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

            fieldToChange.SetValue(attribute, value);
        }
Exemplo n.º 5
0
        private void ChangePropertyName(string property, string name)
        {
            PropertyDescriptor descriptor =
                TypeDescriptor.GetProperties(this.GetType())[property];
            DisplayNameAttribute attrib =
                (DisplayNameAttribute)descriptor.Attributes[typeof(DisplayNameAttribute)];
            FieldInfo isBrow =
                attrib.GetType().GetField("_displayName", BindingFlags.NonPublic | BindingFlags.Instance);

            if (isBrow != null)
            {
                isBrow.SetValue(attrib, name);
            }
        }
Exemplo n.º 6
0
        private void RenameProperty(PropertyDescriptor property, string newName)
        {
            DisplayNameAttribute attribute = (DisplayNameAttribute)
                                             property.Attributes[typeof(DisplayNameAttribute)];

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

            if (fieldToChange != null)
            {
                fieldToChange.SetValue(attribute, newName);
            }
        }