我阅读了有关运营商的相关问答,nameof
但它对我没有帮助,所以我在这里问它。
我想为 C#nameof
运算符编写一个包装器,这样它不仅会返回类属性的名称,而且还会将它与类名连接起来。
让我们假设一个具有单一属性的类:
class Foo
{
public string SomeProperty {get; set;}
}
Console.WriteLine(nameof(Foo.SomeProperty))
现在如果使用(C# 6 or higher)编译,结果将是:
一些财产
所以有可能有这样的东西:
public string PrintFullName(???? object)
{
//????
}
我????
输入了输入Type
,因为我不知道正确的输入Type
是什么。
我希望 PrintFullName 的结果是:
Foo.SomeProperty
我不一定要寻找运行时解决方案。任何编译时解决方法也将有所帮助。