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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:55:34+00:00 2026-06-13T16:55:34+00:00

How to have an instance of anonyme class from reflection? I have this string

  • 0

How to have an instance of anonyme class from reflection?

I have this string :
"<object name='hello' id='654' />"

with an indetermined attribute parameters number(and name)
from this I want to have an instance of anonyme class with a mapping between attribute and properties, and attributes values and properties values.

var anObject = new{name="hello",id=654};

I took the xml format for the string to ilustrate my words but I need a solution from any string format(I don’t want to Xml Serialisation).

For Reed Copsey (please make abstraction of the context where I need it).
I plan to use this to inject DefaultRoute to the map route of an asp.net MVC 3 application

 routes.MapRoute(
        "",
        "superweirdurlwithnostructure.whatever",
        new { controller = "Home", action = "Products", id = 500 }
    );

referering to my question File to define route in MVC3

  • 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-13T16:55:35+00:00Added an answer on June 13, 2026 at 4:55 pm

    You can’t make an anonymous class this way (at least not without major hoops using something like CodeDom to actually write and compile code).

    That being said, even if you could do this, there would be no good way to use this class. Anonymous types are really intended for use within the function where they are defined, and they are turned into a full class which is generated by the compiler at compile time.

    One option, potentially, would be to use dynamic:

    dynamic anObject = new ExpandoObject();
    anObject.name = "hello";
    anObject.id = 654;
    

    You could also use this via ExpandoObject‘s IDictionary<string,object> interface:

    dynamic anObject = new ExpandoObject();
    var setObject = (IDictionary<string,object>)anObject;
    setObject["name"] = "hello";
    setObject["id"] = 654;
    
    // These can be accessed directly now
    Console.WriteLine(anObject.name);
    Console.WriteLine(anObject.id);
    

    However, you’re still going to need a good way to use this – without knowing how the code should access the variables, building types dynamically doesn’t help solve many issues, and just creates more of them…

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

Sidebar

Related Questions

I have for instance the following string: 0x780000105d0e0030 If this is not the string,
I am confused between NSString and NSMutable string usage. Suppose I have instance variables
I have an instance of the Popen class created through subprocess.Popen. I would like
I have an instance of Class A that I want to refer to in
I have installed SQL Server 2005 and now have instance name as the default
I have two models like this: class A(models.Model): attachment = FileField(upload_to='a') class B(models.Model): attachment
I am writing a class in Ruby where I have instance variables (i.e. @person_summary_info
How can I add a bunch of instance variables from one object to another?
I have UIButton instance called card. I have an object called Representer, which has
I have this code : public struct SmartFilter { public int from, to; public

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.