NET 实例化泛形对象并赋值

0
13

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

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

2.调用

Builder(new UserDto());

<

发布回复

请输入评论!
请输入你的名字