Ejemplo n.º 1
0
        object IXamlNameResolver.GetFixupToken(IEnumerable <string> names, bool canAssignDirectly)
        {
            if (this._xamlContext.NameResolutionComplete)
            {
                return(null);
            }
            NameFixupToken token = new NameFixupToken {
                CanAssignDirectly = canAssignDirectly
            };

            token.NeededNames.AddRange(names);
            if (token.CanAssignDirectly && (token.NeededNames.Count != 1))
            {
                throw new ArgumentException(System.Xaml.SR.Get("SimpleFixupsMustHaveOneName"), "names");
            }
            if (this._xamlContext.CurrentType == null)
            {
                if (this._xamlContext.ParentProperty == XamlLanguage.Initialization)
                {
                    token.FixupType                = FixupType.ObjectInitializationValue;
                    token.Target.Instance          = this._xamlContext.GrandParentInstance;
                    token.Target.InstanceWasGotten = this._xamlContext.GrandParentIsObjectFromMember;
                    token.Target.InstanceType      = this._xamlContext.GrandParentType;
                    token.Target.Property          = this._xamlContext.GrandParentProperty;
                }
                else
                {
                    token.FixupType                = FixupType.PropertyValue;
                    token.Target.Instance          = this._xamlContext.ParentInstance;
                    token.Target.InstanceWasGotten = this._xamlContext.ParentIsObjectFromMember;
                    token.Target.InstanceType      = this._xamlContext.ParentType;
                    token.Target.Property          = this._xamlContext.ParentProperty;
                }
            }
            else
            {
                token.FixupType                = FixupType.MarkupExtensionRerun;
                token.Target.Instance          = this._xamlContext.ParentInstance;
                token.Target.InstanceWasGotten = this._xamlContext.ParentIsObjectFromMember;
                token.Target.InstanceType      = this._xamlContext.ParentType;
                token.Target.Property          = this._xamlContext.ParentProperty;
            }
            if (token.CanAssignDirectly)
            {
                token.NameScopeDictionaryList.AddRange(this._xamlContext.StackWalkOfNameScopes);
                return(token);
            }
            token.SavedContext = this._xamlContext.GetSavedContext((token.FixupType == FixupType.MarkupExtensionRerun) ? SavedContextType.ReparseMarkupExtension : SavedContextType.ReparseValue);
            return(token);
        }
Ejemplo n.º 2
0
        object IXamlNameResolver.GetFixupToken(IEnumerable <string> names, bool canAssignDirectly)
        {
            if (_xamlContext.NameResolutionComplete)
            {
                return(null);
            }
            var token = new NameFixupToken();

            token.CanAssignDirectly = canAssignDirectly;
            token.NeededNames.AddRange(names);
            if (token.CanAssignDirectly && token.NeededNames.Count != 1)
            {
                throw new ArgumentException(SR.Get(SRID.SimpleFixupsMustHaveOneName), "names");
            }

            // TypeConverter case (aka "Initialization")
            if (_xamlContext.CurrentType == null)
            {
                // If this is OBJECT Initialization
                if (_xamlContext.ParentProperty == XamlLanguage.Initialization)
                {
                    token.FixupType = FixupType.ObjectInitializationValue;

                    // If this is object initialization syntax:
                    //  SO Button>
                    //    SM Background
                    //       SO RefObject
                    //         SM _Initialization
                    //           V "_name"
                    // This TC will return the RefObject and
                    // The fixup is to Button.Background  (the grand parent)
                    //
                    token.Target.Instance          = _xamlContext.GrandParentInstance;
                    token.Target.InstanceWasGotten = _xamlContext.GrandParentIsObjectFromMember;
                    token.Target.InstanceType      = _xamlContext.GrandParentType;
                    token.Target.Property          = _xamlContext.GrandParentProperty;
                }
                else  // This is PROPERTY Initialization
                {
                    token.FixupType = FixupType.PropertyValue;

                    // If this is Property Value syntax:
                    //  SO TextBox
                    //    SM LabelProp   [has a NameRef TypeConverter]
                    //       V "_name"
                    // The fixup is to TextBox.LabelProp (the parent)
                    //
                    token.Target.Instance          = _xamlContext.ParentInstance;
                    token.Target.InstanceWasGotten = _xamlContext.ParentIsObjectFromMember;
                    token.Target.InstanceType      = _xamlContext.ParentType;
                    token.Target.Property          = _xamlContext.ParentProperty;
                }
            }
            else  // MarkupExtensions
            {
                token.FixupType = FixupType.MarkupExtensionRerun;

                token.Target.Instance          = _xamlContext.ParentInstance;
                token.Target.InstanceWasGotten = _xamlContext.ParentIsObjectFromMember;
                token.Target.InstanceType      = _xamlContext.ParentType;
                token.Target.Property          = _xamlContext.ParentProperty;
            }

            // We don't need to save a context stack for simple fixups (Assigned Directly).
            // This makes them ALOT cheaper.
            // [Simple fixups only need the namescope from the stack.]
            //
            if (token.CanAssignDirectly)
            {
                token.NameScopeDictionaryList.AddRange(_xamlContext.StackWalkOfNameScopes);
            }
            else
            {
                token.SavedContext = _xamlContext.GetSavedContext((token.FixupType == FixupType.MarkupExtensionRerun)
                                                                    ? SavedContextType.ReparseMarkupExtension
                                                                    : SavedContextType.ReparseValue);
            }

            return(token);
        }