Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6755979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:28:04+00:00 2026-05-26T13:28:04+00:00

I have this code and I am using it to raise the PropertyChanged event

  • 0

I have this code and I am using it to raise the PropertyChanged event without passing the name of property to the function.

private void RaisePropertyChanged<TValue>(Expression<Func<TValue>> propertySelector)
    {
        var memberExpression = propertySelector.Body as MemberExpression;
        if (memberExpression != null)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(memberExpression.Member.Name));
            }
        }
    }

and I am calling it in this way:

  this.RaisePropertyChanged(() => this.IsReady);

Which will raise the PropertyChanged event for the IsReady property. I like the idea as writing code in this way will help to change the name of the property very easily.

Now I want to use the same technique to pass the name and value of a property to a method. Is there any way that I can do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:28:05+00:00Added an answer on May 26, 2026 at 1:28 pm

    You already have it:

    string name = memberExpression.Member.Name;
    TValue value = propertySelector.Compile()();
    

    An alternative would be to look at the member.MemberType, cast to PropertyInfo or FieldInfo respectively:

    var member = memberExpression.Member;
    string name = member.Name;
    object value;
    switch(member.MemberType) {
        case MemberTypes.Field:
           value = ((FieldInfo)member).GetValue(this);
           break;
        case MemberTypes.Property:
           value = ((PropertyInfo)member).GetValue(this, null);
           break;
        default:
           throw new NotSupportedException(member.MemberType.ToString());
    }
    

    However, a simpler approach is… to simply pass the name and value to the method:

    Foo("IsReady", IsReady);
    

    It depends a bit on how efficient it needs to be, though (reflection/expression does add an overhead – whether that is significant depends on the context).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code :- using (System.Security.Cryptography.SHA256 sha2 = new System.Security.Cryptography.SHA256Managed()) { .. }
I have this code: using DC = MV6DataContext; using MV6; // Business Logic Layer
I have this code (C#): using System.Collections.Generic; namespace ConsoleApplication1 { public struct Thing {
I have this table: fourn_category (id , sub) I am using this code to
I have this code to show a map using the Virtual Earth API: <script
I have this code written in .NET 4.0 using VS2010 Ultimate Beta 2: smtpClient.Send(mailMsg);
I have this code that fetches some text from a page using BeautifulSoup soup=
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
Using MATLAB, I have this code: value = input('>> Enter a value: '); and
I'm makin' a scripting language interpreter using PHP. I have this code in that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.