Exemple #1
0
        public static void SetValue(
            object instance,
            MutableMember member,
            object value,
            IValueContext context)
        {
            var perspexProperty = FindPerspexProperty(instance, member);

            if (value is IBinding)
            {
                SetBinding(instance, member, perspexProperty, context, (IBinding)value);
            }
            else if (perspexProperty != null)
            {
                ((PerspexObject)instance).SetValue(perspexProperty, value);
            }
            else if (instance is Setter && member.Name == "Value")
            {
                // TODO: Make this more generic somehow.
                var setter         = (Setter)instance;
                var targetType     = setter.Property.PropertyType;
                var xamlType       = member.TypeRepository.GetByType(targetType);
                var convertedValue = default(object);

                if (CommonValueConversion.TryConvert(value, xamlType, context, out convertedValue))
                {
                    SetClrProperty(instance, member, convertedValue);
                }
            }
            else
            {
                SetClrProperty(instance, member, value);
            }
        }
Exemple #2
0
        public void AssignChildToParentProperty()
        {
            var    previousMember = (MutableMember)Previous.Member;
            object compatibleValue;

            var success = CommonValueConversion.TryConvert(Current.Instance, previousMember.XamlType, valueContext, out compatibleValue);

            if (!success)
            {
                compatibleValue = Current.Instance;
            }

            previousMember.SetValue(Previous.Instance, compatibleValue, valueContext);
        }
Exemple #3
0
        private void AdaptCurrentCtorArgumentsToCurrentType()
        {
            var arguments = (IList <ConstructionArgument>)StateCommuter.Current.CtorArguments;
            var xamlTypes = GetTypesOfBestCtorMatch(StateCommuter.Current.XamlType, arguments.Count);

            var i = 0;

            foreach (var ctorArg in arguments)
            {
                var    targetType = xamlTypes[i];
                object compatibleValue;
                CommonValueConversion.TryConvert(ctorArg.StringValue, targetType, valueContext, out compatibleValue);
                ctorArg.Value = compatibleValue;
                i++;
            }
        }
        public override void SetValue(object instance, object value, IValueContext valueContext)
        {
            if (member.Name == "Value" && instance is Setter)
            {
                var setter     = (Setter)instance;
                var targetType = setter.Property.PropertyType;
                var xamlType   = member.TypeRepository.GetByType(targetType);

                object compatibleValue;
                CommonValueConversion.TryConvert(value, xamlType, valueContext, out compatibleValue);

                base.SetValue(instance, compatibleValue, valueContext);
            }
            else
            {
                if (!TrySetDependencyProperty(instance, value))
                {
                    base.SetValue(instance, value, valueContext);
                }
            }
        }
Exemple #5
0
        public override void Execute()
        {
            switch (StateCommuter.ValueProcessingMode)
            {
            case ValueProcessingMode.InitializationValue:
                object compatibleValue;
                CommonValueConversion.TryConvert(value, StateCommuter.Current.XamlType, valueContext, out compatibleValue);
                StateCommuter.Current.Instance    = compatibleValue;
                StateCommuter.ValueProcessingMode = ValueProcessingMode.AssignToMember;
                break;

            case ValueProcessingMode.Key:
                StateCommuter.SetKey(value);
                StateCommuter.ValueProcessingMode = ValueProcessingMode.AssignToMember;
                break;

            case ValueProcessingMode.ConstructionParameter:
                StateCommuter.AddCtorArgument(value);
                break;

            case ValueProcessingMode.AssignToMember:
                StateCommuter.RaiseLevel();
                StateCommuter.Current.Instance = value;
                StateCommuter.AssociateCurrentInstanceToParent();
                StateCommuter.DecreaseLevel();
                break;

            case ValueProcessingMode.Name:
                StateCommuter.SetNameForCurrentInstance(value);
                StateCommuter.ValueProcessingMode = ValueProcessingMode.AssignToMember;
                break;

            default:
                throw new ParseException(
                          "Unexpected mode was set trying to process a Value XAML instruction. " +
                          $"We found \"{StateCommuter.ValueProcessingMode}\") and it cannot be handled.");
            }
        }