private void Analyze(XamlXmlReader reader) { Stack <XamlType> objectTypes = new Stack <XamlType>(); Stack <MemberType> nameStack = new Stack <MemberType>(); Stack <XamlMember> eventStack = new Stack <XamlMember>(); while (reader.Read()) { switch (reader.NodeType) { case XamlNodeType.StartObject: objectTypes.Push(reader.Type); break; case XamlNodeType.EndObject: if (objectTypes.Count > 0) { objectTypes.Pop(); } break; case XamlNodeType.NamespaceDeclaration: break; case XamlNodeType.StartMember: var property = reader.Member; if (property.Name == "Name" && property.Type.UnderlyingType == typeof(string)) { nameStack.Push(MemberType.XName); } else if (property.IsEvent) { nameStack.Push(MemberType.Event); eventStack.Push(property); } else { nameStack.Push(MemberType.Unknown); } break; case XamlNodeType.EndMember: if (nameStack.Pop() == MemberType.Event) { eventStack.Pop(); } break; case XamlNodeType.GetObject: case XamlNodeType.Value: object value = reader.Value; if (value is string) { switch (nameStack.Peek()) { case MemberType.XName: // we are writing a x:Name, save it so we can later get the name from the scope _knownTypes[(string)value] = new XamlTypeReference(objectTypes.Peek(), reader.LineNumber, reader.LinePosition); break; case MemberType.Event: // we have an event handler, save the method name and the XamlMember for the event _eventInfo[(string)value] = new XamlMemberReference(eventStack.Peek(), reader.LineNumber, reader.LinePosition); break; } } break; } } }
private void Analyze(XamlXmlReader reader) { Stack<XamlType> objectTypes = new Stack<XamlType>(); Stack<MemberType> nameStack = new Stack<MemberType>(); Stack<XamlMember> eventStack = new Stack<XamlMember>(); while (reader.Read()) { switch (reader.NodeType) { case XamlNodeType.StartObject: objectTypes.Push(reader.Type); break; case XamlNodeType.EndObject: if (objectTypes.Count > 0) { objectTypes.Pop(); } break; case XamlNodeType.NamespaceDeclaration: break; case XamlNodeType.StartMember: var property = reader.Member; if (property.Name == "Name" && property.Type.UnderlyingType == typeof(string)) { nameStack.Push(MemberType.XName); } else if (property.IsEvent) { nameStack.Push(MemberType.Event); eventStack.Push(property); } else { nameStack.Push(MemberType.Unknown); } break; case XamlNodeType.EndMember: if (nameStack.Pop() == MemberType.Event) { eventStack.Pop(); } break; case XamlNodeType.GetObject: case XamlNodeType.Value: object value = reader.Value; if (value is string) { switch (nameStack.Peek()) { case MemberType.XName: // we are writing a x:Name, save it so we can later get the name from the scope _knownTypes[(string)value] = new XamlTypeReference(objectTypes.Peek(), reader.LineNumber, reader.LinePosition); break; case MemberType.Event: // we have an event handler, save the method name and the XamlMember for the event _eventInfo[(string)value] = new XamlMemberReference(eventStack.Peek(), reader.LineNumber, reader.LinePosition); break; } } break; } } }