Пример #1
0
 protected override void BindConstant(BindingInfo info)
 {
     if (info is ConstantBindingInfo <T> constantInfo)
     {
         boundProperty = new ObservableVariable <T>(constantInfo.Constant);
         RaiseFirstNotification();
     }
 }
Пример #2
0
        protected override void UnbindProperty()
        {
            if (boundProperty != null)
            {
                boundProperty.Changed -= OnBoundPropertyChanged;
                boundProperty          = null;
            }

            exposedProperty.Clear();
        }
Пример #3
0
        public static T GetValue <T>(this IReadOnlyObservableVariable <T> variable, T fallback)
        {
            T result = fallback;

            if (variable.HasValue)
            {
                result = variable.Value;
            }

            return(result);
        }
Пример #4
0
        private static IReadOnlyObservableVariable <T> BoxVariable(object variableToBox)
        {
            IReadOnlyObservableVariable <T> result = null;

            Type variableGenericType = variableToBox.GetType().GetGenericTypeTowardsRoot();

            if (variableGenericType != null)
            {
                Type exposedType    = typeof(T);
                Type boxedType      = variableGenericType.GenericTypeArguments[0];
                Type activationType = typeof(VariableBoxer <,>).MakeGenericType(exposedType, boxedType);
                result = Activator.CreateInstance(activationType, variableToBox) as IReadOnlyObservableVariable <T>;
            }

            return(result);
        }
Пример #5
0
        protected override void BindProperty(object property)
        {
            boundProperty = property as IReadOnlyObservableVariable <T>;

            if (boundProperty == null && BindingUtils.NeedsToBeBoxed(property.GetType(), typeof(IReadOnlyObservableVariable <T>)))
            {
                boundProperty = BoxVariable(property);
            }

            if (boundProperty != null)
            {
                boundProperty.Changed += OnBoundPropertyChanged;
                RaiseFirstNotification();
            }
            else
            {
                Debug.LogError($"Property type ({property.GetType()}) cannot be bound as {typeof(IReadOnlyObservableVariable<T>)}", context);
            }
        }
Пример #6
0
 public VariableBoxer(IReadOnlyObservableVariable <TBoxed> boxedVariable)
 {
     this.boxedVariable     = boxedVariable;
     boxedVariable.Changed += OnBoxedVariableChanged;
     boxedVariable.Cleared -= OnBoxedVariableCleared;
 }
Пример #7
0
 public ObservableCommand(IObservableVariable <bool> canExecuteSource)
 {
     CanExecute = canExecuteSource;
 }
Пример #8
0
 public OperatorVariableViewModel(IReadOnlyObservableVariable <T> value)
 {
     Value = value;
 }