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

  • Home
  • SEARCH
  • 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 8425213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:12:33+00:00 2026-06-10T04:12:33+00:00

I currently have a setter method which looks like this: private string _a; public

  • 0

I currently have a setter method which looks like this:

 private string _a;
    public virtual string A
    {
        get { return _a; }
        set
        {
            if (_a!= value)
            {
                if (this.OnPropertyChanging("A", _a, value))
                {
                    var previousValue = _a;
                    _a = value;
                    this.OnPropertyChanged("A", previousValue, value);
                }
            }

        }
    }

I have implemented this with help from Dr Wily’s Apprentice (http://stackoverflow.com/a/8578507/981225), with a custom Changing handler that keeps track of the old and current value, as well as the ability to set the Changing event as ‘Cancelled’, such that the PropertyChange will not occur.

This works perfectly. However, we have hundreds of properties and this is a lot of code the duplicate.

I have used Castle’s DynamicProxy in the past, to avoid having to write ‘OnPropertyChanged(“A”)’.

How can I implement the logic within this setter, as part of the Proxy’s Intercept method? Is it possible? Thank you.

  • 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-06-10T04:12:35+00:00Added an answer on June 10, 2026 at 4:12 am

    Maybe I’m a bit late, but I came across a similar task in the Linq-To-SharePoint model. I sketched some code if some one’s still wondering.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Castle.DynamicProxy;
    using System.Reflection;
    using System.ComponentModel;
    
    
    namespace DemoSpace
    {
        public abstract class EntityBase : INotifyPropertyChanged, INotifyPropertyChanging
        {
            public virtual void OnPropertyChanging(string propertyName, object value)
            {
                if ((null != PropertyChanging))
                {
                    PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
                }
            }
    
            public virtual void OnPropertyChanged(string propertyName)
            {
                if ((null != PropertyChanged))
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                }
            }
    
            public event PropertyChangedEventHandler  PropertyChanged;
    
            public event PropertyChangingEventHandler  PropertyChanging;
        }
    
        public class DemoInterceptor<T> : IInterceptor where T : EntityBase
        {
            private T _target;
    
            public DemoInterceptor(T target)
            {
                _target = target;
            }
    
            public void Intercept(IInvocation invocation)
            {
                if (invocation.Method.IsPublic && invocation.Method.Name.StartsWith("set_"))
                {
                    string propertyName = invocation.Method.Name.Substring(4);
                    string privateFieldName = ResolvePropName(propertyName); 
    
    
                    object original_value = 
                        typeof(T).GetField(privateFieldName, BindingFlags.NonPublic | BindingFlags.Instance).GetValue(_target);
    
                    _target.OnPropertyChanging(propertyName, original_value);
                    invocation.Method.Invoke(_target, invocation.Arguments);
                    _target.OnPropertyChanged(propertyName);
    
                }
                else
                {
                    invocation.ReturnValue = invocation.Method.Invoke(_target, invocation.Arguments);
                }
    
            }
    
            public virtual string ResolvePropName(string propertyName)
            {
                return "_" + propertyName.Substring(0, 1).ToLower() + propertyName.Substring(1);
            }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have my PHP class variables set up like this: class someThing {
I'm currently refactoring a class which currently looks something like this: class SomeModel {
Assuming you have a class Photo: class Photo { public string Title {get; set;}
I'm currently using this extension to set specific events which handle data in the
I have a Struts form which contains a Map: private Map<Long, String> questionAnswers =
Currently have password protection on my main and sub directories, however I'd like to
I currently have a table of concentrations, which are linked to a table of
I currently have a form with inputs and name attributes. I'm able to get
I currently have a MySQL table like: id | friend 1 | 2 1
I have a GUI problem that I would like to get sorted out, but

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.