Skip to content

Annotate System.Resources.Extensions for nullable reference types #37597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public sealed partial class PreserializedResourceWriter : System.IDisposable, Sy
public PreserializedResourceWriter(System.IO.Stream stream) { }
public PreserializedResourceWriter(string fileName) { }
public void AddActivatorResource(string name, System.IO.Stream value, string typeName, bool closeAfterWrite = false) { }
public void AddBinaryFormattedResource(string name, byte[] value, string typeName = null) { }
public void AddResource(string name, byte[] value) { }
public void AddResource(string name, System.IO.Stream value, bool closeAfterWrite = false) { }
public void AddResource(string name, object value) { }
public void AddResource(string name, string value) { }
public void AddBinaryFormattedResource(string name, byte[] value, string? typeName = null) { }
public void AddResource(string name, byte[]? value) { }
public void AddResource(string name, System.IO.Stream? value, bool closeAfterWrite = false) { }
public void AddResource(string name, object? value) { }
public void AddResource(string name, string? value) { }
public void AddResource(string name, string value, string typeName) { }
public void AddTypeConverterResource(string name, byte[] value, string typeName) { }
public void Close() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ private object ReadBinaryFormattedObject()

internal class UndoTruncatedTypeNameSerializationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
public override Type? BindToType(string assemblyName, string typeName)
{
Type type = null;
Type? type = null;

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

value = Activator.CreateInstance(type, new object[] { stream });
value = Activator.CreateInstance(type, new object[] { stream })!;
break;
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class PreserializedResourceWriter
// an internal type name used to represent an unknown resource type, explicitly omit version to save
// on size and avoid changes in user resources. This works since we only ever load this type name
// from calls to GetType from this assembly.
private static readonly string UnknownObjectTypeName = typeof(UnknownType).FullName;
private static readonly string UnknownObjectTypeName = typeof(UnknownType).FullName!;

private string ResourceReaderTypeName => _requiresDeserializingResourceReader ?
DeserializingResourceReaderFullyQualifiedName :
Expand All @@ -40,22 +40,22 @@ public partial class PreserializedResourceWriter
// is done by reflection
private static readonly IReadOnlyDictionary<string, Type> s_primitiveTypes = new Dictionary<string, Type>(16, TypeNameComparer.Instance)
{
{ typeof(string).FullName, typeof(string) },
{ typeof(int).FullName, typeof(int) },
{ typeof(bool).FullName, typeof(bool) },
{ typeof(char).FullName, typeof(char) },
{ typeof(byte).FullName, typeof(byte) },
{ typeof(sbyte).FullName, typeof(sbyte) },
{ typeof(short).FullName, typeof(short) },
{ typeof(long).FullName, typeof(long) },
{ typeof(ushort).FullName, typeof(ushort) },
{ typeof(uint).FullName, typeof(uint) },
{ typeof(ulong).FullName, typeof(ulong) },
{ typeof(float).FullName, typeof(float) },
{ typeof(double).FullName, typeof(double) },
{ typeof(decimal).FullName, typeof(decimal) },
{ typeof(DateTime).FullName, typeof(DateTime) },
{ typeof(TimeSpan).FullName, typeof(TimeSpan) }
{ typeof(string).FullName!, typeof(string) },
{ typeof(int).FullName!, typeof(int) },
{ typeof(bool).FullName!, typeof(bool) },
{ typeof(char).FullName!, typeof(char) },
{ typeof(byte).FullName!, typeof(byte) },
{ typeof(sbyte).FullName!, typeof(sbyte) },
{ typeof(short).FullName!, typeof(short) },
{ typeof(long).FullName!, typeof(long) },
{ typeof(ushort).FullName!, typeof(ushort) },
{ typeof(uint).FullName!, typeof(uint) },
{ typeof(ulong).FullName!, typeof(ulong) },
{ typeof(float).FullName!, typeof(float) },
{ typeof(double).FullName!, typeof(double) },
{ typeof(decimal).FullName!, typeof(decimal) },
{ typeof(DateTime).FullName!, typeof(DateTime) },
{ typeof(TimeSpan).FullName!, typeof(TimeSpan) }
// byte[] and Stream are primitive types but do not define a conversion from string
};

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

// determine if the type is a primitive type
if (s_primitiveTypes.TryGetValue(typeName, out Type primitiveType))
if (s_primitiveTypes.TryGetValue(typeName, out Type? primitiveType))
{
// directly add strings
if (primitiveType == typeof(string))
Expand Down