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 6993975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:49:57+00:00 2026-05-27T19:49:57+00:00

If I’ve missed this in another question I apologize; I looked for a good

  • 0

If I’ve missed this in another question I apologize; I looked for a good while before deciding I had a unique question… I want to use DynamicProxy2 to provide interception for a WPF application’s model classes. This is so that I do not have to fully implement INotifyPropertyChanged everywhere. For instance, the below class should fully participate in two-way data binding once proxied and intercepted:

public class ModelExample : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    public int Id{ get; set; }
    public string Uri{ get; set; }
    public string Name{ get; set; }
}

I have found that I can create a new instance of the model class and intercept calls to it by calling the CreateClassProxy method:

new ProxyGenerator().CreateClassProxy<T>(interceptors);

Unfortunately, this forces me to allow the ProxyGenerator class to create my model instances, and I’m getting those back from my middle tier, i.e. they already exist. I need to wrap existing objects, so I think I need to call CreateClassProxyWithTarget instead:

new ProxyGenerator().CreateClassProxyWithTarget(instance, interceptors);

However, when I do that my interceptor stops functioning. I’m pretty sure it’s not the interceptor’s fault… it’s a very simple object. Here’s its interface:

public interface IFluentInterceptor : IInterceptor
{
    IFluentInterceptor Before(Action<IInvocation> before);
    IFluentInterceptor After(Action<IInvocation> after);
    IFluentInterceptor Finally(Action<IInvocation> @finally);
    IFluentInterceptor RunCondition(Func<IInvocation, bool> runCondition);
    IFluentInterceptor OnError(Func<IInvocation, Exception, bool> onError);
}

The FluentInterceptor type implements this. The Before, After, etc. methods are too simple to show; they all add to action queues that are meant to be used during method invocation, then each method returns this, allowing for method chaining.

The below code doesn’t work, but I can’t figure out why:

new ProxyGenerator().CreateClassProxyWithTarget(instance, new FluentInterceptor()
    .After(invocation =>
    {
        if (!invocation.Method.Name.StartsWith("set_")) return;
        string propertyName = invocation.Method.Name.Substring(4);
        FieldInfo info = invocation.TargetType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
            .Where(f => f.FieldType.Equals(typeof (PropertyChangedEventHandler)))
            .FirstOrDefault();
        if (info == null) return;
        var handler = info.GetValue(invocation.InvocationTarget) as PropertyChangedEventHandler;
        if (handler != null) handler.Invoke(invocation.TargetType, new PropertyChangedEventArgs(propertyName));
    }));

If I try that with CreateClassProxy, it works like a charm. Does anybody see what I’m doing wrong?

Thanks!

  • 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-27T19:49:57+00:00Added an answer on May 27, 2026 at 7:49 pm

    Honestly, I think this is a non-issue. If I ever need a container to generate the INotifyPropertyChanged implementation for me, it’ll probably be in fringe cases where I’m plugging in model objects that get built by the container anyway because they have depedencies, etc. In those cases CreateClassProxy<T>(interceptors) is fine. In all other cases I have been using MVVM ViewModels where the exact logic surrounding change notification is decided on a case-by-case basis, with the user experience being the focus. Model classes usually get flattened or transformed in some way, so the whole point is moot. I asked this question at a time when I didn’t understand how to properly leverage MVVM in my app, and I thought I was going to be responsible for more moving parts. It’s actually been a lot easier than anticipated, once I started configuring my ViewModels properly.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.