|
|
@ -53,7 +53,7 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public static XamlDocument Parse(Stream stream, XamlParserSettings settings) |
|
|
|
public static XamlDocument Parse(Stream stream, XamlParserSettings settings) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (stream == null) |
|
|
|
if (stream == null) |
|
|
|
throw new ArgumentNullException("stream"); |
|
|
|
throw new ArgumentNullException("stream"); |
|
|
|
return Parse(XmlReader.Create(stream), settings); |
|
|
|
return Parse(XmlReader.Create(stream), settings); |
|
|
|
} |
|
|
|
} |
|
|
@ -63,7 +63,7 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public static XamlDocument Parse(TextReader reader, XamlParserSettings settings) |
|
|
|
public static XamlDocument Parse(TextReader reader, XamlParserSettings settings) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (reader == null) |
|
|
|
if (reader == null) |
|
|
|
throw new ArgumentNullException("reader"); |
|
|
|
throw new ArgumentNullException("reader"); |
|
|
|
return Parse(XmlReader.Create(reader), settings); |
|
|
|
return Parse(XmlReader.Create(reader), settings); |
|
|
|
} |
|
|
|
} |
|
|
@ -80,11 +80,11 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
var errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink)); |
|
|
|
var errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink)); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
doc.Load(reader); |
|
|
|
doc.Load(reader); |
|
|
|
return Parse(doc, settings); |
|
|
|
return Parse(doc, settings); |
|
|
|
} catch (XmlException x) { |
|
|
|
} catch (XmlException x) { |
|
|
|
if (errorSink != null) |
|
|
|
if (errorSink != null) |
|
|
|
errorSink.ReportError(x.Message, x.LineNumber, x.LinePosition); |
|
|
|
errorSink.ReportError(x.Message, x.LineNumber, x.LinePosition); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
@ -93,6 +93,8 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a XAML document from an existing XmlDocument.
|
|
|
|
/// Creates a XAML document from an existing XmlDocument.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", |
|
|
|
|
|
|
|
Justification="We need to continue parsing, and the error is reported to the user.")] |
|
|
|
internal static XamlDocument Parse(XmlDocument document, XamlParserSettings settings) |
|
|
|
internal static XamlDocument Parse(XmlDocument document, XamlParserSettings settings) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (settings == null) |
|
|
|
if (settings == null) |
|
|
@ -104,7 +106,7 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
p.errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink)); |
|
|
|
p.errorSink = (IXamlErrorSink)settings.ServiceProvider.GetService(typeof(IXamlErrorSink)); |
|
|
|
p.document = new XamlDocument(document, settings); |
|
|
|
p.document = new XamlDocument(document, settings); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
var root = p.ParseObject(document.DocumentElement); |
|
|
|
var root = p.ParseObject(document.DocumentElement); |
|
|
|
p.document.ParseComplete(root); |
|
|
|
p.document.ParseComplete(root); |
|
|
|
} catch (Exception x) { |
|
|
|
} catch (Exception x) { |
|
|
@ -121,11 +123,6 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
XamlParserSettings settings; |
|
|
|
XamlParserSettings settings; |
|
|
|
IXamlErrorSink errorSink; |
|
|
|
IXamlErrorSink errorSink; |
|
|
|
|
|
|
|
|
|
|
|
Type FindType(string namespaceUri, string localName) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return FindType(settings.TypeFinder, namespaceUri, localName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Type FindType(XamlTypeFinder typeFinder, string namespaceUri, string localName) |
|
|
|
static Type FindType(XamlTypeFinder typeFinder, string namespaceUri, string localName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Type elementType = typeFinder.GetType(namespaceUri, localName); |
|
|
|
Type elementType = typeFinder.GetType(namespaceUri, localName); |
|
|
@ -159,6 +156,7 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
currentXamlObject.HasErrors = true; |
|
|
|
currentXamlObject.HasErrors = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: what when there's no error sink? I think we should throw exception
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
XamlObject ParseObject(XmlElement element) |
|
|
|
XamlObject ParseObject(XmlElement element) |
|
|
@ -214,8 +212,8 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
currentXamlObject = obj; |
|
|
|
currentXamlObject = obj; |
|
|
|
obj.ParentObject = parentXamlObject; |
|
|
|
obj.ParentObject = parentXamlObject; |
|
|
|
|
|
|
|
|
|
|
|
if (parentXamlObject == null && obj.DependencyObject != null) { |
|
|
|
if (parentXamlObject == null && obj.Instance is DependencyObject) { |
|
|
|
NameScope.SetNameScope(obj.DependencyObject, new NameScope()); |
|
|
|
NameScope.SetNameScope((DependencyObject)obj.Instance, new NameScope()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ISupportInitialize iSupportInitializeInstance = instance as ISupportInitialize; |
|
|
|
ISupportInitialize iSupportInitializeInstance = instance as ISupportInitialize; |
|
|
@ -348,6 +346,8 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", |
|
|
|
|
|
|
|
Justification="We need to continue parsing, and the error is reported to the user.")] |
|
|
|
XamlPropertyValue ParseValue(XmlNode childNode) |
|
|
|
XamlPropertyValue ParseValue(XmlNode childNode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
try { |
|
|
|
try { |
|
|
@ -466,13 +466,15 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
propertyName = qualifiedName.Substring(pos + 1); |
|
|
|
propertyName = qualifiedName.Substring(pos + 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", |
|
|
|
|
|
|
|
Justification="We need to continue parsing, and the error is reported to the user.")] |
|
|
|
void ParseObjectAttribute(XamlObject obj, XmlAttribute attribute) |
|
|
|
void ParseObjectAttribute(XamlObject obj, XmlAttribute attribute) |
|
|
|
{ |
|
|
|
{ |
|
|
|
try { |
|
|
|
try { |
|
|
|
ParseObjectAttribute(obj, attribute, true); |
|
|
|
ParseObjectAttribute(obj, attribute, true); |
|
|
|
} catch (Exception x) { |
|
|
|
} catch (Exception x) { |
|
|
|
ReportException(x, attribute); |
|
|
|
ReportException(x, attribute); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
internal static void ParseObjectAttribute(XamlObject obj, XmlAttribute attribute, bool real) |
|
|
|
internal static void ParseObjectAttribute(XamlObject obj, XmlAttribute attribute, bool real) |
|
|
@ -481,18 +483,18 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
XamlPropertyValue value = null; |
|
|
|
XamlPropertyValue value = null; |
|
|
|
|
|
|
|
|
|
|
|
var valueText = attribute.Value; |
|
|
|
var valueText = attribute.Value; |
|
|
|
if (valueText.StartsWith("{") && !valueText.StartsWith("{}")) { |
|
|
|
if (valueText.StartsWith("{", StringComparison.Ordinal) && !valueText.StartsWith("{}", StringComparison.Ordinal)) { |
|
|
|
var xamlObject = MarkupExtensionParser.Parse(valueText, obj, real ? attribute : null); |
|
|
|
var xamlObject = MarkupExtensionParser.Parse(valueText, obj, real ? attribute : null); |
|
|
|
value = xamlObject; |
|
|
|
value = xamlObject; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (real) |
|
|
|
if (real) |
|
|
|
value = new XamlTextValue(obj.OwnerDocument, attribute); |
|
|
|
value = new XamlTextValue(obj.OwnerDocument, attribute); |
|
|
|
else |
|
|
|
else |
|
|
|
value = new XamlTextValue(obj.OwnerDocument, valueText); |
|
|
|
value = new XamlTextValue(obj.OwnerDocument, valueText); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var property = new XamlProperty(obj, propertyInfo, value); |
|
|
|
var property = new XamlProperty(obj, propertyInfo, value); |
|
|
|
obj.AddProperty(property); |
|
|
|
obj.AddProperty(property); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static bool ObjectChildElementIsPropertyElement(XmlElement element) |
|
|
|
static bool ObjectChildElementIsPropertyElement(XmlElement element) |
|
|
@ -562,8 +564,8 @@ namespace ICSharpCode.WpfDesign.XamlDom |
|
|
|
|
|
|
|
|
|
|
|
internal static object CreateObjectFromAttributeText(string valueText, Type targetType, XamlObject scope) |
|
|
|
internal static object CreateObjectFromAttributeText(string valueText, Type targetType, XamlObject scope) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var converter = |
|
|
|
var converter = |
|
|
|
XamlNormalPropertyInfo.GetCustomTypeConverter(targetType) ?? |
|
|
|
XamlNormalPropertyInfo.GetCustomTypeConverter(targetType) ?? |
|
|
|
TypeDescriptor.GetConverter(targetType); |
|
|
|
TypeDescriptor.GetConverter(targetType); |
|
|
|
|
|
|
|
|
|
|
|
return converter.ConvertFromInvariantString( |
|
|
|
return converter.ConvertFromInvariantString( |
|
|
|