Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. public class ITestInterface { };
  2.  
  3.  
  4. public class TestClass<T> : ITestInterface
  5. {
  6. public T member { get; set; }
  7. }
  8.  
  9. public static class Util
  10. {
  11. public static ITestInterface Create<C>(C t)
  12. {
  13. return new TestClass<C> { member = t };
  14. }
  15. }
  16.  
  17. class Program
  18. {
  19. static void Main(string[] args)
  20. {
  21.  
  22. var a = Util.Create(new
  23. {
  24. p1 = 100,
  25. p2 = "string"
  26. });
  27.  
  28. var b = a as TestClass<Object>;
  29. // this will be "null" in this example
  30. // So, how can I convert back to its real type?
  31. // And get the "member" data
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement