@ -80,6 +80,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -80,6 +80,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
throw new ArgumentNullException ( "reader" ) ;
return Parse ( XmlReader . Create ( reader ) , settings ) ;
}
private XmlNode currentParsedNode ;
/// <summary>
/// Parses a XAML document using an XmlReader.
@ -128,7 +130,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -128,7 +130,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
var root = p . ParseObject ( document . DocumentElement ) ;
p . document . ParseComplete ( root ) ;
} catch ( Exception x ) {
p . ReportException ( x , document . DocumentElement ) ;
p . ReportException ( x , p . currentParsedNode ) ;
}
return p . document ;
@ -220,12 +222,15 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -220,12 +222,15 @@ namespace ICSharpCode.WpfDesign.XamlDom
if ( onlyTextNodes & & numberOfTextNodes = = 1 ) {
foreach ( XmlNode childNode in element . ChildNodes ) {
if ( childNode . NodeType = = XmlNodeType . Text ) {
currentParsedNode = childNode ;
initializeFromTextValueInsteadOfConstructor = ( XamlTextValue ) ParseValue ( childNode ) ;
}
}
}
}
currentParsedNode = element ;
object instance ;
if ( initializeFromTextValueInsteadOfConstructor ! = null ) {
instance = TypeDescriptor . GetConverter ( elementType ) . ConvertFromString (
@ -284,9 +289,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -284,9 +289,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
ParseObjectAttribute ( obj , attribute ) ;
}
if ( ! ( obj . Instance is Style ) ) {
ParseObjectContent ( obj , element , defaultProperty , initializeFromTextValueInsteadOfConstructor ) ;
}
ParseObjectContent ( obj , element , defaultProperty , initializeFromTextValueInsteadOfConstructor ) ;
if ( iSupportInitializeInstance ! = null ) {
iSupportInitializeInstance . EndInit ( ) ;
@ -318,6 +321,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -318,6 +321,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
collectionPropertyElement = element ;
} else if ( defaultProperty ! = null & & defaultProperty . IsCollection & & ! element . IsEmpty ) {
foreach ( XmlNode childNode in elementChildNodes ) {
currentParsedNode = childNode ;
XmlElement childElement = childNode as XmlElement ;
if ( childElement = = null | | ! ObjectChildElementIsPropertyElement ( childElement ) ) {
obj . AddProperty ( collectionProperty = new XamlProperty ( obj , defaultProperty ) ) ;
@ -328,6 +332,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -328,6 +332,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
currentParsedNode = element ;
if ( collectionType ! = null & & collectionInstance = = null & & elementChildNodes . Count ( ) = = 1 )
{
var firstChild = elementChildNodes . First ( ) as XmlElement ;
@ -344,6 +350,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -344,6 +350,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
else
{
foreach ( XmlNode childNode in elementChildNodes ) {
currentParsedNode = childNode ;
XmlElement childElement = childNode as XmlElement ;
if ( childElement ! = null ) {
if ( childElement . NamespaceURI = = XamlConstants . XamlNamespace )
@ -374,6 +381,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -374,6 +381,8 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
}
currentParsedNode = element ;
}
IEnumerable < XmlNode > GetNormalizedChildNodes ( XmlElement element )
@ -412,10 +421,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -412,10 +421,12 @@ namespace ICSharpCode.WpfDesign.XamlDom
Justification = "We need to continue parsing, and the error is reported to the user." ) ]
XamlPropertyValue ParseValue ( XmlNode childNode )
{
currentParsedNode = childNode ;
try {
return ParseValueCore ( childNode ) ;
return ParseValueCore ( currentParse dNode ) ;
} catch ( Exception x ) {
ReportException ( x , chil dNode ) ;
ReportException ( x , currentParse dNode ) ;
}
return null ;
}
@ -457,13 +468,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -457,13 +468,11 @@ namespace ICSharpCode.WpfDesign.XamlDom
internal static XamlPropertyInfo FindProperty ( object elementInstance , Type propertyType , string propertyName )
{
PropertyDescriptorCollection properties ;
if ( elementInstance ! = null ) {
properties = TypeDescriptor . GetProperties ( elementInstance ) ;
} else {
properties = TypeDescriptor . GetProperties ( propertyType ) ;
}
PropertyDescriptor propertyInfo = properties [ propertyName ] ;
PropertyDescriptor propertyInfo = TypeDescriptor . GetProperties ( propertyType ) [ propertyName ] ;
if ( propertyInfo = = null & & elementInstance ! = null )
propertyInfo = TypeDescriptor . GetProperties ( elementInstance ) . OfType < DependencyPropertyDescriptor > ( ) . FirstOrDefault ( x = > x . IsAttached & & x . Name = = propertyName ) ;
if ( propertyInfo ! = null ) {
return new XamlNormalPropertyInfo ( propertyInfo ) ;
} else {
@ -649,6 +658,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -649,6 +658,7 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
foreach ( XmlNode childNode in element . ChildNodes ) {
currentParsedNode = childNode ;
XamlPropertyValue childValue = ParseValue ( childNode ) ;
if ( childValue ! = null ) {
if ( propertyInfo . IsCollection ) {
@ -669,7 +679,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
@@ -669,7 +679,9 @@ namespace ICSharpCode.WpfDesign.XamlDom
}
}
}
currentParsedNode = element ;
currentXmlSpace = oldXmlSpace ;
}