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

  • Home
  • SEARCH
  • 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 8979093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:46:04+00:00 2026-06-15T19:46:04+00:00

I’m developing a Desktop Applicaiton which is akin to a plugin based system. I

  • 0

I’m developing a Desktop Applicaiton which is akin to a plugin based system. I have a client module, that will load a DLL containing a ‘Machine’ object. Thereafter the ‘Machine’ object is manipulated and used as per well defined interfaces.

The tricky part is that the DLL containing the ‘Machine’ object is generated on the fly by using another program. At it’s core, the DLL generating application accepts user input, generates classes, in c# code files (which contain fields specified by the user, of which I don’t have any prior knowledge of) and compiles those classes to a DLL (machine.dll file).

The client program picks up this dll, dynamically loads it and then operates on this machine bject.

I am facing a lot of trouble modeling a solution to address the problem of passing data between the Machine object and the Client program, essentially because I dont know what data is contained in the machine object.

The client program is to do the following things.

— Load the dll and instantiate the ‘machine’ object.
— Call a series of functions in the ‘machine’ object, that are known to the client via an interface.
— Extract various variables from the ‘machine’ object and display it to the user.

I am not able to perform the last step.

Note: I have programmed a trivial solution where the meta-data about the fields is generated by the dll generating program and stored in xml files. The client program uses these xml files to get information about the fields stored in the machine object. It then uses reflection on the machine object to access the fields of the object.

I feel this is cumbersome and slow. Are there any patterns or methods to this kind of stuff??

  • 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-15T19:46:05+00:00Added an answer on June 15, 2026 at 7:46 pm

    A solution that came to mind when I read this was to make use of the built-in support for Attributes in C#. An attribute is a way of tagging a property, field, method, class, etc with some additional meta-data that is then used by some other class, for example during Serialization. You will see it there most often.

    I had an application that I was building that needed to be able to take an IEnumerable collection of objects and output some data to a file based on user selected choices. I created an attribute class that gave me the ability to read the choices via reflection, and act as directed. Let me show you the example:

    First the attribute class:

    [System.AttributeUsage(AttributeTargets.Property)]
    class ExportOptionsAttribute : System.Attribute
    {
        public string Header { get; set; }
        public string FormatString { get; set; }
        public bool Export { get; set; }
        public int Order { get; set; }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="header"></param>
        public ExportOptionsAttribute(string header) : this (header, null, true)
        {
    
        }
    
        /// <summary>
        /// 
        /// </summary>
        /// <param name="header"></param>
        /// <param name="formatString"></param>
        /// <param name="export"></param>
        public ExportOptionsAttribute(string header, string formatString, bool export)
        {
            this.Header = header;
            this.FormatString = formatString;
            this.Export = export;
            this.Order = 0;
        }
    }
    

    With this class defined like so, I could decorate my data class properties like this (actual properties changed so as to not get lost on the business jargon):

    public sealed class PartsOrder
    {
        /// <summary>
        /// 
        /// </summary>  
        [ExportOptions("Customer Name", Order=0)]
        public string CustomerName { get; set; }
    
        /// <summary>
        /// 
        /// </summary>
        [ExportOptions("Catalog Name", Order = 1)]
        public string Catalog Name { get; set; }
    
        /// <summary>
        /// 
        /// </summary>
        [ExportOptions("Unit", Order = 2)]
        public string Unit { get; set; }
    
        /// <summary>
        /// 
        /// </summary>
        [ExportOptions("Component", Order = 3)]
        public string Component { get; set; }
    
        /// <summary>
        /// 
        /// </summary>
        [ExportOptions("Delivery Point", Order = 4)]
        public string DeliveryPoint { get; set; }
    
        /// <summary>
        /// 
        /// </summary>  
        [ExportOptions("Order Date", Order = 5)]
        public string OrderDate { get; set; }
    }
    

    So then in my export routine, instead of hard-coding the property names, which are variable, or passing a complex data structure around which contained the information on which fields to show or hide and what the ordering was, I just ran the following code, using reflection, to loop the properties and output their values, to a CSV file in this case.

    StringBuilder outputDoc = new StringBuilder();
    
    // loop through the headers in the attributes
    // a struct which decomposes the information gleaned from the attributes
    List<OrderedProperties> orderedProperties = new List<OrderedProperties>();
    
    // get the properties for my object
    PropertyInfo[] props =
        (typeof(PartsOrder)).GetProperties();
    
    // loop the properties
    foreach (PropertyInfo prop in props)
    {
        // check for a custom attribute
        if (prop.GetCustomAttributesData().Count() > 0)
        {
            foreach (object o in prop.GetCustomAttributes(false))
            {
                ExportOptionsAttribute exoa = o as ExportOptionsAttribute;
    
                if (exoa != null)
                {
                    orderedProperties.Add(new OrderedProperties() { OrderByValue = exoa.Order, PropertyName = prop.Name, Header = exoa.Header, Export = exoa.Export });
                }
            }
        }
    }
    
    orderedProperties = orderedProperties.Where(op => op.Export == true).OrderBy(op => op.OrderByValue).ThenBy(op => op.PropertyName).ToList();
    
    foreach (var a in orderedProperties)
    {
        outputDoc.AppendFormat("{0},", a.Header);
    }
    
    // remove the trailing commma and append a new line
    outputDoc.Remove(outputDoc.Length - 1, 1);
    outputDoc.AppendFormat("\n");
    
    
    var PartsOrderType = typeof(PartsOrder);
    
    //TODO: loop rows
    foreach (PartsOrder price in this.Orders)
    {
        foreach (OrderedProperties op in orderedProperties)
        {
            // invokes the property on the object without knowing the name of the property
            outputDoc.AppendFormat("{0},", PartsOrderType.InvokeMember(op.PropertyName, BindingFlags.GetProperty, null, price, null));
        }
    
        // remove the trailing comma and append a new line
        outputDoc.Remove(outputDoc.Length - 1, 1);
        outputDoc.AppendFormat("\n");
    }
    

    The code for the OrderedProperties struct is here:

    struct OrderedProperties
    {
        /// <summary>
        /// 
        /// </summary>
        public int OrderByValue;
        /// <summary>
        /// 
        /// </summary>
        public string PropertyName;
        /// <summary>
        /// 
        /// </summary>
        public string Header;
        /// <summary>
        /// 
        /// </summary>
        public bool Export;
    }
    

    As you can see, the logic to extract the property values is completely ignorant of the structure of the class. All it does is find the properties that are decorated with the attribute I created, and use that to drive the processing.

    I hope this all makes sense, and if you need more help or clarification, please feel free to ask.

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

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.