We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
To use the delegation on various design patterns, we must write a lot of tedious code.
To introduce the delegation class in c#.
Class Z use a delegation to class A.
class A { public int Method1() { return 0; } public void Method2(int p) {} public void Method3(int p) {} } class Z : delegate A { public void Set(A a) { base<A> = a; } }
The delegation syntax is written like the inheritance syntax; Above is expanded to:
class Z { private A _a; public int Method1() { return _a.Method1(); } public void Method2(int p) { _a.Method2(p); } public void Method3(int p) { _a.Method3(p); } public void Set(A a) { _a = a; } }
Three methods are automatically generated by the compiler.
Next example is using with readonly and override keyword. You must set a delegation in constructor and you can change a method behavior.
class Y : delegate readonly A { public Y(A a) { base<A> = a; } public override int Method1() { return base<A>.Method1() + 1; } }
Above is expanded to:
class Y { private readonly A _a; void Method2(int p) { _a.Method2(p); } public void Method3(int p) { _a.Method3(p); } public Y(A a) { _a = a; } public int Method1() { return _a.Method1() + 1; } }
Next example is using two delegation classes. Class B has two conflict method names, so one is given an alias name, other is excluded.
class B { public int Method1() { return 10; } public void Method2(int p) {} public void Method3(string q) {} } class W : delegate A, delegate B { uses { B { alias B_Method1 = Method1; exclude Method2; } } public void Set(A a) { base<A> = a; } public void Set(B b) { base<B> = b; } }
class W { private A _a; public int Method1() { return _a.Method1(); } public void Method2(int p) { _a.Method2(p); } public void Method3(int p) { _a.Method3(p); } private B _b; public int B_Method1() { return _b.Method1(); } public void Method3(string q) { _b.Method3(q); } public void Set(A a) { _a = a; } public void Set(B b) { _b = b; } }
Next example is using with inheritance. It is similar to the previous example.
class U : A, delegate B { uses { B { alias B_Method1 = Method1; exclude Method2; } } public void Set(B b) { base<B> = b; } }
class U : A { private B _b; public int B_Method1() { return _b.Method1(); } public void Method3(string q) { _b.Method3(q); } public void Set(B b) { _b = b; } }
I wish that this proposal makes C# better and it is useful for the people using C#.
The text was updated successfully, but these errors were encountered:
This is actually a mixin. See #60 I think a better way is to also support mixin in generic constraints.
Sorry, something went wrong.
@zgxnet
I read #60 interestingly very much. I wish that C# 7 will be added a mixin or a trait that has better supports of delegation.
Thank you for your kind comment.
We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages.
Traits, which are proposed at dotnet/csharplang#52, can provide some of the requestion functionality but in a syntactically different form.
No branches or pull requests
Problem
To use the delegation on various design patterns, we must write a lot of tedious code.
Proposal
To introduce the delegation class in c#.
Example
Class Z use a delegation to class A.
The delegation syntax is written like the inheritance syntax;
Above is expanded to:
Three methods are automatically generated by the compiler.
Next example is using with readonly and override keyword. You must set a delegation in constructor and you can change a method behavior.
Above is expanded to:
Next example is using two delegation classes. Class B has two conflict method names, so one is given an alias name, other is excluded.
Above is expanded to:
Next example is using with inheritance. It is similar to the previous example.
Above is expanded to:
I wish that this proposal makes C# better and it is useful for the people using C#.
The text was updated successfully, but these errors were encountered: