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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:08:46+00:00 2026-05-30T05:08:46+00:00

Context I have a very large number of small classes or structures . The

  • 0

Context

I have a very large number of small classes or structures. The implementation details of these classes are not important, but for each of these there will be a few simple built-in data type properties that I want to expose so that they can be edited in a WinForms control. These will be completely different from class to class though. For example:

class SleepAction : IGameAction
{
    public float Duration { get; set; }
}

class TeleportCharacterAction : IGameAction
{
    public string CharacterId { get; set;
    public string DestinationRoomId { get; set; }
    public Vector2 DestinationPosition { get; set; }
}

The problem is that I wanted to have a single WinForms control that is capable of editing all of these object types. There would be a dropdown list of all the class types on top, and when selecting an item from this dropdown list, the interface would change to accomodate the properties of that type, as well as create an instance of that type to store the data.

At first I was considering handcrafting each of these interfaces, possibly using a TabControl object, one tab per class, with the tabs hidden. But then the number of classes grew exponentially, so I’m turning to some other solution, probably using attributes and reflection. I’m just not sure how to get started.

What I have in mind now is something like:

class ActionEditorControl : UserControl
{
    void ChangeEditorMode(Type type)
    {
        // Clear all GUI interface
        // Create object of type Type with default constructor
        // Use Type metadata to generate new GUI interface
        // Databind new interface to object properties
    }

    object GetObject()
    {
        // Return current object
    }
}

And on my model objects I could use attributes to add the necessary metadata:

class SleepAction : IGameAction
{
    [FieldLabel("Duration")]
    [FieldType("NumericSpinner")]
    public float Duration { get; set; }
}

class TeleportCharacterAction : IGameAction
{
    [FieldLabel("Character")]
    [FieldType("CharacterList")]
    public string CharacterId { get; set;

    [FieldLabel("Room")]
    [FieldType("RoomList")]
    public string DestinationRoomId { get; set; }

    [FieldLabel("Position")]
    [FieldType("VectorPicker")]
    public Vector2 DestinationPosition { get; set; }
}

Of course I’d need to teach my control how to interpret these attributes. Now for my actual questions.

Specific Questions

  1. Would this work?
  2. Is there a better alternative to solving this problem that I’m overlooking?
  3. How to deal with the placement or layout of the controls in the interface?
  4. Finally, I’ve never used custom attributes before. Any good example to get me started?
  • 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-30T05:08:47+00:00Added an answer on May 30, 2026 at 5:08 am

    Yes, this should work, I have built something similar for generating dynamic search dialogs based on entities.

    Custom attributes can identify the properties that should appear on the form. The form can then generate controls for those properties and use databinding to link the control back to the property on the object.

    A TableLayoutPanel can help with the layout of the generated controls. One column could store the label objects and the second column could store the control (textbox, etc). Or several sets of these if you want more columns.

    Working with Attributes

    Since you have a type, you can search each property for your special attributes:

    foreach (var property in searchObjectType.GetProperties())
    {
        var labelAttrib = (FieldLabelAttribute)property.GetCustomAttributes(typeof(FieldLabelAttribute), false).FirstOrDefault();
        var typeAttrib = (FieldTypeAttribute)property.GetCustomAttributes(typeof(FieldTypeAttribute), false).FirstOrDefault();
     }
    

    Table Panel:

    Once you know you need to build a control, figure out what kind of control you’re going to build: (This assumes you have an attribute with an Order property so you know ‘where’ to place the control in the grid. This example is based on five columns, being label, control, spacer, label, control):

    if (type == typeof(string))
    {
      generatedControl = new Textbox();
      generatedControl.DataBindings.Add("Text", myObject, property.Name);
    }
    

    And then add the control to the table (this assumes you created a label control):

    pnlLayout.Controls.Add(label, (myAttrib.Order % 2 * 3), myAttrib.Order / 2);
    
    pnlLayout.Controls.Add(generatedControl, (myAttrib.Order % 2 * 3) + 1, myAttrib.Order / 2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have UITableView with very large cells with lots of content (more than one
I have some very large mp3's stored at a remote location and I presently
Here is the main problem. I have very large database (25,000 or so) of
I have a very large problem. I've written a large app using Flex3/Tomcat/BlazeDS/Spring that
Let say I have a query with a very large resultset (+100.000 rows) and
Say I have the following data Name Value =============== Small 10 Medium 100 Large
My project requires me to validate a large number of web URLs. These URLs
We have a very large JavaScript application, where after many months of coding there
I have a site that's growing large, and has very separate needs for different
I want to create a Gallery that displays a very large number of images.

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.