diff --git a/src/libraries/System.Resources.Extensions/ref/System.Resources.Extensions.cs b/src/libraries/System.Resources.Extensions/ref/System.Resources.Extensions.cs index 4c08022721854a..f4e0695166247d 100644 --- a/src/libraries/System.Resources.Extensions/ref/System.Resources.Extensions.cs +++ b/src/libraries/System.Resources.Extensions/ref/System.Resources.Extensions.cs @@ -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() { } diff --git a/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs b/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs index 972e9ccfeb8170..972f20378b1b5e 100644 --- a/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs +++ b/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/DeserializingResourceReader.cs @@ -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)) @@ -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: diff --git a/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/PreserializedResourceWriter.cs b/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/PreserializedResourceWriter.cs index 5eba6fb9faa22f..c1017736d01d23 100644 --- a/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/PreserializedResourceWriter.cs +++ b/src/libraries/System.Resources.Extensions/src/System/Resources/Extensions/PreserializedResourceWriter.cs @@ -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 : @@ -40,22 +40,22 @@ public partial class PreserializedResourceWriter // is done by reflection private static readonly IReadOnlyDictionary s_primitiveTypes = new Dictionary(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 }; @@ -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))