Hello :
I have a nuget package , project. I have Implemented abstract class here.
Code Sample
//Nuget Package Project namespace Common.Base { public abstract class DocumentBase { public abstract byte[] Print(string Code, string Number); } } namespace Document.CraftFUN { public class ProcessFUN : DocumentBase { public override byte[] Print(string Code, string Number) { byte[] ByteStream = null; PDFByteStream = GenerateCraft(Code, Number); return (ByteStream); } } } namespace Document.CraftGUM { public class ProcessGUM : DocumentBase { public override byte[] Print(string Code, string Number) { byte[] ByteStream = null; PDFByteStream = GenerateCraft(Code, Number); return (ByteStream); } } } namespace Document.Iron { public class ProcessIron : DocumentBase { throw new NotImplementedException("This isn't done yet"); } }
//Code in WEb API
//var cls = (DocumentBase)System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(string className) if (Code.ToUpper() == "FUN") { ProcessFUN pc = new ProcessFUN(_config); foreach (string CraftToPrint in MyNumbers) { byte[] MemoBytes = pc.Print(Code.ToUpper(), CraftToPrint); } } if (Code.ToUpper() == "GUM") { ProcessGUM pc = new ProcessGUM(_config); foreach (string CraftToPrint in MyNumbers) { byte[] MemoBytes = pc.Print(Code.ToUpper(), CraftToPrint); } }
Is there a better way of Handling the above code initialization using Reflection
//var cls = (DocumentBase)System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(string className)
Thank you,
urpalshu