1

I have created an extension method:

public static class Validation
        {
            public static bool ValidateEMail(this String str)
            {
            return Regex.Match(str, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*").Success;
            }

         }

I can call this method as:

bool result = EMailId.ValidateEMail()

My Question is: Can I get the property name of the caller of this extension method within my extension method so that I can do additional operation on that property name? In this case, can I get the name "EmailId" within "ValidateEMail"

Thanks

Satyajit
  • 1,971
  • 5
  • 28
  • 51
  • 1
    Make it an `Expression>`. You can inspect expression body and for trivial expressions is pretty easy. You will use it as `ValidateEmail(() => Emailid) `. Even better with c# 6 static usings. – Adriano Repetti Jul 30 '15 at 06:10
  • @AdrianoRepetti Thanks. Will try this. – Satyajit Jul 30 '15 at 07:52

0 Answers0