我正在尝试创建一个应用程序,该应用程序从从 XML 文件中读取的数据创建对象。
使用反射,我设法创建了我需要的对象并分配了一些属性,如原始类型和 ENUM 类型。
对于属性是字典条目的基本类型,其中要更改的属性名称和要设置的值
type.GetProperty((string)property.Key).SetValue(control, Convert.ChangeType((string)property.Value, propertyType, null), null);
对于 ENUM 类型
object desiredPropertyValue = Enum.Parse(propertyType, (string)property.Value);
propertyInfo.SetValue(control, desiredPropertyValue, null);
我遇到的问题是我似乎无法找到一种方法来设置其他类型的属性,如 Fontweight、fontfamily、Margin 和许多其他我认为这些是类型结构的属性,任何帮助将不胜感激