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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:38:33+00:00 2026-05-26T00:38:33+00:00

I have occasionally had cause to write collection class adapters, i.e. create an adapter

  • 0

I have occasionally had cause to write collection class adapters, i.e. create an adapter for a class that implements IList<T> proxying its methods, whist adding some extra functionality. The IList interface has numerous methods / properties, I was wondering whether the straight-through proxy methods could be implemented dynamically? I had a look at DynamicObject, but could only find a few simple examples that proxy DTO classes, i.e. proxying a class that just has properties.

Is the proxying of IList<T> possible?

e.g.

public class ListProxy : IList<T>
{
  private IList<T> _adaptee;

  public ListProxy(IList<T> adaptee)
  {
    _adaptee = adaptee
  }

  // dynamically implement straight-through IList methods / properties
}
  • 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-26T00:38:34+00:00Added an answer on May 26, 2026 at 12:38 am

    Something like this?

    using System;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Runtime.Remoting.Messaging;
    using System.Runtime.Remoting.Proxies;
    
    class Program
    {
        static void Main(string[] args)
        {
            IList<string> listProxy = MyProxyGenerator.Create<IList<string>>(new ListProxy<string>(new List<string>() { "aa","bb" }));
            bool b1 = listProxy.Contains("aa");
            bool b2 = listProxy.Contains("cc");
            int count = listProxy.Count;
            string s = listProxy[1];
        }
    
        public class ListProxy<T>
        {
            private IList<T> _adaptee;
    
            //Only method needed by proxy generator
            object Adaptee
            {
                get { return _adaptee; }
            }
    
            public ListProxy(IList<T> adaptee)
            {
                _adaptee = adaptee;
            }
        }
    
        class MyProxyGenerator : RealProxy
        {
            Type _Type;
            object _Instance;
    
            public static T Create<T>(object instance)
            {
                return (T)new MyProxyGenerator(typeof(T),instance).GetTransparentProxy();
            }
    
            MyProxyGenerator(Type type,object instance) : base(type)
            {
                _Type = type;
                _Instance = instance.GetType().InvokeMember("get_Adaptee", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, instance, null);
            }
    
            public override IMessage Invoke(IMessage msg)
            {
                IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)msg);
                string method = (string)msg.Properties["__MethodName"];
                object[] args = (object[])msg.Properties["__Args"];
    
                object retObj = _Instance.GetType().InvokeMember(method, BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod,null,_Instance,args);
                return new ReturnMessage(retObj,methodMessage.Args,methodMessage.ArgCount,methodMessage.LogicalCallContext,methodMessage);
            }
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Like it or not, occasionally you have have to write tests for classes that
I have a class that occasionally gets passed null for File objects. During normal
Occasionally I'll have some WPF C# code that I'd like to write in a
I have a program that occasionally pops up on the screen and displays a
I have a multi-threaded Windows application that occasionally deadlocks. Inevitably this happens on a
Occasionally, I have had to build a SQL string in VBA and execute it
I have a Windows application written in C++ that occasionally evaporates. I use the
This is a two part question. I have a class that gets all processes
I occasionally have Python programs that take a long time to run, and that
I have a DataTable that's had people wire into it's different column changed events,

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.