Skip to content

Commit

Permalink
Merge pull request #1541 from neuecc/nrt
Browse files Browse the repository at this point in the history
Last of the nullable ref annotations
  • Loading branch information
AArnott committed Dec 3, 2022
2 parents 95249b1 + a477b7e commit 049565b
Show file tree
Hide file tree
Showing 24 changed files with 295 additions and 302 deletions.
4 changes: 4 additions & 0 deletions MessagePack.sln
Expand Up @@ -4,6 +4,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 17.5.33201.384
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC}"
ProjectSection(SolutionItems) = preProject
src\Directory.Build.props = src\Directory.Build.props
src\Directory.Build.targets = src\Directory.Build.targets
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagePack", "src\MessagePack\MessagePack.csproj", "{7ABB33EE-A2F1-492B-8DAF-5DF89F0F0B79}"
EndProject
Expand Down
2 changes: 1 addition & 1 deletion sandbox/DynamicCodeDumper/Program.cs
Expand Up @@ -43,7 +43,7 @@ private static void Main(string[] args)
////DynamicObjectResolver.Instance.GetFormatter<SimpleStringKeyData2>();
////DynamicObjectResolver.Instance.GetFormatter<StringKeySerializerTarget>();
////DynamicObjectResolver.Instance.GetFormatter<LongestString>();
IMessagePackFormatter<MyClass> f = DynamicObjectResolverAllowPrivate.Instance.GetFormatter<MyClass>();
IMessagePackFormatter<MyClass> f = DynamicObjectResolverAllowPrivate.Instance.GetFormatterWithVerify<MyClass>();
////IMessagePackFormatter<MessagePackFormatterFieldUser> f = DynamicObjectResolver.Instance.GetFormatter<MessagePackFormatterFieldUser>();
////DynamicObjectResolver.Instance.GetFormatter<StringKeySerializerTargetBinary>();
////DynamicObjectResolver.Instance.GetFormatter<Callback1>();
Expand Down
6 changes: 6 additions & 0 deletions src/Directory.Build.props
@@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
<Import Project="$([MSBuild]::GetPathOfFileAbove($(MSBuildThisFile), $(MSBuildThisFileDirectory)..))" />
</Project>
1 change: 0 additions & 1 deletion src/MessagePack.Annotations/MessagePack.Annotations.csproj
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<NoWarn>$(NoWarn);CS0649</NoWarn>
<Nullable>enable</Nullable>
<RootNamespace>MessagePack</RootNamespace>

