Skip to content

Commit

Permalink
Merge pull request #66 from MrJul/fix-init-properties
Browse files Browse the repository at this point in the history
Ignore modopt/modreq on Cecil types to match SRE
  • Loading branch information
kekekeks authored Aug 5, 2022
2 parents d990d63 + ad103bf commit ad11913
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<Project>

<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>

</Project>
5 changes: 5 additions & 0 deletions src/XamlX.IL.Cecil/CecilTypeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public CecilType Get(TypeReference reference)
{
if (reference.GetType() == typeof(TypeReference))
reference = reference.Resolve();
else if (reference is RequiredModifierType modReqType)
reference = modReqType.ElementType;
else if (reference is OptionalModifierType modOptType)
reference = modOptType.ElementType;

var definition = reference.Resolve();
var asm = TypeSystem.FindAsm(definition.Module.Assembly);
if (!_definitions.TryGetValue(definition, out var dentry))
Expand Down
29 changes: 29 additions & 0 deletions tests/XamlParserTests/SpecialPropertiesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Xunit;

namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit
{
}
}

namespace XamlParserTests
{
public class InitPropertiesTestClass
{
public string Prop1 { get; init; }
public int Prop2 { get; init; }
}

public class SpecialPropertiesTests : CompilerTestBase
{
[Fact]
public void Init_Properties_Should_Be_Set()
{
var result = (InitPropertiesTestClass) CompileAndRun(
"<InitPropertiesTestClass xmlns='clr-namespace:XamlParserTests' Prop1='foo' Prop2='42' />");
Assert.Equal("foo", result.Prop1);
Assert.Equal(42, result.Prop2);
}
}
}

0 comments on commit ad11913

Please sign in to comment.