c# - Creating similiar classes programatically including methods -


hopefully title, explained question, trying create classes programmatically each 1 have different properties along methods specific each.

currently, each class manually created change programmatically if possible. @ moment, each class following:

public class someeventname : eventbase {      public string hardwareid { get; set; }     public ushort componantstatus { get; set; }      public override string tostring()     {         return string.format("someeventname event - hardwareid: {0}, generatedtime: {1}, receivedtime: {2}", hardwareid , generatedtime, receivedtime);     }      public static someeventname default(string tvmid, datetime createtime, datetime receivetime)     {         return new someeventname          {             hardwareid = hardwareid,             generatedtime = generatedtime,             receivedtime = receivedtime,             adaptedtime = datetime.utcnow         };     } } 

i have substituted names

  • someeventname name of event
  • the properties specific event
  • the tostring override need substitute someeventname actual type of class
  • the default method need return instance of class.

i know classes can created through code using reflection.emit, when comes methods, i've seen ways of doing through il code want avoid. change tostring override use parameter print class type, unsure how handle default method.

the must haves need able instantiate said classes , need following line of code return actual type , not generic name:

typeof(someeventname); 

therefore, reflection best bet , if so, there way handle default method without having use il code? or there different way approach this?

assuming want write assembly given classes, can use runsharp. once got syntax, can write assemblies in runtime can reference other applications.

the declaration pretty straight-forward , can use write valid .net-assemblies (with reflectable .net code) without having deal il.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -