You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a proposal to add some kind of "bind" declaration (the name can be changed if people prefer something else), where one can create a binding between a class and an interface such that the class can be used as though it implemented the interface in code where the binding is accessible. Here's an example of what this might look like:
// Assembly ApublicclassFoo{publicintval;publicFoo(inti){val=i;}publicvoidMethodA(){}publicvoidMethodB(){}publicvoidMethodC(){}}// Assembly BpublicinterfaceIBar{voidSomethingA();intSomethingB();voidSomethingC(intx);}// Your Assembly// this syntax was thrown together quickly, so that can be changed.publicbindFoo: IBar {voidSomethingA()=>MethodA();intSomethingB(){MethodB();returnval;}// only public fields and methods are accessible. voidSomethingC(intx)=>MethodC();}// The binding can be used as such...Foofoo=newFoo(3);IBarbar=foo;bar=newFoo(4);foo=(Foo)bar;
The bind declaration automatically generates:
[ClassInterfaceBinding(typeof(Foo),typeof(IBar))]// Exposes this binding to other assemblies.// There may be another way to do this that I'm not aware of.struct_BindFooIBar:IBar{privateFoo_instance;public_BindFooIBar(Fooinstance){_instance=instance;}publicvoidSomethingA()=>_instance.MethodA();publicintSomethingB(){_instance.MethodB();return_instance.val;}publicvoidSomethingC(intx)=>_instance.MethodC();publicstaticexplicitoperatorFoo(_BindFooIBarv)=>v._instance;publicstaticexplicitoperator_BindFooIBar(Foov)=>new_BindFooIBar(v);}
While in some ways similar, this proposal is not covered by shapes. "Extension everything" also does not cover this proposal to my knowledge, though this proposal could theoretically be merged into "extension everything."
Outstanding questions:
What should be done if multiple namespaces provide the same binding? With extension methods it simply blocks you from using that extension method. Would doing the same make sense for bindings?
The text was updated successfully, but these errors were encountered:
Almost, but not quite. This would allow binding a class to an interface that already exists. To my understanding (which may be wrong), an API must ask for a shape in order to support shapes being used. If it only asks for an interface, you can't treat that interface as if it was a shape.
This is a proposal to add some kind of "bind" declaration (the name can be changed if people prefer something else), where one can create a binding between a class and an interface such that the class can be used as though it implemented the interface in code where the binding is accessible. Here's an example of what this might look like:
The bind declaration automatically generates:
And the usage magically translates to:
While in some ways similar, this proposal is not covered by shapes. "Extension everything" also does not cover this proposal to my knowledge, though this proposal could theoretically be merged into "extension everything."
Outstanding questions:
The text was updated successfully, but these errors were encountered: