private bool TryCreateCompatibleInstanceForCurrentMember(StateBag stateBag, object instanceToConvert, Type destinationType) { var convertedValue = ConvertValueIfNecessary(instanceToConvert, destinationType); stateBag.Current.Instance = convertedValue; return true; }
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); } }
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; }
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); } }
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); }
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); } } }
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; } }
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); } } }
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); } }