コード例 #1
0
        private bool TryCreateCompatibleInstanceForCurrentMember(StateBag stateBag, object instanceToConvert, Type destinationType)
        {
            var convertedValue = ConvertValueIfNecessary(instanceToConvert, destinationType);

            stateBag.Current.Instance = convertedValue;
            return true;
        }
コード例 #2
0
        internal void PrepareNewInstanceBecauseWeWantToConfigureIt(StateBag bag)
        {
            var newInstance = typeOperations.Create(bag.Current.Type);
            bag.Current.Instance = newInstance;

            if (bag.LiveDepth > 1 && !(newInstance is IMarkupExtension) && bag.LiveDepth > 1)
            {
                CheckAssignmentToParentStart(bag);
            }
        }
コード例 #3
0
        private MarkupExtensionContext GetExtensionContext(StateBag stateBag)
        {
            var inflationContext = new MarkupExtensionContext
            {
                TargetObject = stateBag.Parent.Instance,
                TargetProperty = stateBag.Parent.Instance.GetType().GetRuntimeProperty(stateBag.Parent.Property.Name),
                TypeRepository = this.XamlTypeRepository,
            };

            return inflationContext;
        }
コード例 #4
0
        private void ApplyPropertyValue(StateBag bag, XamlMember parentProperty, object value, bool onParent)
        {
            var instance = onParent ? bag.Parent.Instance : bag.Current.Instance;

            var isSetExternally = OnSetValue(instance, parentProperty, value);

            if (!isSetExternally)
            {
                TypeOperations.SetValue(instance, parentProperty, value);
            }
        }
コード例 #5
0
        private void AssignValueFromMarkupExtension(StateBag stateBag)
        {
            var markupExtension = (IMarkupExtension)stateBag.Current.Instance;

            var extensionContext = GetExtensionContext(stateBag);

            var providedValue = markupExtension.ProvideValue(extensionContext);

            stateBag.Current.Type = typeRepository.GetXamlType(providedValue.GetType());
            stateBag.Current.Instance = providedValue;

            AssignCurrentInstanceToParent(Bag);
        }
コード例 #6
0
        private void AssignCurrentInstanceToParent(StateBag bag)
        {
            var parentProperty = bag.Parent.Property;
            var currentInstance = bag.Current.Instance;
            var parentPropertyType = parentProperty.Type;

            if (IsAssignmentBeingMadeToContainer(parentProperty, parentPropertyType))
            {
                AssignInstanceToParentCollection(bag.Parent.Collection, bag.Current.Instance);
            }
            else if (bag.Parent.Instance != null)
            {
                if (!bag.Current.IsObjectFromMember)
                {
                    ApplyPropertyValue(bag, parentProperty, currentInstance, true);
                }
            }
        }
コード例 #7
0
 private void CheckAssignmentToParentStart(StateBag bag)
 {
     var parentPropertyIsItemsDictionary = bag.Parent.Property == CoreTypes.Items && bag.Parent.Type.IsDictionary;
     if (!parentPropertyIsItemsDictionary)
     {
         bag.Current.WasAssignedAtCreation = true;
         AssignCurrentInstanceToParent(bag);
     }
     else
     {
         bag.Current.WasAssignedAtCreation = false;
     }
 }
コード例 #8
0
        internal void AssignCurrentInstanceToParent(StateBag bag)
        {
            var parentProperty = (MutableXamlMember)bag.Parent.Property;
            var currentInstance = bag.Current.Instance;
            var parentPropertyType = parentProperty.XamlType;

            if (IsAssignmentBeingMadeToContainer(parentProperty, parentPropertyType))
            {
                AssignCurrentInstanceToParentCollection();
            }
            else if (bag.Parent.Instance != null)
            {
                if (!bag.Current.IsCollectionHoldingObject)
                {
                    ApplyPropertyValue(bag, parentProperty, currentInstance, true);
                }
            }
        }
コード例 #9
0
        internal void PrepareNewInstanceBecauseWeWantToConfigureIt(StateBag bag)
        {
            var parameters = bag.Current.ConstructorArguments != null ? bag.Current.ConstructorArguments.ToArray() : null;
            var newInstance = typeOperations.Create(bag.Current.Type, parameters);

            // Resets the constructor arguments
            bag.Current.ConstructorArguments = null;
            bag.Current.Instance = newInstance;


            if (bag.LiveDepth > 1 && !(newInstance is IMarkupExtension) && bag.LiveDepth > 1)
            {
                CheckAssignmentToParentStart(bag);
            }
        }