C# 反射创建实例并赋值
创建实例
当构造方法被私有化
Setting copy =
(Setting)FormatterServices.GetUninitializedObject(dbSetting.GetType());
常规手法
var copy = Activator.CreateInstance(typeof(Setting)) ;
修改属性
Type type = typeof(Setting);
type.GetProperty("Name").SetValue(copy, sourceSetting.Name);
原文地址:https://blog.csdn.net/zcy_wxy/article/details/135461192
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!