相关疑难解决方法(0)

使用lambda表达式获取属性名称和类型

我正在尝试编写一个函数,它将使用如下语法提取属性的名称和类型:

private class SomeClass
{
    Public string Col1;
}

PropertyMapper<Somewhere> propertyMapper = new PropertyMapper<Somewhere>();
propertyMapper.MapProperty(x => x.Col1)
Run Code Online (Sandbox Code Playgroud)

有没有办法将属性传递给函数而不对此语法进行任何重大更改?

我想获取属性名称和属性类型.

所以在下面的例子中我想要检索

Name = "Col1"Type = "System.String"

有人可以帮忙吗?

c# reflection lambda

37
推荐指数
1
解决办法
3万
查看次数

标签 统计

c# ×1

lambda ×1

reflection ×1