{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/13952","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/13952/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/13952/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/13952/events","html_url":"https://github.com/dotnet/roslyn/issues/13952","id":178345918,"number":13952,"title":"Proposal: C# interface delegation","user":{"login":"Opiumtm","id":16596090,"avatar_url":"https://avatars.githubusercontent.com/u/16596090?v=3","gravatar_id":"","url":"https://api.github.com/users/Opiumtm","html_url":"https://github.com/Opiumtm","followers_url":"https://api.github.com/users/Opiumtm/followers","following_url":"https://api.github.com/users/Opiumtm/following{/other_user}","gists_url":"https://api.github.com/users/Opiumtm/gists{/gist_id}","starred_url":"https://api.github.com/users/Opiumtm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Opiumtm/subscriptions","organizations_url":"https://api.github.com/users/Opiumtm/orgs","repos_url":"https://api.github.com/users/Opiumtm/repos","events_url":"https://api.github.com/users/Opiumtm/events{/privacy}","received_events_url":"https://api.github.com/users/Opiumtm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-21T13:25:19Z","updated_at":"2016-09-21T13:44:25Z","closed_at":null,"body":"There was useful feature in Borland Delphi, interface delegation. This feature is absent in C#.\r\nYou can delegate interface implementation on class to instance stored in field or property.\r\n\r\nDeclare sample interface and sample implementation:\r\n```C#\r\npublic interface ISampleInterface\r\n{\r\n    void DoSomeWork();\r\n    int GetSomeResult();\r\n}\r\n\r\npublic sealed class SampleImplementation : ISampleInterface\r\n{\r\n    public void DoSomeWork()\r\n    {\r\n        // do some work\r\n    }\r\n\r\n   public int GetSomeResult()\r\n   {\r\n       // return some result here\r\n   }\r\n}\r\n```\r\n\r\nDelegate interface implementation:\r\n```C#\r\npublic sealed class DelegatedImplementation : ISampleInterface\r\n{\r\n    private ISampleInterface _wrappedObj : ISampleInterface;\r\n\r\n    public DelegatedImplementation(ISampleInterface wrappedObj)\r\n    {\r\n        _wrappedObj = wrappedObj;\r\n    }\r\n}\r\n```\r\nThis would translate to:\r\n```C#\r\npublic sealed class DelegatedImplementation : ISampleInterface\r\n{\r\n    private ISampleInterface _wrappedObj;\r\n\r\n    void ISampleInterface.DoSomeWork()\r\n    {\r\n        _wrappedObj.DoSomeWork();\r\n    }\r\n\r\n    int ISampleInterface.GetSomeResult()\r\n    {\r\n        return _wrappedObj.GetSomeResult();\r\n    }\r\n\r\n    public DelegatedImplementation(ISampleInterface wrappedObj)\r\n    {\r\n        _wrappedObj = wrappedObj;\r\n    }\r\n}\r\n```\r\nSo, `ISampleInterface` implementation is transparently delegated to field `_wrappedObj`\r\n```C#\r\nprivate ISampleInterface _wrappedObj : ISampleInterface;\r\n```\r\n\r\nClass, of course, can override this behavior:\r\n```C#\r\npublic sealed class DelegatedImplementation : ISampleInterface\r\n{\r\n    private ISampleInterface _wrappedObj : ISampleInterface;\r\n\r\n    /* delegation for DoSomeWork member is ignored as class explicitly implement this member */\r\n    void ISampleInterface.DoSomeWork()\r\n    {        \r\n        // do some other work\r\n    }\r\n\r\n    public DelegatedImplementation(ISampleInterface wrappedObj)\r\n    {\r\n        _wrappedObj = wrappedObj;\r\n    }\r\n}\r\n```\r\nThis would translate to:\r\n```C#\r\npublic sealed class DelegatedImplementation : ISampleInterface\r\n{\r\n    private ISampleInterface _wrappedObj;\r\n\r\n    /* delegation for DoSomeWork member is ignored as class explicitly implement this member */\r\n    void ISampleInterface.DoSomeWork()\r\n    {\r\n        // do some other work\r\n    }\r\n\r\n    /* this member is still delegated as class doesn't override delegation behavior */\r\n    int ISampleInterface.GetSomeResult()\r\n    {\r\n        return _wrappedObj.GetSomeResult();\r\n    }\r\n\r\n    public DelegatedImplementation(ISampleInterface wrappedObj)\r\n    {\r\n        _wrappedObj = wrappedObj;\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/248616553","html_url":"https://github.com/dotnet/roslyn/issues/13952#issuecomment-248616553","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/13952","id":248616553,"user":{"login":"Opiumtm","id":16596090,"avatar_url":"https://avatars.githubusercontent.com/u/16596090?v=3","gravatar_id":"","url":"https://api.github.com/users/Opiumtm","html_url":"https://github.com/Opiumtm","followers_url":"https://api.github.com/users/Opiumtm/followers","following_url":"https://api.github.com/users/Opiumtm/following{/other_user}","gists_url":"https://api.github.com/users/Opiumtm/gists{/gist_id}","starred_url":"https://api.github.com/users/Opiumtm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Opiumtm/subscriptions","organizations_url":"https://api.github.com/users/Opiumtm/orgs","repos_url":"https://api.github.com/users/Opiumtm/repos","events_url":"https://api.github.com/users/Opiumtm/events{/privacy}","received_events_url":"https://api.github.com/users/Opiumtm/received_events","type":"User","site_admin":false},"created_at":"2016-09-21T13:44:25Z","updated_at":"2016-09-21T13:44:25Z","body":"@HaloFour you can implement anything via source generators.\r\nTo avoid usage of source generators language features are introduced."}}
{"actor":{"display_login":"Opiumtm"}}