<IsPackable>true</IsPackable>
Expand Down
Expand Up @@ -23,4 +23,4 @@
<ItemGroup>
<ProjectReference Include="..\MessagePack\MessagePack.csproj" />
</ItemGroup>
</Project>
</Project>
Expand Up @@ -9,14 +9,14 @@ namespace MessagePack.AspNetCoreMvcFormatter
public class MessagePackInputFormatter : InputFormatter
{
private const string ContentType = "application/x-msgpack";
private readonly MessagePackSerializerOptions options;
private readonly MessagePackSerializerOptions? options;

public MessagePackInputFormatter()
: this(null)
{
}

public MessagePackInputFormatter(MessagePackSerializerOptions options)
public MessagePackInputFormatter(MessagePackSerializerOptions? options)
{
this.options = options;

Expand Down
Expand Up @@ -9,14 +9,14 @@ namespace MessagePack.AspNetCoreMvcFormatter
public class MessagePackOutputFormatter : OutputFormatter
{
private const string ContentType = "application/x-msgpack";
private readonly MessagePackSerializerOptions options;
private readonly MessagePackSerializerOptions? options;

public MessagePackOutputFormatter()
: this(null)
{
}

public MessagePackOutputFormatter(MessagePackSerializerOptions options)
public MessagePackOutputFormatter(MessagePackSerializerOptions? options)
{
this.options = options;

Expand Down
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>

<IsPackable>true</IsPackable>
Expand Down
1 change: 0 additions & 1 deletion src/MessagePack.Generator/MessagePack.Generator.csproj
Expand Up @@ -4,7 +4,6 @@
<AssemblyName>mpc</AssemblyName>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<PackAsTool>true</PackAsTool>
<ToolCommandName>mpc</ToolCommandName>
Expand Down
Expand Up @@ -6,7 +6,6 @@

<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\opensource.snk</AssemblyOriginatorKeyFile>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Nullable>enable</Nullable>

<NoPackageAnalysis>true</NoPackageAnalysis>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
Expand Down
12 changes: 6 additions & 6 deletions src/MessagePack.ReactiveProperty/Formatters.cs
Expand Up @@ -109,9 +109,9 @@ internal static int ToReactivePropertySlimModeInt<T>(global::Reactive.Bindings.R
}

// [Mode, SchedulerId, Value] : length should be three.
public class ReactivePropertyFormatter<T> : IMessagePackFormatter<ReactiveProperty<T>>
public class ReactivePropertyFormatter<T> : IMessagePackFormatter<ReactiveProperty<T>?>
{
public void Serialize(ref MessagePackWriter writer, ReactiveProperty<T> value, MessagePackSerializerOptions options)
public void Serialize(ref MessagePackWriter writer, ReactiveProperty<T>? value, MessagePackSerializerOptions options)
{
if (value == null)
{
Expand All @@ -127,7 +127,7 @@ public void Serialize(ref MessagePackWriter writer, ReactiveProperty<T> value, M
}
}

public ReactiveProperty<T> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
public ReactiveProperty<T>? Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
if (reader.TryReadNil())
{
Expand Down Expand Up @@ -332,9 +332,9 @@ public void Serialize(ref MessagePackWriter writer, Unit? value, MessagePackSeri
}

// [Mode, Value]
public class ReactivePropertySlimFormatter<T> : IMessagePackFormatter<ReactivePropertySlim<T>>
public class ReactivePropertySlimFormatter<T> : IMessagePackFormatter<ReactivePropertySlim<T>?>
{
public void Serialize(ref MessagePackWriter writer, ReactivePropertySlim<T> value, MessagePackSerializerOptions options)
public void Serialize(ref MessagePackWriter writer, ReactivePropertySlim<T>? value, MessagePackSerializerOptions options)
{
if (value == null)
{
Expand All @@ -349,7 +349,7 @@ public void Serialize(ref MessagePackWriter writer, ReactivePropertySlim<T> valu
}
}

public ReactivePropertySlim<T> Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
public ReactivePropertySlim<T>? Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
if (reader.TryReadNil())
{
Expand Down
10 changes: 5 additions & 5 deletions src/MessagePack.ReactiveProperty/ReactivePropertyResolver.cs
Expand Up @@ -18,18 +18,18 @@ private ReactivePropertyResolver()
{
}

public IMessagePackFormatter<T> GetFormatter<T>()
public IMessagePackFormatter<T>? GetFormatter<T>()
{
return FormatterCache<T>.Formatter;
}

private static class FormatterCache<T>
{
internal static readonly IMessagePackFormatter<T> Formatter;
internal static readonly IMessagePackFormatter<T>? Formatter;

static FormatterCache()
{
Formatter = (IMessagePackFormatter<T>)ReactivePropertyResolverGetFormatterHelper.GetFormatter(typeof(T));
Formatter = (IMessagePackFormatter<T>?)ReactivePropertyResolverGetFormatterHelper.GetFormatter(typeof(T));
}
}
}
Expand All @@ -45,7 +45,7 @@ internal static class ReactivePropertyResolverGetFormatterHelper
{ typeof(ReactivePropertySlim<>), typeof(ReactivePropertySlimFormatter<>) },
};

internal static object GetFormatter(Type t)
internal static object? GetFormatter(Type t)
{
if (t == typeof(Unit))
{
Expand All @@ -71,7 +71,7 @@ internal static object GetFormatter(Type t)
return null;
}

private static object CreateInstance(Type genericType, Type[] genericTypeArguments, params object[] arguments)
private static object? CreateInstance(Type genericType, Type[] genericTypeArguments, params object[] arguments)
{
return Activator.CreateInstance(genericType.MakeGenericType(genericTypeArguments), arguments);
}
Expand Down

0 comments on commit 049565b

Please sign in to comment.