NET 实例化泛形对象并赋值

1.泛形方法:具体实例点击查看BuilderResultList

        /// 
        /// 实例化泛形对象并赋值
        /// 
        /// 
        /// 
        private static void Builder(T Entity) where T : class, new()
        {
            T newEntity = new T();
            var newEntityType = newEntity.GetType();
            newEntityType.GetProperty("属性名").SetValue(newEntity, "属性值");
        }

2.调用

Builder(new UserDto());

 

你可能感兴趣的:(NET 实例化泛形对象并赋值)