Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions ICSharpCode.BamlDecompiler/Rewrite/AttributeRewritePass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ THE SOFTWARE.
using System.Xml.Linq;

using ICSharpCode.BamlDecompiler.Xaml;
using ICSharpCode.Decompiler.TypeSystem;

namespace ICSharpCode.BamlDecompiler.Rewrite
{
Expand Down Expand Up @@ -59,20 +60,25 @@ bool ProcessElement(XamlContext ctx, XElement elem)

bool RewriteElement(XamlContext ctx, XElement parent, XElement elem)
{
var property = elem.Annotation<XamlProperty>();
if (property == null && elem.Name != key)
return false;

if (elem.HasAttributes || elem.HasElements)
return false;

ctx.CancellationToken.ThrowIfCancellationRequested();

var value = elem.Value;
var attrName = elem.Name;
if (attrName != key)
{
var property = elem.Annotation<XamlProperty>();
if (property is null)
return false;

if (property.ResolvedMember is IProperty propertyDef && !propertyDef.CanSet)
return false;

attrName = property.ToXName(ctx, parent, property.IsAttachedTo(parent.Annotation<XamlType>()));
var attr = new XAttribute(attrName, value);
}

ctx.CancellationToken.ThrowIfCancellationRequested();

var attr = new XAttribute(attrName, elem.Value);
var list = new List<XAttribute>(parent.Attributes());
if (attrName == key)
list.Insert(0, attr);
Expand All @@ -85,4 +91,4 @@ bool RewriteElement(XamlContext ctx, XElement parent, XElement elem)
return true;
}
}
}
}
Loading