Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it Possible to Create New Classes on RunTime C#

Hi is it possible to Create New Classes in C# ,classes which the Application Read's from XML and Declare they're Attributes also reading from XML . like :

<item id=1>
 <Name>John</Name>
 <Surname>Kennedy</Surname>
 <Age>24</Age>
</item>

bests.

like image 435
Rosmarine Popcorn Avatar asked Jun 03 '11 08:06

Rosmarine Popcorn


People also ask

Can we create class at runtime?

In the preceding code ClassName is a variable, that contains the class name to be created. This class helps to create a dynamic assembly at run time. This is a sealed class and has no constructor. The object of this class is created using the DefineDynamicAssembly method of the AppDomain class.

Can we create a class at runtime in Java?

Dynamic Class creation enables you to create a Java class on the fly at runtime, from source code created from a string. Dynamic class creation can be used in extremely low latency applications to improve performance.

Can we create a class dynamically in C#?

You can create custom dynamic objects by using the classes in the System. Dynamic namespace. For example, you can create an ExpandoObject and specify the members of that object at run time. You can also create your own type that inherits the DynamicObject class.

How do you create a dynamic class?

Classes can be dynamically created using the type() function in Python. The type() function is used to return the type of the object. The above syntax returns the type of object.


1 Answers

Yes it is with System.Reflection.Emit namespace.

But in .net 4.0 you can use dynamic keywoard for this. Like this http://blogs.msdn.com/b/mcsuksoldev/archive/2010/02/04/dynamic-xml-reader-with-c-and-net-4-0.aspx

without dynamic, even if you create new class, you will need reflection to access their properties

like image 124
Kikaimaru Avatar answered Oct 30 '22 04:10

Kikaimaru