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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:38:39+00:00 2026-06-17T02:38:39+00:00

I have a custom control. This custom control uses Reflection heavily. Inside the custom

  • 0

I have a custom control. This custom control uses Reflection heavily. Inside the custom control assembly I have a class, which is a reflection manager. It handels everything reflection related in the control. One of the things it does is cache the PropertyInfo objects for each property of the objects in the DataSource. I would like to make it static so I can easily use it inside the custom control class and also other support classes inside the assembly. The problem is that this control is used in several places, and with different datasources, and each has it’s own collection of PropertyInfo objects.

What would be the best way to create this class so that it has an instance per instance of the control, and is also available to other classes within the custom control assembly.

One thing I thought of is to insert the instance of the reflection manager I created in the custom control class in to a property / though the constructor of the supporting classes (ala DI), but maybe there is a better pattern I’m just not aware of.

Edit: Sorry for being unclear. The project is an ASP.NET WebForms project. The control is a CompositeDataBoundControl if that matters.

Edit 2: I will elaborate on the design I have and what flaws I see in it.
I have a custom control class which is being used (or planned to be used in several pages).
Inside this control I have this class (sorry if I have some syntax mistakes, I`m writing this from memory). This is not the entire class, just what is relevant here.

public static class DataReflectionManager
{
    private static Dictionary<string, PropertyInfo> _propertyInfos = new Dictionary<string, PropertyInfo>();

    public static void RegisterDataSource(IEnumerable dataSource)
    {
        //Get the property info of each property of and
        //stick it in the dictionary.
    }

    public static string GetValueByPropertyKey(object o, string key)
    {
        //Takes o and gets the value of property key by the PropertyInfo object.
        return "";
    }
}

Now this class cannot remain static, or the dictionary will be the same for all instances of the custom controls, and they each have their own datasource, which holds different types of objects. So… static is out. But what then?
If I used DataReflectionManager in just the custom control class, I would just create an instance there. The problem is that the custom control uses column types, which all inherit from ColumnBase and ColumnBase has an abstract function, which uses the DataReflection manager in most of the inheriting column types. So I could pass the instance around, but I’m looking for maybe a more intelligent solution.

  • 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-17T02:38:40+00:00Added an answer on June 17, 2026 at 2:38 am

    I could not find a “perfect” solution here, since every way of doing this I could come up with has some drawbacks for our specific design.

    The thinking that helped me arrive at my current solution was that the list of ProperyInfo objects is tied to a specific instance of the control, and thus the Dictionary<string, PropertyInfo> used to store it should also be a member of the control class. This allowed me to keep the reflection manager static and make minimal code changes in supporting classes.

    Supporting classes get PropertyInfo objects as needed in their respective constructors.

    The reflection manager created the dictionary through reflection in the control constructor and from there on, the control stores it.

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

Sidebar

Related Questions

I have a class derived from slider which uses a custom control template and
I have a custom control that inherits from .NET's CompositeControl class. This control overrides
I have a custom WPF control base class. This base class registers a custom
I have a custom user control on my windows forms. This control has a
In a WPF/MVVM application I have a custom control on a particular view. This
I have a asp.net webpage that contain a custom login control like this: <div
I have done some looking and I found this: http://www.codeproject.com/Articles/14439/The-ScrollableListBox-Custom-Control-for-ASP-NET-2 but to me it
I have a custom control which displays results of some operations. It is hidden
I have a custom templated control(toolbar) that contains a custom usercontrol(button) The button uses
I have custom control: public class TestTextBox : TextBox { public TestTextBox() { Text

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.