Skip to content
New issue

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

Implement IBindable interfaces for get-only support #1517

merged 3 commits into from Apr 15, 2018


Copy link

@smoogipoo smoogipoo commented Apr 13, 2018

Doesn't change existing code, but will now allow us to expose bindables as IBindable and IBindable<T> with get-only access, disallowing external objects from setting values.

Bindables must be exposed as the same interface to be able to bind to each other, or must use potentially unsafe casting to bind to interface-types. The following compile-time behaviour is observed:

IBindable bindable1 = new Bindable<int>();
IBindable bindable2 = new Bindable<int>();
IBindable<int> bindable3 = new Bindable<int>();
IBindable<int> bindable4 = new Bindable<int>();
Bindable<int> bindable5 = new Bindable<int>();
Bindable<int> bindable6 = new Bindable<int>();

bindable1.BindTo(bindable2); // Allowed
bindable1.BindTo(bindable3); // Not allowed (not assignable)
bindable1.BindTo(bindable5); // Allowed

bindable3.BindTo(bindable1); // Not allowed (not assignable)
bindable3.BindTo(bindable4); // Allowed
bindable3.BindTo(bindable6); // Allowed

bindable5.BindTo(bindable1); // Not allowed (not assignable)
bindable5.BindTo(bindable3); // Not allowed (not assignable)
bindable5.BindTo(bindable6); // Allowed

bindable5.BindTo((Bindable<int>)bindable1); // Allowed, but unsafe and may lead to InvalidCastExceptions
bindable5.BindTo((Bindable<int>)bindable3); // Allowed, but unsafe and may lead to InvalidCastExceptions

bindable2 = bindable1.GetBoundCopy(); // Allowed
bindable2 = bindable3.GetBoundCopy(); // Not allowed (cannot convert)
bindable2 = bindable5.GetBoundCopy(); // Allowed

bindable4 = bindable1.GetBoundCopy(); // Not allowed (cannot convert)
bindable4 = bindable3.GetBoundCopy(); // Allowed
bindable4 = bindable5.GetBoundCopy(); // Allowed

bindable6 = bindable1.GetBoundCopy(); // Not allowed (cannot convert)
bindable6 = bindable3.GetBoundCopy(); // Not allowed (cannot convert)
bindable6 = bindable5.GetBoundCopy(); // Allowed

@peppy peppy merged commit f155804 into ppy:master Apr 15, 2018
@smoogipoo smoogipoo deleted the ibindable-interfaces branch November 26, 2018 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants