Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

kyourek/Ensues.Reflection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 

Repository files navigation

Ensues.Reflection

(Formerly NetNames)

Methods for resolving .NET member names to strings.

For example, consider the following class:

class Example {
    public bool BoolField = default(bool);
    public string StringProperty { get { throw new NotSupportedException(); } }
    public void VoidMethod() { throw new NotSupportedException(); }
    public string String1ParamMethod(object param1) { 
        throw new NotSupportedException(); 
    }
}

With the namespace Ensues.Objects used, the following program:

class Program {
    static void Main(string[] args) {

        var instance = new Example();

        Console.WriteLine(instance.GetMemberName(i => i.BoolField));
        Console.WriteLine(instance.GetMemberName(i => i.StringProperty));
        Console.WriteLine(instance.GetMemberName(i => i.VoidMethod()));
        Console.WriteLine(instance.GetMemberName(i => i.String1ParamMethod("")));

        Console.ReadKey();
    }
}

produces the output:

BoolField
StringProperty
VoidMethod
String1ParamMethod

The Ensues.Reflection namespace also provides the MemberResolver class for getting member names without a type instance.

var mr = new MemberResolver<Example>();
Console.WriteLine(mr.GetMemberName(m => m.BoolField));
Console.WriteLine(mr.GetMemberName(m => m.StringProperty));
Console.WriteLine(mr.GetMemberName(m => m.VoidMethod()));
Console.WriteLine(mr.GetMemberName(m => m.String1ParamMethod("")));

About

Utilities for resolving .NET member names to strings

Resources

License

Stars

Watchers

Forks

Packages

No packages published