How can i add property to a class dynamically
问题 I want to create an error class. And it has some static properties. For example : Message , InnerException , Stacktrace , Source . But I want to add some dynamic properties. If exception is a FileNotFoundException , I want to add FileName property. Or if it is a SqlException , I want to add LineNumber property. And I can't inherit that class from Exception because, I return that class from a web service. How can I do that? 回答1: you can create type dynamically using new features in C# like