Skip to content

Commit fb878b8

Browse files
committed
fix nullable
1 parent 08b0287 commit fb878b8

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

ExpressionDebugger.Tests/DebugInfoInjectorTest.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,12 +723,14 @@ public void TestProperties()
723723
{
724724
IsStatic = false,
725725
Namespace = "ExpressionDebugger.Tests",
726-
TypeName = "MockClass"
726+
TypeName = "MockClass",
727+
NullableContext = 2,
727728
});
728729
translator.Properties.Add(new PropertyDefinitions
729730
{
730731
Name = "Prop1",
731-
Type = typeof(string)
732+
Type = typeof(string),
733+
NullableContext = 0,
732734
});
733735
translator.Properties.Add(new PropertyDefinitions
734736
{
@@ -741,7 +743,8 @@ public void TestProperties()
741743
{
742744
Name = "Prop3",
743745
Type = typeof(string),
744-
IsInitOnly = true
746+
IsInitOnly = true,
747+
NullableContext = 0,
745748
});
746749
var str = translator.ToString();
747750
Assert.AreEqual(@"

ExpressionTranslator/ExpressionTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ private string TranslateNullable(Type type, byte? nullableContext, byte[]? nulla
422422
public string Translate(Type type)
423423
{
424424
var refNullable = !type.GetTypeInfo().IsValueType &&
425-
(_nilCtx == 2 || _nilIndex < _nil?.Length && _nil[_nilIndex++] == 2);
425+
(_nilIndex < _nil?.Length ? _nil[_nilIndex++] == 2 : _nilCtx == 2);
426426
var typeName = TranslateInner(type);
427427
return refNullable ? $"{typeName}?" : typeName;
428428
}

ExpressionTranslator/ExpressionTranslator.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<SignAssembly>True</SignAssembly>
1313
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
1414
<AssemblyOriginatorKeyFile>ExpressionTranslator.snk</AssemblyOriginatorKeyFile>
15-
<Version>2.4.2</Version>
15+
<Version>2.4.3</Version>
1616
<RootNamespace>ExpressionDebugger</RootNamespace>
1717
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1818
<PackageIcon>icon.png</PackageIcon>
@@ -33,10 +33,6 @@
3333
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.3.0" />
3434
</ItemGroup>
3535

36-
<ItemGroup>
37-
<None Remove="ExpressionTranslator.cs~RFe80e7f7.TMP" />
38-
</ItemGroup>
39-
4036
<ItemGroup>
4137
<None Include="icon.png" Pack="true" PackagePath="\" />
4238
</ItemGroup>

ExpressionTranslator/PropertyDefinitions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ public class PropertyDefinitions
1010
public string Name { get; set; }
1111
public bool IsReadOnly { get; set; }
1212
public bool IsInitOnly { get; set; }
13+
14+
/// <summary>
15+
/// Set to 2 to mark type as nullable
16+
/// </summary>
1317
public byte? NullableContext { get; set; }
18+
19+
/// <summary>
20+
/// If type is generic, array or tuple, you can mark nullable for each type
21+
/// Set to 2 for nullable
22+
/// </summary>
1423
public byte[]? Nullable { get; set; }
1524
}
1625
}

ExpressionTranslator/TypeDefinitions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public class TypeDefinitions
1212
public IEnumerable<Type>? Implements { get; set; }
1313
public bool PrintFullTypeName { get; set; }
1414
public bool IsRecordType { get; set; }
15+
16+
/// <summary>
17+
/// Set to 2 to mark all properties as nullable
18+
/// </summary>
1519
public byte? NullableContext { get; set; }
1620
}
1721
}

0 commit comments

Comments
 (0)