コード例 #1
0
        protected void SetPropertyValue(Control control, string propertyName, string propertyValue)
        {
            object obj2 = null;
            InstanceAndPropertyInfo memberInfo   = GetMemberInfo(control, propertyName);
            PropertyInfo            propertyInfo = memberInfo.PropertyInfo;
            TypeConverter           converter    = null;
            TypeConverterAttribute  attribute    = Attribute.GetCustomAttribute(propertyInfo, typeof(TypeConverterAttribute), true) as TypeConverterAttribute;

            if (attribute != null)
            {
                Type type = Type.GetType(attribute.ConverterTypeName, false);
                if (type != null)
                {
                    converter = (TypeConverter)Activator.CreateInstance(type);
                }
            }
            if ((converter != null) && converter.CanConvertFrom(typeof(string)))
            {
                obj2 = converter.ConvertFromInvariantString(propertyValue);
            }
            else
            {
                converter = TypeDescriptor.GetConverter(propertyInfo.PropertyType);
                if ((converter != null) && converter.CanConvertFrom(typeof(string)))
                {
                    obj2 = converter.ConvertFromInvariantString(propertyValue);
                }
            }
            propertyInfo.SetValue(memberInfo.Instance, obj2, null);
        }
コード例 #2
0
        private void ClearDefaults(Control control, string propertyName)
        {
            InstanceAndPropertyInfo memberInfo = GetMemberInfo(control, propertyName);

            if ((memberInfo.PropertyInfo != null) && (memberInfo.Instance != null))
            {
                object target = memberInfo.PropertyInfo.GetValue(memberInfo.Instance, null);
                target.GetType().InvokeMember("ClearDefaults", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase, null, target, new object[0], CultureInfo.InvariantCulture);
            }
        }