Object createObjectBy(Type clazz){
// .. do construction work here
Object theObject = Activator.CreateInstance(clazz);
return theObject;
}
Usage:
createObjectBy(typeof(A));
Or you could simply use Activator.CreateInstance
directly 🙂
More Related Contents:
- How do I get the contents of a JSON file I added in the StartUp method to use it in one of my actions?
- Object dispose in IDisposable class
- Throttling asynchronous tasks
- Object cannot be cast from DBNull to other types
- Gradient Circles for Map Generator
- Passing strings from C# to C++ DLL and back — minimal example
- DateTime “null” value
- C# Export Private/Public RSA key from RSACryptoServiceProvider to PEM string
- C#: Raising an inherited event
- C# ‘is’ operator performance
- Call static method with reflection
- Web API 2: how to return JSON with camelCased property names, on objects and their sub-objects
- What are the limitations of SqlDependency?
- What are the benefits to marking a field as `readonly` in C#?
- How do I use the LINQPad Dump() extension method in Visual Studio? [closed]
- Get Substring – everything before certain char
- Creating an anonymous type dynamically? [duplicate]
- Asynchronously sending Emails in C#?
- Enumerating Collections that are not inherently IEnumerable?
- asp.net dynamically button with event handler
- Setting a WebRequest’s body data
- @Html.HiddenFor does not work on Lists in ASP.NET MVC
- How do I measure how long a function is running?
- C# List – Removing items while looping / iterating [duplicate]
- Json.Net adding $id to EF objects despite setting PreserveReferencesHandling to “None”
- Getting files by creation date in .NET
- Installing a .NetStandard 2.0 Nuget package into a VS2015 Net 4.6.1 project
- How to modify IConfiguration natively injected in Azure Functions
- The component does not have a resource identified by the uri
- WPF C# InputBox