{"action":"closed","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/1974","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/1974/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/1974/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/1974/events","html_url":"https://github.com/dotnet/csharplang/issues/1974","id":376137799,"node_id":"MDU6SXNzdWUzNzYxMzc3OTk=","number":1974,"title":"[Proposal] Constructor constraint with params in generic class or method definition like where T : new(*ctor_signature*)","user":{"login":"woldemar89","id":20968707,"node_id":"MDQ6VXNlcjIwOTY4NzA3","avatar_url":"https://avatars0.githubusercontent.com/u/20968707?v=4","gravatar_id":"","url":"https://api.github.com/users/woldemar89","html_url":"https://github.com/woldemar89","followers_url":"https://api.github.com/users/woldemar89/followers","following_url":"https://api.github.com/users/woldemar89/following{/other_user}","gists_url":"https://api.github.com/users/woldemar89/gists{/gist_id}","starred_url":"https://api.github.com/users/woldemar89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/woldemar89/subscriptions","organizations_url":"https://api.github.com/users/woldemar89/orgs","repos_url":"https://api.github.com/users/woldemar89/repos","events_url":"https://api.github.com/users/woldemar89/events{/privacy}","received_events_url":"https://api.github.com/users/woldemar89/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-10-31T20:01:59Z","updated_at":"2018-10-31T21:33:55Z","closed_at":"2018-10-31T21:33:55Z","author_association":"NONE","body":"I would like to have possibility to add params to constructor constraint in generic classes and methods:\r\n\r\n`public class MyClass<T1, T2> where T1 : new(*parameters*) { }`\r\n\r\nFor example, I want to create next class: \r\n\r\n`public class MyClass<T1, T2> where T2 : new(T1) { }` \r\n\r\nto oblige T2 have ctor which accepts T1 instance, but can point only 'new()' constraint, \r\nand at the moment I need to use next way:\r\n\r\n```\r\nabstract class MustHaveConstructor<T>\r\n{\r\n     public MustHaveConstructor(T param) { }\r\n}\r\n\r\nclass A { }\r\n\r\nclass B : MustHaveConstructor<A>\r\n{\r\n     public B(A a) : base(a) { }\r\n}\r\n\r\npublic class MyClass<T1, T2> where T2 : MustHaveConstructor<T1> { }\r\n```\r\n\r\nOkay, fine, but the problem begins then I also want to have T2 inherited from T1:\r\n\r\n`public class MyClass<T1, T2> where T2 : MustHaveConstructor<T1>, T1`\r\n\r\nC# does not support multiple inheritance, so it is not possible to have both requirements.\r\n\r\nI think it is not a single problem that can be solved by having params in constructor constraints.\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"gafter"}}