3

Consider that I have a MemberInfo object of member MyObject.Field1, how would I get the full name of this member? I understand that MemberInfo.ReflectedType.FullName + '.' + MemberInfo.Name would do, but is there any more "native" solution? I would rather not define notations myself. I have also seen notations like MyObject+Abc as a reference to delegates so I am careful.

3
  • MemberInfo.ToString() not working?
    – leppie
    Commented Aug 1, 2014 at 12:16
  • No. It will just give the short definition of the member inside the type. Commented Aug 1, 2014 at 12:18
  • 3
    The notation TypeA+TypeB is the CLR notation for TypeB nested in TypeA. Commented Aug 1, 2014 at 12:20

1 Answer 1

1

I believe MemberInfo.ReflectedType.FullName + '.' + MemberInfo.Name is fine(till someone provides elegant way). I'd use string.format to make it bit cleaner

string fullMemberName = string.Format("{0}.{1}", member.ReflectedType.FullName, member.Name);

+ notation is used for nested types. In your example if Abc is nested type of MyObject name of the type Abc will be MyObject+Abc.

Not the answer you're looking for? Browse other questions tagged or ask your own question.