我正在尝试编写一个函数,它将使用如下语法提取属性的名称和类型:
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"
有人可以帮忙吗?
我上了课
public class News : Record
{
public News()
{
}
public LocaleValues Name { get; set; }
public LocaleValues Body;
}
Run Code Online (Sandbox Code Playgroud)
在我的LocaleValues班上,我有:
public class LocaleValues : List<LocalizedText>
{
public string Method
{
get
{
var res = System.Reflection.MethodBase.GetCurrentMethod().Name;
return res;
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我像这样调用时,我需要Method属性返回Name属性名称的字符串表示形式:
var propName = new News().Name.Method;
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?感谢您的时间!