[C] allow inheriting from Behavior (#5559)

- fixes #5520
This commit is contained in:
Stephane Delcroix 2019-04-08 19:15:14 +02:00 коммит произвёл Samantha Houts
Родитель 7dc2edc7b0
Коммит ccf8c123c4
1 изменённых файлов: 5 добавлений и 9 удалений

Просмотреть файл

@ -5,28 +5,24 @@ namespace Xamarin.Forms
{ {
public abstract class Behavior : BindableObject, IAttachedObject public abstract class Behavior : BindableObject, IAttachedObject
{ {
internal Behavior(Type associatedType) protected Behavior() : this(typeof(BindableObject))
{ {
if (associatedType == null)
throw new ArgumentNullException("associatedType");
AssociatedType = associatedType;
} }
internal Behavior(Type associatedType) => AssociatedType = associatedType ?? throw new ArgumentNullException(nameof(associatedType));
protected Type AssociatedType { get; } protected Type AssociatedType { get; }
void IAttachedObject.AttachTo(BindableObject bindable) void IAttachedObject.AttachTo(BindableObject bindable)
{ {
if (bindable == null) if (bindable == null)
throw new ArgumentNullException("bindable"); throw new ArgumentNullException(nameof(bindable));
if (!AssociatedType.IsInstanceOfType(bindable)) if (!AssociatedType.IsInstanceOfType(bindable))
throw new InvalidOperationException("bindable not an instance of AssociatedType"); throw new InvalidOperationException("bindable not an instance of AssociatedType");
OnAttachedTo(bindable); OnAttachedTo(bindable);
} }
void IAttachedObject.DetachFrom(BindableObject bindable) void IAttachedObject.DetachFrom(BindableObject bindable) => OnDetachingFrom(bindable);
{
OnDetachingFrom(bindable);
}
protected virtual void OnAttachedTo(BindableObject bindable) protected virtual void OnAttachedTo(BindableObject bindable)
{ {