TizenFX
TizenFX copied to clipboard
[NUI] Use generic delegate to avoid boxing unboxing
trafficstars
Description of Change
This is a draft patch. I added BindableProperty Create<> (generic) api, but it still exists boxing/unboxing it. so I wonder if there is any point in continuing?
internal static BindableProperty Create<TDeclarer, TPropertyType>(string propertyName, TPropertyType defaultValue, BindingMode defaultBindingMode,
ValidateValueDelegate<TPropertyType> validateValue, BindingPropertyChangedDelegate<TPropertyType> propertyChanged, BindingPropertyChangingDelegate<TPropertyType> propertyChanging,
CoerceValueDelegate<TPropertyType> coerceValue, BindablePropertyBindingChanging bindingChanging, bool isReadOnly = false,
CreateDefaultValueDelegate<TDeclarer, TPropertyType> defaultValueCreator = null) where TDeclarer : BindableObject
{
ValidateValueDelegate untypedValidateValue = null;
BindingPropertyChangedDelegate untypedBindingPropertyChanged = null;
BindingPropertyChangingDelegate untypedBindingPropertyChanging = null;
CoerceValueDelegate untypedCoerceValue = null;
CreateDefaultValueDelegate untypedDefaultValueCreator = null;
if (validateValue != null)
untypedValidateValue = (bindable, value) => validateValue(bindable, (TPropertyType)value);
if (propertyChanged != null)
untypedBindingPropertyChanged = (bindable, oldValue, newValue) => propertyChanged(bindable, (TPropertyType)oldValue, (TPropertyType)newValue);
if (propertyChanging != null)
untypedBindingPropertyChanging = (bindable, oldValue, newValue) => propertyChanging(bindable, (TPropertyType)oldValue, (TPropertyType)newValue);
if (coerceValue != null)
untypedCoerceValue = (bindable, value) => coerceValue(bindable, (TPropertyType)value);
if (defaultValueCreator != null)
untypedDefaultValueCreator = o => defaultValueCreator((TDeclarer)o);
return new BindableProperty(propertyName, typeof(TPropertyType), typeof(TDeclarer), defaultValue, defaultBindingMode, untypedValidateValue, untypedBindingPropertyChanged,
untypedBindingPropertyChanging, untypedCoerceValue, bindingChanging, isReadOnly, untypedDefaultValueCreator);
}
API Changes
- ACR: None