public ObjectWriterContext(XamlSchemaContext schemaContext, XamlObjectWriterSettings settings, XAML3.INameScope rootNameScope, XamlRuntime runtime) : base(schemaContext) { _stack = new XamlContextStack <ObjectWriterFrame>(() => new ObjectWriterFrame()); XAML3.INameScopeDictionary rootNameScopeDictionary = null; if (rootNameScope == null) { #if TARGETTING35SP1 rootNameScopeDictionary = new NameScopeDictionary(new NameScope()); #else rootNameScopeDictionary = new NameScope(); #endif } else { rootNameScopeDictionary = rootNameScope as XAML3.INameScopeDictionary; if (rootNameScopeDictionary == null) { rootNameScopeDictionary = new NameScopeDictionary(rootNameScope); } } _stack.CurrentFrame.NameScopeDictionary = rootNameScopeDictionary; _stack.PushScope(); // put a blank sentinal frame on the stack. if (settings != null) { _settings = settings.StripDelegates(); } _runtime = runtime; _savedDepth = 0; }
public ObjectWriterContext(XamlSchemaContext schemaContext, XamlObjectWriterSettings settings, INameScope rootNameScope, XamlRuntime runtime) : base(schemaContext) { this._stack = new XamlContextStack <ObjectWriterFrame>(() => new ObjectWriterFrame()); INameScopeDictionary dictionary = null; if (rootNameScope == null) { dictionary = new NameScope(); } else { dictionary = rootNameScope as INameScopeDictionary; if (dictionary == null) { dictionary = new NameScopeDictionary(rootNameScope); } } this._stack.CurrentFrame.NameScopeDictionary = dictionary; this._stack.PushScope(); if (settings != null) { this._settings = settings.StripDelegates(); } this._runtime = runtime; this._savedDepth = 0; }
private INameScopeDictionary HuntAroundForARootNameScope(ObjectWriterFrame rootFrame) { object instance = rootFrame.Instance; if ((instance == null) && rootFrame.XamlType.IsNameScope) { throw new InvalidOperationException(System.Xaml.SR.Get("NameScopeOnRootInstance")); } INameScopeDictionary nameScopeDictionary = null; nameScopeDictionary = instance as INameScopeDictionary; if (nameScopeDictionary == null) { INameScope underlyingNameScope = instance as INameScope; if (underlyingNameScope != null) { nameScopeDictionary = new NameScopeDictionary(underlyingNameScope); } } if (nameScopeDictionary == null) { XamlType xamlType = rootFrame.XamlType; if (xamlType.UnderlyingType != null) { XamlMember nameScopeProperty = TypeReflector.LookupNameScopeProperty(xamlType); if (nameScopeProperty != null) { INameScope scope2 = (INameScope)this._runtime.GetValue(instance, nameScopeProperty, false); if (scope2 == null) { nameScopeDictionary = new NameScope(); this._runtime.SetValue(instance, nameScopeProperty, nameScopeDictionary); } else { nameScopeDictionary = scope2 as INameScopeDictionary; if (nameScopeDictionary == null) { nameScopeDictionary = new NameScopeDictionary(scope2); } } } } } if (((nameScopeDictionary == null) && (this._settings != null)) && this._settings.RegisterNamesOnExternalNamescope) { ObjectWriterFrame previous = (ObjectWriterFrame)rootFrame.Previous; nameScopeDictionary = previous.NameScopeDictionary; } if (nameScopeDictionary == null) { nameScopeDictionary = new NameScope(); } rootFrame.NameScopeDictionary = nameScopeDictionary; return(nameScopeDictionary); }
public ObjectWriterContext(XamlSavedContext savedContext, XamlObjectWriterSettings settings, XAML3.INameScope rootNameScope, XamlRuntime runtime) : base(savedContext.SchemaContext) { _stack = new XamlContextStack <ObjectWriterFrame>(savedContext.Stack, false); if (settings != null) { _settings = settings.StripDelegates(); } _runtime = runtime; BaseUri = savedContext.BaseUri; // If the bottom of the stack is a (no XamlType) Value (reparse) then back-up onto it. // Otherwise add a blank frame to isolate template use from the saved context. switch (savedContext.SaveContextType) { case SavedContextType.Template: // Templates always need a root namescope, to isolate them from the rest of the doc XAML3.INameScopeDictionary rootNameScopeDictionary = null; if (rootNameScope == null) { #if TARGETTING35SP1 rootNameScopeDictionary = new NameScopeDictionary(new NameScope()); #else rootNameScopeDictionary = new NameScope(); #endif } else { rootNameScopeDictionary = rootNameScope as XAML3.INameScopeDictionary; if (rootNameScopeDictionary == null) { rootNameScopeDictionary = new NameScopeDictionary(rootNameScope); } } // Push an extra frame to ensure that the template NameScope is // not part of the saved context. Otherwise, the namescope // will hold things alive as long as the template is alive _stack.PushScope(); _savedDepth = _stack.Depth; _stack.CurrentFrame.NameScopeDictionary = rootNameScopeDictionary; _stack.PushScope(); break; case SavedContextType.ReparseValue: case SavedContextType.ReparseMarkupExtension: Debug.Assert(rootNameScope == null, "Cannot pass a new namescope in to a reparse context"); _savedDepth = _stack.Depth - 1; break; } }
public ObjectWriterContext(XamlSavedContext savedContext, XamlObjectWriterSettings settings, INameScope rootNameScope, XamlRuntime runtime) : base(savedContext.SchemaContext) { INameScopeDictionary dictionary; this._stack = new XamlContextStack <ObjectWriterFrame>(savedContext.Stack, false); if (settings != null) { this._settings = settings.StripDelegates(); } this._runtime = runtime; this.BaseUri = savedContext.BaseUri; switch (savedContext.SaveContextType) { case SavedContextType.Template: dictionary = null; if (rootNameScope != null) { dictionary = rootNameScope as INameScopeDictionary; if (dictionary == null) { dictionary = new NameScopeDictionary(rootNameScope); } break; } dictionary = new NameScope(); break; case SavedContextType.ReparseValue: case SavedContextType.ReparseMarkupExtension: this._savedDepth = this._stack.Depth - 1; return; default: return; } this._stack.PushScope(); this._savedDepth = this._stack.Depth; this._stack.CurrentFrame.NameScopeDictionary = dictionary; this._stack.PushScope(); }
private XAML3.INameScopeDictionary HuntAroundForARootNameScope(ObjectWriterFrame rootFrame) { Debug.Assert(rootFrame.Depth == 1); object inst = rootFrame.Instance; if (inst == null && rootFrame.XamlType.IsNameScope) { throw new InvalidOperationException(SR.Get(SRID.NameScopeOnRootInstance)); } XAML3.INameScopeDictionary nameScopeDictionary = null; nameScopeDictionary = inst as XAML3.INameScopeDictionary; if (nameScopeDictionary == null) { XAML3.INameScope nameScope = inst as XAML3.INameScope; if (nameScope != null) { nameScopeDictionary = new NameScopeDictionary(nameScope); } } // If the root instance isn't a name scope // then perhaps it designated a property as the name scope. if (nameScopeDictionary == null) { XamlType xamlType = rootFrame.XamlType; if (xamlType.UnderlyingType != null) { // Get the Name Scope Property (from attribute on the class) XamlMember nameScopeProperty = TypeReflector.LookupNameScopeProperty(xamlType); if (nameScopeProperty != null) { // Read the value of the property. If it is an object we are good. // if it is null create a stock name scope dictionary object and assign it back. XAML3.INameScope nameScope = (XAML3.INameScope)_runtime.GetValue(inst, nameScopeProperty, false); if (nameScope == null) { #if TARGETTING35SP1 nameScopeDictionary = new NameScopeDictionary(new NameScope()); #else nameScopeDictionary = new NameScope(); #endif _runtime.SetValue(inst, nameScopeProperty, nameScopeDictionary); } else { nameScopeDictionary = nameScope as XAML3.INameScopeDictionary; if (nameScopeDictionary == null) { nameScopeDictionary = new NameScopeDictionary(nameScope); } } } } } if (nameScopeDictionary == null && _settings != null && _settings.RegisterNamesOnExternalNamescope) { ObjectWriterFrame frameZero = (ObjectWriterFrame)rootFrame.Previous; nameScopeDictionary = frameZero.NameScopeDictionary; } // Otherwise we still need a namescope at the root of the parse // for our own usage. For IXamlNameResolver() to use. if (nameScopeDictionary == null) { #if TARGETTING35SP1 nameScopeDictionary = new NameScopeDictionary(new NameScope()); #else nameScopeDictionary = new NameScope(); #endif } rootFrame.NameScopeDictionary = nameScopeDictionary; return(nameScopeDictionary); }