Browse Source

Fix #2773: Decompilation of readonly properties in XAML

pull/2828/head
Siegfried Pammer 3 years ago
parent
commit
94977d0022
  1. 6
      ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs
  2. 3
      ILSpy.BamlDecompiler.Tests/Cases/MyControl.xaml.cs
  3. 4
      ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj
  4. 15
      ILSpy.BamlDecompiler/Rewrite/MarkupExtensionRewritePass.cs

6
ILSpy.BamlDecompiler.Tests/BamlTestRunner.cs

@ -154,6 +154,12 @@ namespace ILSpy.BamlDecompiler.Tests @@ -154,6 +154,12 @@ namespace ILSpy.BamlDecompiler.Tests
RunTest("cases/issue2116");
}
[Test]
public void ReadonlyProperty()
{
RunTest("cases/readonlyproperty");
}
#region RunTest
void RunTest(string name)
{

3
ILSpy.BamlDecompiler.Tests/Cases/MyControl.xaml.cs

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System.Collections;
using System.Windows.Controls;
namespace ILSpy.BamlDecompiler.Tests.Cases
@ -25,6 +26,8 @@ namespace ILSpy.BamlDecompiler.Tests.Cases @@ -25,6 +26,8 @@ namespace ILSpy.BamlDecompiler.Tests.Cases
/// </summary>
public partial class MyControl : UserControl
{
public IList DataTypes { get; } = new ArrayList();
public MyControl()
{
InitializeComponent();

4
ILSpy.BamlDecompiler.Tests/ILSpy.BamlDecompiler.Tests.csproj

@ -58,6 +58,7 @@ @@ -58,6 +58,7 @@
<Compile Include="Cases\MyControl.xaml.cs">
<DependentUpon>MyControl.xaml</DependentUpon>
</Compile>
<Compile Include="Cases\ReadonlyProperty.xaml.cs" />
<Compile Include="Cases\Resources.xaml.cs">
<DependentUpon>Resources.xaml</DependentUpon>
</Compile>
@ -102,6 +103,9 @@ @@ -102,6 +103,9 @@
<Page Include="Cases\MarkupExtension.xaml" />
<Page Include="Cases\MyControl.xaml" />
<Page Include="Cases\NamespacePrefix.xaml" />
<Page Include="Cases\ReadonlyProperty.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Cases\Resources.xaml" />
<Page Include="Cases\Simple.xaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>

15
ILSpy.BamlDecompiler/Rewrite/MarkupExtensionRewritePass.cs

@ -21,9 +21,13 @@ @@ -21,9 +21,13 @@
*/
using System.Collections.Generic;
using System.DirectoryServices.ActiveDirectory;
using System.Linq;
using System.Windows.Forms;
using System.Xml.Linq;
using ICSharpCode.Decompiler.TypeSystem;
using ILSpy.BamlDecompiler.Xaml;
namespace ILSpy.BamlDecompiler.Rewrite
@ -64,8 +68,15 @@ namespace ILSpy.BamlDecompiler.Rewrite @@ -64,8 +68,15 @@ namespace ILSpy.BamlDecompiler.Rewrite
{
var type = parent.Annotation<XamlType>();
var property = elem.Annotation<XamlProperty>();
if ((property == null || type == null) && elem.Name != key)
return false;
if (elem.Name != key)
{
if (property == null || type == null)
return false;
if (property.ResolvedMember is IProperty { CanSet: false })
return false;
}
if (elem.Elements().Count() != 1 || elem.Attributes().Any(t => t.Name.Namespace != XNamespace.Xmlns))
return false;

Loading…
Cancel
Save