LIBRARY = PresentationFramework.dll
LIB_MCS_FLAGS = -r:System.Xml.dll -r:WindowsBase.dll -r:System.dll
-NO_TEST = yes
+TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -r:TestVocab.dll -r:System.dll
+TEST_MONO_PATH = .
+
+Test/XamlParser.cs: Test/TestVocab.dll
+
+Test/TestVocab.dll: ../../tools/xamlc/demo/TestVocab/*.cs
+ echo $(MONO_PATH)
+ (cd ../../tools/xamlc/demo; make TestVocab.dll)
+ cp ../../tools/xamlc/demo/TestVocab.dll Test/TestVocab.dll
+ cp Test/TestVocab.dll TestVocab.dll
include ../../build/library.make
public CurrentType type;
}
+ private bool begun = false;
+
private ParserState currentState = null;
private ArrayList oldStates = new ArrayList();
- public XamlParser(string filename, XamlWriter writer)
+ public XamlParser(string filename, XamlWriter writer) : this(
+ new XmlTextReader(filename), writer)
{
- reader = new XmlTextReader(filename);
+ }
+
+ public XamlParser(TextReader reader, XamlWriter writer) : this(
+ new XmlTextReader(reader), writer)
+ {
+ }
+
+ public XamlParser(XmlReader reader, XamlWriter writer)
+ {
+ this.reader = reader;
this.writer = writer;
}
public void Parse()
{
while (reader.Read()) {
- if (currentState != null &&
- currentState.type == CurrentType.Code)
+ if (begun && currentState == null)
+ throw new Exception("Too far: " + reader.NodeType + ", " + reader.Name);
+ if (currentState != null && currentState.type == CurrentType.Code)
{
if (reader.NodeType == XmlNodeType.EndElement &&
reader.LocalName == "Code" &&
if (parent.GetInterface("System.Windows.Serialization.IAddChild") == null)
{} //TODO: throw exception
if (currentState == null) {
+ if (reader.GetAttribute("Name", XAML_NAMESPACE) != null)
+ throw new Exception("The XAML Name attribute can not be applied to top level elements\n"+
+ "Do you mean the Class attribute?");
+ begun = true;
createTopLevel(parent.AssemblyQualifiedName, reader.GetAttribute("Class", XAML_NAMESPACE));
} else {
string name = reader.GetAttribute("Name", XAML_NAMESPACE);
currentState = new ParserState();
currentState.type = CurrentType.Object;
currentState.obj = t;
- if (className == null) {
- className = "derived" + t.Name;
- }
writer.CreateTopLevel(t, className);
}
{
if (currentState.type == CurrentType.Code)
writer.CreateCode((string)currentState.obj);
- if (currentState.type == CurrentType.Object)
+ else if (currentState.type == CurrentType.Object)
writer.EndObject();
else if (currentState.type == CurrentType.Property)
writer.EndProperty();
else if (currentState.type == CurrentType.DependencyProperty)
writer.EndDependencyProperty();
-
pop();
}
int lastIndex = oldStates.Count - 1;
currentState = (ParserState)oldStates[lastIndex];
oldStates.RemoveAt(lastIndex);
-
}
}