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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:54:30+00:00 2026-05-26T21:54:30+00:00

I have an object handed into our library and passed through various processes. I

  • 0

I have an object handed into our library and passed through various processes. I need to attach some additional information to these objects as they pass through various stages and out the other end – a kind of dynamic decorator pattern, I guess, except adding additional properties rather than changing existing behaviour.

I was hoping to use LinFu or Castle to create a dynamic proxy and implement an additional interface on the object to store this. Components that know about the extended interface could cast and access it – whilst those that are not are oblivious, as the underlying type has not changed.

However, I hadn’t appreciated that all these mechanisms assume you have control over the point at which the type is initially created – which I don’t.

Does anyone have suggestions on how I could better approach this?

Many 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-26T21:54:31+00:00Added an answer on May 26, 2026 at 9:54 pm

    This doesn’t address your scenario exactly but how about using a DynamicObject implementation that acts as a decorator around your object? It would allow you to access the original object as well as additional properties. Sort of like ExpandoObject but starting out with your own instance data.

    Something like this:

    public class Expando : DynamicObject
    {
        public dynamic Instance;
        Dictionary<string, dynamic> ExtraProperties = new Dictionary<string, dynamic>();
    
        public Expando(object instance)
        {
            Instance = instance;
        }
    
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            try
            {
                result = ReflectionUtils.GetProperty(Instance, binder.Name);
                return true;
            }
            catch
            {
                if (ExtraProperties.Keys.Contains(binder.Name))
                {
                    result = ExtraProperties[binder.Name];
                    return true;
                }
            }
    
            result = null;
            return false;
        }
    
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            try
            {
                ReflectionUtils.SetProperty(Instance, binder.Name, value);
            }
            catch (Exception ex)
            {
                ExtraProperties[binder.Name] = value;
            }
    
            return true;
        }
    
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            try
            {
                result = ReflectionUtils.CallMethod(Instance, binder.Name, args);
                return true;
            }
            catch
            {}
    
            result = null;
            return false;
        }
    }
    

    It doesn’t address your strong typing/interface requirement unfortunately though and performance isn’t going to be the greatest given the Reflection usage here (from https://github.com/RickStrahl/Westwind.Utilities/blob/master/Westwind.Utilities/Utilities/ReflectionUtils.cs)

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

Sidebar

Related Questions

I think I read somewhere that some modules only have object oriented interfaces (
I can have Spring convert my json POST submission into an object with a
I have an object which straight forward instance variables. Some are NSString, some are
I have some code that reads a file into an array of lines, and
I have object A which contains multiple instances of object B, which in turn
I have two tables: object that has object_id column and avalues that have object_id
I have an object in C# with lets say 20 properties and it's part
I have an object and a temp object now if i do tempObj =
I have an object for which I'd like to track the number of threads
I have an object for which I want to generate a unique hash (override

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.