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
someeventnamename of event- the properties specific event
- the
tostringoverride need substitutesomeeventnameactual type of class - the
defaultmethod 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
Post a Comment