Skip to content

Commit 2f7ed84

Browse files
authored
Annotate System.Resources.Extensions for nullable reference types (#37597)
1 parent fc15e38 commit 2f7ed84

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

src/libraries/System.Resources.Extensions/ref/System.Resources.Extensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public sealed partial class PreserializedResourceWriter : System.IDisposable, Sy
2121
public PreserializedResourceWriter(System.IO.Stream stream) { }
2222
public PreserializedResourceWriter(string fileName) { }
2323
public void AddActivatorResource(string name, System.IO.Stream value, string typeName, bool closeAfterWrite = false) { }
24-
public void AddBinaryFormattedResource(string name, byte[] value, string typeName = null) { }
25-
public void AddResource(string name, byte[] value) { }
26-
public void AddResource(string name, System.IO.Stream value, bool closeAfterWrite = false) { }
27-
public void AddResource(string name, object value) { }
28-
public void AddResource(string name, string value) { }
24+
public void AddBinaryFormattedResource(string name, byte[] value, string? typeName = null) { }
25+
public void AddResource(string name, byte[]? value) { }
26+
public void AddResource(string name, System.IO.Stream? value, bool closeAfterWrite = false) { }
27+
public void AddResource(string name, object? value) { }
28+
public void AddResource(string name, string? value) { }
2929
public void AddResource(string name, string value, string typeName) { }
3030
public void AddTypeConverterResource(string name, byte[] value, string typeName) { }
3131
public void Close() { }

src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ private object ReadBinaryFormattedObject()
5151

5252
internal class UndoTruncatedTypeNameSerializationBinder : SerializationBinder
5353
{
54-
public override Type BindToType(string assemblyName, string typeName)
54+
public override Type? BindToType(string assemblyName, string typeName)
5555
{
56-
Type type = null;
56+
Type? type = null;
5757

5858
// determine if we have a mangled generic type name
5959
if (typeName != null && assemblyName != null && !AreBracketsBalanced(typeName))
@@ -212,7 +212,7 @@ private object DeserializeObject(int typeIndex)
212212
stream = new MemoryStream(bytes, false);
213213
}
214214

215-
value = Activator.CreateInstance(type, new object[] { stream });
215+
value = Activator.CreateInstance(type, new object[] { stream })!;
216216
break;
217217
}
218218
default:

src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/PreserializedResourceWriter.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public partial class PreserializedResourceWriter
2525
// an internal type name used to represent an unknown resource type, explicitly omit version to save
2626
// on size and avoid changes in user resources. This works since we only ever load this type name
2727
// from calls to GetType from this assembly.
28-
private static readonly string UnknownObjectTypeName = typeof(UnknownType).FullName;
28+
private static readonly string UnknownObjectTypeName = typeof(UnknownType).FullName!;
2929

3030
private string ResourceReaderTypeName => _requiresDeserializingResourceReader ?
3131
DeserializingResourceReaderFullyQualifiedName :
@@ -40,22 +40,22 @@ public partial class PreserializedResourceWriter
4040
// is done by reflection
4141
private static readonly IReadOnlyDictionary<string, Type> s_primitiveTypes = new Dictionary<string, Type>(16, TypeNameComparer.Instance)
4242
{
43-
{ typeof(string).FullName, typeof(string) },
44-
{ typeof(int).FullName, typeof(int) },
45-
{ typeof(bool).FullName, typeof(bool) },
46-
{ typeof(char).FullName, typeof(char) },
47-
{ typeof(byte).FullName, typeof(byte) },
48-
{ typeof(sbyte).FullName, typeof(sbyte) },
49-
{ typeof(short).FullName, typeof(short) },
50-
{ typeof(long).FullName, typeof(long) },
51-
{ typeof(ushort).FullName, typeof(ushort) },
52-
{ typeof(uint).FullName, typeof(uint) },
53-
{ typeof(ulong).FullName, typeof(ulong) },
54-
{ typeof(float).FullName, typeof(float) },
55-
{ typeof(double).FullName, typeof(double) },
56-
{ typeof(decimal).FullName, typeof(decimal) },
57-
{ typeof(DateTime).FullName, typeof(DateTime) },
58-
{ typeof(TimeSpan).FullName, typeof(TimeSpan) }
43+
{ typeof(string).FullName!, typeof(string) },
44+
{ typeof(int).FullName!, typeof(int) },
45+
{ typeof(bool).FullName!, typeof(bool) },
46+
{ typeof(char).FullName!, typeof(char) },
47+
{ typeof(byte).FullName!, typeof(byte) },
48+
{ typeof(sbyte).FullName!, typeof(sbyte) },
49+
{ typeof(short).FullName!, typeof(short) },
50+
{ typeof(long).FullName!, typeof(long) },
51+
{ typeof(ushort).FullName!, typeof(ushort) },
52+
{ typeof(uint).FullName!, typeof(uint) },
53+
{ typeof(ulong).FullName!, typeof(ulong) },
54+
{ typeof(float).FullName!, typeof(float) },
55+
{ typeof(double).FullName!, typeof(double) },
56+
{ typeof(decimal).FullName!, typeof(decimal) },
57+
{ typeof(DateTime).FullName!, typeof(DateTime) },
58+
{ typeof(TimeSpan).FullName!, typeof(TimeSpan) }
5959
// byte[] and Stream are primitive types but do not define a conversion from string
6060
};
6161

@@ -80,7 +80,7 @@ public void AddResource(string name, string value, string typeName)
8080
throw new ArgumentNullException(nameof(typeName));
8181

8282
// determine if the type is a primitive type
83-
if (s_primitiveTypes.TryGetValue(typeName, out Type primitiveType))
83+
if (s_primitiveTypes.TryGetValue(typeName, out Type? primitiveType))
8484
{
8585
// directly add strings
8686
if (primitiveType == typeof(string))

0 commit comments

Comments
 (0)