I read a related question and answer about the nameof operator, but it didn't help me, so I asked it here.
I want to write a wrapper for the C# nameof operator so not only will it will return the name of a class property, but also concatenate it with the class name.
Let's assume a class with single property:
class Foo
{
public string SomeProperty {get; set;}
}
Now if compiling Console.WriteLine(nameof(Foo.SomeProperty)) with (C# 6 or higher), the result will be:
SomeProperty
So that is it possible to have something like this:
public string PrintFullName(???? object)
{
//????
}
I put ???? for the input Type, because I don't know what the proper input Type is.
I want the result of the PrintFullName to be:
Foo.SomeProperty
I don't necessarily look for run-time solutions. Any compile-time workaround will also help.
Foo.SomePropertysince SomeProperty is an instance member ofFoo. You can olny writeinstanceOfFoo.SomeProperty. You only may use reflexion on the class type to get members definitions.Console.WriteLine(nameof(Foo.SomeProperty))is now a valid C# expression for C# 6PrintFullNamereturn "Foo.SomeProperty"? What is the connection between the two?Console.WriteLine(typeof(Foo).Name + "." + nameof(Foo.SomeProperty));?