Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected T CreateNew<T>()
- where T : new()
- {
- return new T();
- }
- var x = CreateNew<Point>();
- ISomeInterface inter;
- if (selection == 1)
- inter = new SomeClass();
- else
- inter = new SomeClass2();
- // ...
- ISomeInterface inter2 = CreateNew<typeof(inter)>();
- Function<ISomeInterface> creationDelegate;
- if (selection == 1)
- creationDelegate = () => CreateNew<SomeClass>;
- else
- creationDelegate = () => CreateNew<SomeClass2>;
- ISomeInterface inter = creationDelegate();
- // ...
- ISomeInterface inter2 = creationDelegate();
Add Comment
Please, Sign In to add comment