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

The Archive Base Latest Questions

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

I have a series of static methods to modify a collection then return the

  • 0

I have a series of static methods to modify a collection then return the modified collection:

private static IEnumerable<Invoice> ResolveProxies(IEnumerable<Invoice> e) {
    // do something to e
    return e;
}

private static IEnumerable<Person> ResolveProxies(IEnumerable<Person> e) {
    // do something to e
    return e;
}

In another part of the application there is a method to decide if a collection is of a certain type, so that it can be converted to that type and have its corresponding ResolveProxies method called:

public static GridModel<T> ToGridModel<T>(this GridModel gridModel) {
    // gridModel.Data is just IEnumerable
    var collection = gridModel.Data as IEnumerable<T> ?? new List<T>();

    return new GridModel<T> {
        Data = EvaluateDynamicProxies(collection),
        Total = gridModel.Total
    };
}

private static IEnumerable<T> EvaluateProxies<T>(IEnumerable<T> collection) {
    if (collection is IEnumerable<Invoice>) {
        var enumeration = (collection as IEnumerable<Invoice>);
        return ResolveProxies(enumeration) as IEnumerable<T>;
    }
    if (collection is IEnumerable<Person>) {
        var enumeration = (collection as IEnumerable<Person>);
        return ResolveProxies(enumeration) as IEnumerable<T>;
    }

    // proxy resolution isn't needed so return the unchanged collection
    return collection;
}

Having such repetitive conditional logic is bad code smell. I’m struggling to come up with some way to mark particular types so that I know they have a corresponding proxy resolver method. Something like this perhaps:

public interface IProxyResolver<out T> where T:IEnumerable<T> {
    T ResolveProxies();
}

But how would I use this? In effect I need a way to ask the compiler:

  1. Does T have a matching ResolveProxies method?
  2. What is the name of the class or method that resolves proxies for T so that I can get an instance of it and call it?
  • 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-28T03:03:04+00:00Added an answer on May 28, 2026 at 3:03 am

    You could use an inversion of control (IOC) framework. For example, my team uses Castle Windsor. You can register services (usually interfaces) and types that provide the services. It has some nice generics resolution, so you can do things like this:

    interface IProxyResolver<T> { /* whatever */ }
    class ProxyResolver<T> : IProxyResolver<T> { /* ... */ }
    class PersonProxyResolver : ProxyResolver<Person> { }
    class InvoiceProxyResolver : ProxyResolver<Invoice> { }
    

    then, you can summon these types like this:

    void SomeMethodThatNeedsAProxyResolver<T>(T obj)
    {
        var resolver = ioc.Resolve<IProxyResolver<T>>();
        //...
    }
    

    If you’ve regsitered the classes above, when T is Person or Invoice, you get the correct non-generic subclass of ProxyResolver; if it is any other type, you get the default generic superclass. Of course, you can structure things differently; if you need a specific proxy resolver for every type, that’s possible too.

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

Sidebar

Related Questions

I have a series of Extension methods to help with null-checking on IDataRecord objects,
I have a variable declared as: private static List<String> _search_result_list = new ArrayList<String>( 15
I have a series of PDFs named sequentially like so: 01_foo.pdf 02_bar.pdf 03_baz.pdf etc.
I have a series of functional tests against a web application that correctly run,
I have a series of performance tests I would like to show as a
We have a series of drop down controls that determine the sort order of
I have a series of datetime objects and would like to calculate the average
I have a series of ASCII flat files coming in from a mainframe to
I have a series of text that contains mixed numbers (ie: a whole part
I have a series of Eclipse projects containing a number of plugins and features

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.