Skip to content

Commit

Permalink
Merge branch 'issue/nullable-system-type-arguments' into development
Browse files Browse the repository at this point in the history
Closes #224
  • Loading branch information
Washi1337 committed Nov 28, 2021
2 parents 8977a4d + d292e10 commit 93a8e07
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void ReadValue(in BlobReadContext context, ref BinaryStreamReader reader,
string? typeFullName = reader.ReadSerString();
var type = typeFullName is not null
? TypeNameParser.Parse(module, typeFullName)
: context.ReaderContext.BadImageAndReturn<TypeSignature>("Type full name in attribute argument is null.");
: null;

Elements.Add(type);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ private void WriteElement(TypeSignature argumentType, object? element)
private void WriteNullElement(TypeSignature argumentType)
{
var writer = _context.Writer;

if (argumentType.IsTypeOf("System", "Type"))
{
writer.WriteSerString(default(string));
return;
}

switch (argumentType.ElementType)
{
case ElementType.String:
Expand Down
10 changes: 10 additions & 0 deletions test/AsmResolver.DotNet.Tests/CustomAttributeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ public void FixedEnumArgument(bool rebuild)
Assert.Equal((int) TestEnum.Value3, argument.Element);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void FixedNullTypeArgument(bool rebuild)
{
var attribute = GetCustomAttributeTestCase(nameof(CustomAttributesTestClass.FixedNullTypeArgument), rebuild);
var fixedArg = Assert.Single(attribute.Signature.FixedArguments);
Assert.Null(fixedArg.Element);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,133 +1,138 @@
using System;
using System.Collections.Generic;

// Disable warnings for unused members.
#pragma warning disable 67

namespace AsmResolver.DotNet.TestCases.CustomAttributes
{
[TestCase]
public class CustomAttributesTestClass
{
[TestCase]
public event EventHandler TestEvent;

[TestCase]
public int TestField;

[TestCase]
public void TestMethod([TestCase] int testParameter)
{
}

[TestCase]
public int TestProperty
{
[TestCase]
get;
[TestCase]
set;
}

[TestCase(1)]
public void FixedInt32Argument()
{
}

[TestCase("String fixed arg")]
public void FixedStringArgument()
{
}

[TestCase(TestEnum.Value3)]
public void FixedEnumArgument()
{
}

[TestCase(typeof(string))]
public void FixedTypeArgument()
{
}

[TestCase(typeof(KeyValuePair<string[], int[]>))]
public void FixedComplexTypeArgument()
{
}

[TestCase(2, "Fixed arg", TestEnum.Value3)]
public void FixedMultipleArguments()
{
}

[TestCase(IntValue = 2)]
public void NamedInt32Argument()
{
}

[TestCase(StringValue = "String named arg")]
public void NamedStringArgument()
{
}

[TestCase(EnumValue = TestEnum.Value2)]
public void NamedEnumArgument()
{
}

[TestCase(TypeValue = typeof(int))]
public void NamedTypeArgument()
{
}

[TestCase(typeof(TestGenericType<object>))]
public void GenericType()
{
}

[TestCase(typeof(TestGenericType<object>[]))]
public void GenericTypeArray()
{
}

[TestCase((object) 123)]
public void Int32PassedAsObject()
{
}

[TestCase((object) typeof(int))]
public void TypePassedAsObject()
{
}

[TestCase(new int[] {1, 2, 3, 4})]
public void FixedInt32ArrayArgument()
{
}

[TestCase(default(int[]))]
public void FixedInt32ArrayNullArgument()
{
}

[TestCase(new int[0])]
public void FixedInt32ArrayEmptyArgument()
{
}

[TestCase((object) new int[] {1, 2, 3, 4})]
public void FixedInt32ArrayAsObjectArgument()
{
}

[TestCase((object) default(int[]))]
public void FixedInt32ArrayAsObjectNullArgument()
{
}

[TestCase((object) new int[0])]
public void FixedInt32ArrayAsObjectEmptyArgument()
{
}

}
}
using System;
using System.Collections.Generic;

// Disable warnings for unused members.
#pragma warning disable 67

namespace AsmResolver.DotNet.TestCases.CustomAttributes
{
[TestCase]
public class CustomAttributesTestClass
{
[TestCase]
public event EventHandler TestEvent;

[TestCase]
public int TestField;

[TestCase]
public void TestMethod([TestCase] int testParameter)
{
}

[TestCase]
public int TestProperty
{
[TestCase]
get;
[TestCase]
set;
}

[TestCase(1)]
public void FixedInt32Argument()
{
}

[TestCase("String fixed arg")]
public void FixedStringArgument()
{
}

[TestCase(TestEnum.Value3)]
public void FixedEnumArgument()
{
}

[TestCase(typeof(string))]
public void FixedTypeArgument()
{
}

[TestCase(typeof(KeyValuePair<string[], int[]>))]
public void FixedComplexTypeArgument()
{
}

[TestCase(2, "Fixed arg", TestEnum.Value3)]
public void FixedMultipleArguments()
{
}

[TestCase(IntValue = 2)]
public void NamedInt32Argument()
{
}

[TestCase(StringValue = "String named arg")]
public void NamedStringArgument()
{
}

[TestCase(EnumValue = TestEnum.Value2)]
public void NamedEnumArgument()
{
}

[TestCase(TypeValue = typeof(int))]
public void NamedTypeArgument()
{
}

[TestCase(typeof(TestGenericType<object>))]
public void GenericType()
{
}

[TestCase(typeof(TestGenericType<object>[]))]
public void GenericTypeArray()
{
}

[TestCase((object) 123)]
public void Int32PassedAsObject()
{
}

[TestCase((object) typeof(int))]
public void TypePassedAsObject()
{
}

[TestCase(new int[] {1, 2, 3, 4})]
public void FixedInt32ArrayArgument()
{
}

[TestCase(default(int[]))]
public void FixedInt32ArrayNullArgument()
{
}

[TestCase(new int[0])]
public void FixedInt32ArrayEmptyArgument()
{
}

[TestCase((object) new int[] {1, 2, 3, 4})]
public void FixedInt32ArrayAsObjectArgument()
{
}

[TestCase((object) default(int[]))]
public void FixedInt32ArrayAsObjectNullArgument()
{
}

[TestCase((object) new int[0])]
public void FixedInt32ArrayAsObjectEmptyArgument()
{
}

[TestCase((Type) null)]
public void FixedNullTypeArgument()
{
}

}
}

0 comments on commit 93a8e07

Please sign in to comment.