fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. interface IEntity
  5. {
  6. string Name { get; set; }
  7. }
  8.  
  9. class FooEntity : IEntity
  10. {
  11. public string Name { get; set; }
  12.  
  13. public FooEntity()
  14. {
  15. Name = "foo";
  16. }
  17. }
  18.  
  19. interface ILetter<T> where T:IEntity
  20. {
  21. string EntityMetadata { get; set; }
  22. List<T> GetRecords();
  23. }
  24.  
  25.  
  26. abstract class AbstractLetter<T> : ILetter<T> where T:IEntity
  27. {
  28. public abstract string EntityMetadata { get; set; }
  29. public abstract List<T> GetRecords();
  30. }
  31.  
  32. class JobLetter<T> : AbstractLetter<T> where T : IEntity, new()
  33. {
  34. public override string EntityMetadata { get; set; }
  35. public override List<T> GetRecords() { return null; }
  36.  
  37. public JobLetter()
  38. {
  39. var entity = new T();
  40. EntityMetadata = entity.Name;
  41. }
  42. }
  43.  
  44.  
  45.  
  46. public class Test
  47. {
  48. static List<T<K>> CreateLetterList<T, K>() where T : AbstractLetter<K>, new() where K : IEntity
  49. {
  50. return new List<T<K>> { new T<K>(), };
  51. }
  52.  
  53. public static void Main()
  54. {
  55. var jobLetterList = CreateLetterList<JobLetter, FooEntity>();
  56. foreach (var letter in jobLetterList)
  57. {
  58. Console.WriteLine(letter.EntityMetadata);
  59. }
  60. }
  61. }
Compilation error #stdin compilation error #stdout 0.03s 33920KB
stdin
Standard input is empty
compilation info
prog.cs(48,21): error CS0246: The type or namespace name `T' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty