private List <object> FindAmbientValues(XamlType[] types, bool stopAfterFirst) { ArrayHelper.ForAll <XamlType>(types, new Action <XamlType>(ObjectWriterContext.CheckAmbient)); List <object> list = new List <object>(); ObjectWriterFrame previousFrame = this._stack.PreviousFrame; ObjectWriterFrame currentFrame = this._stack.CurrentFrame; while (previousFrame.Depth >= 1) { foreach (XamlType type in types) { object instance = previousFrame.Instance; if (((previousFrame.XamlType != null) && previousFrame.XamlType.CanAssignTo(type)) && (instance != null)) { list.Add(instance); if (stopAfterFirst) { return(list); } } } previousFrame = (ObjectWriterFrame)previousFrame.Previous; } return(list); }
private INameScopeDictionary LookupNameScopeDictionary(ObjectWriterFrame frame) { if (frame.NameScopeDictionary == null) { if ((frame.XamlType != null) && frame.XamlType.IsNameScope) { frame.NameScopeDictionary = (frame.Instance as INameScopeDictionary) ?? new NameScopeDictionary(frame.Instance as INameScope); } if (frame.NameScopeDictionary == null) { if (frame.Depth == 1) { frame.NameScopeDictionary = this.HuntAroundForARootNameScope(frame); } else if (frame.Depth > 1) { if (((frame.Depth == (this.SavedDepth + 1)) && (this._settings != null)) && !this._settings.RegisterNamesOnExternalNamescope) { frame.NameScopeDictionary = new NameScope(); } else { ObjectWriterFrame previous = (ObjectWriterFrame)frame.Previous; frame.NameScopeDictionary = this.LookupNameScopeDictionary(previous); } } } } return(frame.NameScopeDictionary); }
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 XamlSavedContext GetSavedContext(SavedContextType savedContextType) { ObjectWriterFrame topFrame = this.GetTopFrame(); if (topFrame.NameScopeDictionary == null) { topFrame.NameScopeDictionary = this.LookupNameScopeDictionary(topFrame); } return(new XamlSavedContext(savedContextType, this, new XamlContextStack <ObjectWriterFrame>(this._stack, true))); }
public bool IsOnTheLiveStack(object instance) { for (ObjectWriterFrame frame = this._stack.CurrentFrame; frame.Depth > this.SavedDepth; frame = (ObjectWriterFrame)frame.Previous) { if (instance == frame.Instance) { return(true); } } return(false); }
public override string FindNamespaceByPrefix(string prefix) { for (ObjectWriterFrame frame = this._stack.CurrentFrame; frame.Depth > 0; frame = (ObjectWriterFrame)frame.Previous) { string str; if (frame.TryGetNamespaceByPrefix(prefix, out str)) { return(str); } } return(null); }
public override string FindNamespaceByPrefix(string prefix) { string xamlNs; ObjectWriterFrame frame = _stack.CurrentFrame; while (frame.Depth > 0) { if (frame.TryGetNamespaceByPrefix(prefix, out xamlNs)) { return(xamlNs); } frame = (ObjectWriterFrame)frame.Previous; } return(null); }
public XamlSavedContext GetSavedContext(SavedContextType savedContextType) { // Ensure that we have a root namescope before cloning the stack ObjectWriterFrame topFrame = GetTopFrame(); if (topFrame.NameScopeDictionary == null) { topFrame.NameScopeDictionary = LookupNameScopeDictionary(topFrame); } // Clone the stack var newStack = new XamlContextStack <ObjectWriterFrame>(_stack, true); XamlSavedContext savedContext = new XamlSavedContext(savedContextType, this, newStack); return(savedContext); }
internal XamlType GetDestinationType() { ObjectWriterFrame currentFrame = this._stack.CurrentFrame; if (currentFrame == null) { return(null); } if ((currentFrame.Instance != null) && (currentFrame.XamlType == null)) { currentFrame = currentFrame.Previous as ObjectWriterFrame; } if (currentFrame.Member == XamlLanguage.Initialization) { return(currentFrame.XamlType); } return(currentFrame.Member.Type); }
public ObjectWriterFrame(ObjectWriterFrame source) : base(source) { if (source._preconstructionPropertyValues != null) { this._preconstructionPropertyValues = new Dictionary<XamlMember, object>(source.PreconstructionPropertyValues); } if (source._assignedProperties != null) { this._assignedProperties = new HashSet<XamlMember>(source.AssignedProperties); } this._key = source._key; this._flags = source._flags; this.Instance = source.Instance; this.Collection = source.Collection; this.NameScopeDictionary = source.NameScopeDictionary; this.PositionalCtorArgs = source.PositionalCtorArgs; this.InstanceRegisteredName = source.InstanceRegisteredName; }
public ObjectWriterFrame(ObjectWriterFrame source) : base(source) { if (source._preconstructionPropertyValues != null) { this._preconstructionPropertyValues = new Dictionary <XamlMember, object>(source.PreconstructionPropertyValues); } if (source._assignedProperties != null) { this._assignedProperties = new HashSet <XamlMember>(source.AssignedProperties); } this._key = source._key; this._flags = source._flags; this.Instance = source.Instance; this.Collection = source.Collection; this.NameScopeDictionary = source.NameScopeDictionary; this.PositionalCtorArgs = source.PositionalCtorArgs; this.InstanceRegisteredName = source.InstanceRegisteredName; }
public override IEnumerable <NamespaceDeclaration> GetNamespacePrefixes() { ObjectWriterFrame frame = _stack.CurrentFrame; HashSet <string> keys = new HashSet <string>(); while (frame.Depth > 0) { if (frame._namespaces != null) { foreach (NamespaceDeclaration namespaceDeclaration in frame.GetNamespacePrefixes()) { if (keys.Add(namespaceDeclaration.Prefix)) { yield return(namespaceDeclaration); } } } frame = (ObjectWriterFrame)frame.Previous; } }
public override IEnumerable <NamespaceDeclaration> GetNamespacePrefixes() { ObjectWriterFrame frame = _stack.CurrentFrame; Dictionary <string, string> keys = new Dictionary <string, string>(); while (frame.Depth > 0) { if (frame._namespaces != null) { foreach (NamespaceDeclaration namespaceDeclaration in frame.GetNamespacePrefixes()) { if (!keys.ContainsKey(namespaceDeclaration.Prefix)) { keys.Add(namespaceDeclaration.Prefix, null); yield return(namespaceDeclaration); } } } frame = (ObjectWriterFrame)frame.Previous; } }
private List <object> FindAmbientValues(XamlType[] types, bool stopAfterFirst) { foreach (XamlType xamlType in types) { if (!xamlType.IsAmbient) { throw new ArgumentException(SR.Get(SRID.NotAmbientType, xamlType.Name), nameof(types)); } } List <object> retList = new List <object>(); // Start the search for ambient properties with the parent frame. ObjectWriterFrame frame = _stack.PreviousFrame; while (frame.Depth >= 1) { foreach (XamlType type in types) { object inst = frame.Instance; if (frame.XamlType != null && frame.XamlType.CanAssignTo(type)) { if (inst != null) { retList.Add(inst); if (stopAfterFirst) { return(retList); } } } } frame = (ObjectWriterFrame)frame.Previous; Debug.Assert(frame != null); } return(retList); }
internal XamlType GetDestinationType() { ObjectWriterFrame frame = _stack.CurrentFrame; if (frame == null) { return(null); } if (frame.Instance != null && frame.XamlType == null) { // // Text/TypeConverter, we need to go up a frame frame = frame.Previous as ObjectWriterFrame; } if (frame.Member == XamlLanguage.Initialization) { return(frame.XamlType); } return(frame.Member.Type); }
public ObjectWriterFrame(ObjectWriterFrame source) : base(source) { // Calling the getter will instantiate new Dictionaries. // So we just check the field instead to verify that it isn't // being used. if (source._preconstructionPropertyValues != null) { _preconstructionPropertyValues = new Dictionary <XamlMember, object>(source.PreconstructionPropertyValues); } if (source._assignedProperties != null) { _assignedProperties = new HashSet <XamlMember>(source.AssignedProperties); } _key = source._key; _flags = source._flags; Instance = source.Instance; Collection = source.Collection; NameScopeDictionary = source.NameScopeDictionary; PositionalCtorArgs = source.PositionalCtorArgs; InstanceRegisteredName = source.InstanceRegisteredName; }
public override IEnumerable <NamespaceDeclaration> GetNamespacePrefixes() { ObjectWriterFrame currentFrame = this._stack.CurrentFrame; Dictionary <string, string> iteratorVariable1 = new Dictionary <string, string>(); while (currentFrame.Depth > 0) { if (currentFrame._namespaces != null) { foreach (NamespaceDeclaration iteratorVariable2 in currentFrame.GetNamespacePrefixes()) { if (iteratorVariable1.ContainsKey(iteratorVariable2.Prefix)) { continue; } iteratorVariable1.Add(iteratorVariable2.Prefix, null); yield return(iteratorVariable2); } } currentFrame = (ObjectWriterFrame)currentFrame.Previous; } }
private XAML3.INameScopeDictionary LookupNameScopeDictionary(ObjectWriterFrame frame) { if (frame.NameScopeDictionary == null) { if (frame.XamlType != null && frame.XamlType.IsNameScope) { frame.NameScopeDictionary = frame.Instance as XAML3.INameScopeDictionary ?? new NameScopeDictionary(frame.Instance as XAML3.INameScope); } if (frame.NameScopeDictionary == null) { if (frame.Depth == 1) { frame.NameScopeDictionary = HuntAroundForARootNameScope(frame); } else if (frame.Depth > 1) { if (frame.Depth == SavedDepth + 1 && _settings != null && !_settings.RegisterNamesOnExternalNamescope) { #if TARGETTING35SP1 frame.NameScopeDictionary = new NameScopeDictionary(new NameScope()); #else frame.NameScopeDictionary = new NameScope(); #endif } else { var parentFrame = (ObjectWriterFrame)frame.Previous; frame.NameScopeDictionary = LookupNameScopeDictionary(parentFrame); } } } } // We are sure to find a name scope at the root (at least). Debug.Assert(frame.NameScopeDictionary != null || frame.Depth == 0); return(frame.NameScopeDictionary); }
private List <object> FindAmbientValues(XamlType[] types, bool stopAfterFirst) { ArrayHelper.ForAll <XamlType>(types, CheckAmbient); List <object> retList = new List <object>(); // Start the search for ambient properties with the parent frame. ObjectWriterFrame frame = _stack.PreviousFrame; ObjectWriterFrame lowerFrame = _stack.CurrentFrame; while (frame.Depth >= 1) { foreach (XamlType type in types) { object inst = frame.Instance; if (frame.XamlType != null && frame.XamlType.CanAssignTo(type)) { if (inst != null) { retList.Add(inst); if (stopAfterFirst) { return(retList); } } } } lowerFrame = frame; frame = (ObjectWriterFrame)frame.Previous; Debug.Assert(frame != null); } return(retList); }
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); }
private List <AmbientPropertyValue> FindAmbientValues(IEnumerable <XamlType> ceilingTypesEnumerable, bool searchLiveStackOnly, IEnumerable <XamlType> types, XamlMember[] properties, bool stopAfterFirst) { ArrayHelper.ForAll <XamlMember>(properties, CheckAmbient); List <XamlType> ceilingTypes = ArrayHelper.ToList <XamlType>(ceilingTypesEnumerable); List <AmbientPropertyValue> retList = new List <AmbientPropertyValue>(); // Start the search for ambient properties and types starting with the parent frame. ObjectWriterFrame frame = _stack.PreviousFrame; ObjectWriterFrame lowerFrame = _stack.CurrentFrame; while (frame.Depth >= 1) { if (searchLiveStackOnly && frame.Depth <= SavedDepth) { break; } object inst = frame.Instance; if (types != null) { foreach (XamlType type in types) { if (frame.XamlType != null && frame.XamlType.CanAssignTo(type)) { if (inst != null) { AmbientPropertyValue apValue = new AmbientPropertyValue(null, inst); retList.Add(apValue); } } } } if (properties != null) { foreach (XamlMember prop in properties) { bool returnAmbientValue = false; object value = null; if (frame.XamlType != null && frame.XamlType.CanAssignTo(prop.DeclaringType)) { if (inst != null) { // If we are searching from inside the target Ambient property, // (like StaticResource inside a ResourceDictionary) // and the object is bottom-up, then it won't be assigned to // the object but will only exist on the parse stack. // If it is top-down it will be attached to the instance already // and the normal path will serve. if (prop == frame.Member && lowerFrame.Instance != null && lowerFrame.XamlType != null && !lowerFrame.XamlType.IsUsableDuringInitialization) { // One last thing to check: If the object we are inside is a ME // then we are inside a call to ProvideValue and we don't want to // return a reference to ourselves to ourselves. if (!(lowerFrame.Instance is XAML3.MarkupExtension)) { returnAmbientValue = true; value = lowerFrame.Instance; } } else { // The Ambient Property is either Fully build or not set. // FIRST: Ask the object (via IQueryAmbient interface) if it has a value for this property. // This is usefull to prevent needless creation of empty lazy properties. var ambientCtrl = inst as XAML3.IQueryAmbient; // If there is no ambientControl or if ambientControl says YES, then get the property value. if (ambientCtrl == null || ambientCtrl.IsAmbientPropertyAvailable(prop.Name)) { returnAmbientValue = true; value = _runtime.GetValue(inst, prop); } } } if (returnAmbientValue) { AmbientPropertyValue apValue = new AmbientPropertyValue(prop, value); retList.Add(apValue); } } } } if (stopAfterFirst && retList.Count > 0) { break; } if (ceilingTypes != null) { if (ceilingTypes.Contains(frame.XamlType)) { break; } } lowerFrame = frame; frame = (ObjectWriterFrame)frame.Previous; Debug.Assert(frame != null); } return(retList); }
private List <AmbientPropertyValue> FindAmbientValues(IEnumerable <XamlType> ceilingTypesEnumerable, bool searchLiveStackOnly, IEnumerable <XamlType> types, XamlMember[] properties, bool stopAfterFirst) { ArrayHelper.ForAll <XamlMember>(properties, new Action <XamlMember>(ObjectWriterContext.CheckAmbient)); List <XamlType> list = ArrayHelper.ToList <XamlType>(ceilingTypesEnumerable); List <AmbientPropertyValue> list2 = new List <AmbientPropertyValue>(); ObjectWriterFrame previousFrame = this._stack.PreviousFrame; ObjectWriterFrame currentFrame = this._stack.CurrentFrame; while (previousFrame.Depth >= 1) { if (searchLiveStackOnly && (previousFrame.Depth <= this.SavedDepth)) { return(list2); } object instance = previousFrame.Instance; if (types != null) { foreach (XamlType type in types) { if (((previousFrame.XamlType != null) && previousFrame.XamlType.CanAssignTo(type)) && (instance != null)) { AmbientPropertyValue item = new AmbientPropertyValue(null, instance); list2.Add(item); } } } if (properties != null) { foreach (XamlMember member in properties) { bool flag = false; object obj3 = null; if ((previousFrame.XamlType != null) && previousFrame.XamlType.CanAssignTo(member.DeclaringType)) { if (instance != null) { if (((member == previousFrame.Member) && (currentFrame.Instance != null)) && ((currentFrame.XamlType != null) && !currentFrame.XamlType.IsUsableDuringInitialization)) { if (!typeof(MarkupExtension).IsAssignableFrom(currentFrame.Instance.GetType())) { flag = true; obj3 = currentFrame.Instance; } } else { IQueryAmbient ambient = instance as IQueryAmbient; if ((ambient == null) || ambient.IsAmbientPropertyAvailable(member.Name)) { flag = true; obj3 = this._runtime.GetValue(instance, member); } } } if (flag) { AmbientPropertyValue value3 = new AmbientPropertyValue(member, obj3); list2.Add(value3); } } } } if (stopAfterFirst && (list2.Count > 0)) { return(list2); } if ((list != null) && list.Contains(previousFrame.XamlType)) { return(list2); } currentFrame = previousFrame; previousFrame = (ObjectWriterFrame)previousFrame.Previous; } return(list2); }