Skip to content

Commit

Permalink
Don't crash when XAML namespace cannot be resolved (refs #282)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElektroKill committed Jan 11, 2024
1 parent e6c047e commit 474a6af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
10 changes: 1 addition & 9 deletions Extensions/dnSpy.BamlDecompiler/Xaml/XamlProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,7 @@ public string ToMarkupExtensionName(XamlContext ctx, XElement parent, bool isFul
return XmlConvert.EncodeLocalName(PropertyName);

var sb = new StringBuilder();
if (DeclaringType.Namespace != parent.GetDefaultNamespace()) {
var prefix = parent.GetPrefixOfNamespace(DeclaringType.Namespace);
if (!string.IsNullOrEmpty(prefix)) {
sb.Append(prefix);
sb.Append(':');
}
}

DeclaringType.TypeName.AppendEncodedName(sb);
DeclaringType.AppendMarkupExtensionName(sb, parent);
sb.Append('.');
sb.Append(XmlConvert.EncodeLocalName(PropertyName));
return sb.ToString();
Expand Down
8 changes: 5 additions & 3 deletions Extensions/dnSpy.BamlDecompiler/Xaml/XamlType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,19 @@ public XName ToXName(XamlContext ctx) {

public string ToMarkupExtensionName(XamlContext ctx, XElement elem) {
ResolveNamespace(elem, ctx);
return AppendMarkupExtensionName(new StringBuilder(), elem).ToString();
}

var sb = new StringBuilder();
if (Namespace != elem.GetDefaultNamespace()) {
public StringBuilder AppendMarkupExtensionName(StringBuilder sb, XElement elem) {
if (Namespace is not null && Namespace != elem.GetDefaultNamespace()) {
var prefix = elem.GetPrefixOfNamespace(Namespace);
if (!string.IsNullOrEmpty(prefix)) {
sb.Append(prefix);
sb.Append(':');
}
}

return TypeName.AppendEncodedName(sb).ToString();
return TypeName.AppendEncodedName(sb);
}

public override string ToString() => TypeName;
Expand Down

0 comments on commit 474a6af

Please sign in to comment.