Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
31 changes: 26 additions & 5 deletions 31 .editorconfig
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# EditorConfig is awesome:http://EditorConfig.org
# EditorConfig is awesome:http://EditorConfig.org

# top-most EditorConfig file
root = true

# Don't use tabs for indentation.
[*]
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

# (Please don't specify an indent_size here; that has too many unintended consequences.)

Expand All @@ -18,18 +16,21 @@ indent_style = space
# Code files
[*.{cs,csx,vb,vbx,h,cpp,idl}]
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

# Xml project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj,msbuildproj}]
indent_size = 2

# Xml config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct,runsettings}]
indent_size = 2

# JSON files
[*.json]
indent_size = 2
indent_style = space

# Dotnet code style settings:
[*.{cs,vb}]
Expand Down Expand Up @@ -167,3 +168,23 @@ csharp_new_line_before_members_in_anonymous_types = true

# Blocks are allowed
csharp_prefer_braces = true:silent

dotnet_diagnostic.RS0041.severity = suggestion

# SA1130: Use lambda syntax
dotnet_diagnostic.SA1130.severity = silent

# IDE1006: Naming Styles - StyleCop handles these for us
dotnet_diagnostic.IDE1006.severity = none

dotnet_diagnostic.DOC100.severity = silent
dotnet_diagnostic.DOC104.severity = warning
dotnet_diagnostic.DOC105.severity = warning
dotnet_diagnostic.DOC106.severity = warning
dotnet_diagnostic.DOC107.severity = warning
dotnet_diagnostic.DOC108.severity = warning
dotnet_diagnostic.DOC200.severity = warning
dotnet_diagnostic.DOC202.severity = warning

[*.sln]
indent_style = tab
2 changes: 2 additions & 0 deletions 2 Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Visible="false" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNetAnalyzers.DocumentationAnalyzers" Version="1.0.0-beta.59" PrivateAssets="All" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.119" PrivateAssets="all" />
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.4.27" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.435" PrivateAssets="all" />
Expand Down
5 changes: 3 additions & 2 deletions 5 MessagePack.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29108.181
# Visual Studio Version 17
VisualStudioVersion = 17.5.33201.384
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC}"
EndProject
Expand Down Expand Up @@ -44,6 +44,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestData2", "sandbox\TestDa
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{301F812B-8AEE-4DC2-8009-4510F02294AD}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
azure-pipelines.yml = azure-pipelines.yml
azure-pipelines\build.yml = azure-pipelines\build.yml
Directory.Build.props = Directory.Build.props
Expand Down
1 change: 1 addition & 0 deletions 1 sandbox/DynamicCodeDumper/DynamicCodeDumper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<OutputType>exe</OutputType>
<DefineConstants>$(DefineConstants);DYNAMICCODEDUMPER</DefineConstants>
</PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions 8 sandbox/DynamicCodeDumper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private class EmptyResolver : IFormatterResolver
{
internal static readonly MessagePackSerializerOptions Options = new MessagePackSerializerOptions(new EmptyResolver());

public IMessagePackFormatter<T> GetFormatter<T>() => null;
public IMessagePackFormatter<T>? GetFormatter<T>() => null;
}
}

Expand All @@ -127,7 +127,7 @@ public class MyClass

[Key(1)]
[MessagePackFormatter(typeof(String_x2Formatter))]
public string MyProperty2 { get; set; }
public string? MyProperty2 { get; set; }

#pragma warning disable SA1306 // Field names should begin with lower-case letter
[Key(2)]
Expand Down Expand Up @@ -334,7 +334,7 @@ public class Contractless2
{
public int MyProperty { get; set; }

public string MyProperty2 { get; set; }
public string? MyProperty2 { get; set; }
}

public interface IEntity
Expand Down Expand Up @@ -364,7 +364,7 @@ public Holder(IEntity entity)

public abstract class EntityBase
{
public string Name { get; }
public string? Name { get; }

public EntityBase()
{
Expand Down
1 change: 1 addition & 0 deletions 1 sandbox/MessagePack.Internal/MessagePack.Internal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<Nullable>enable</Nullable>
<DefineConstants>$(DefineConstants);SPAN_BUILTIN;MESSAGEPACK_INTERNAL</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
Expand Down
1 change: 1 addition & 0 deletions 1 src/MessagePack.Annotations/MessagePack.Annotations.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<NoWarn>$(NoWarn);CS0649</NoWarn>
<Nullable>enable</Nullable>
<RootNamespace>MessagePack</RootNamespace>

<IsPackable>true</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class KeyAttribute : Attribute
{
public int? IntKey { get; private set; }

public string StringKey { get; private set; }
public string? StringKey { get; private set; }

public KeyAttribute(int x)
{
Expand All @@ -32,7 +32,7 @@ public KeyAttribute(int x)

public KeyAttribute(string x)
{
this.StringKey = x;
this.StringKey = x ?? throw new ArgumentNullException(nameof(x));
}
}

Expand Down Expand Up @@ -62,7 +62,7 @@ public class UnionAttribute : Attribute
public UnionAttribute(int key, Type subType)
{
this.Key = key;
this.SubType = subType;
this.SubType = subType ?? throw new ArgumentNullException(nameof(subType));
}

/// <summary>
Expand All @@ -87,16 +87,16 @@ public class MessagePackFormatterAttribute : Attribute
{
public Type FormatterType { get; private set; }

public object[] Arguments { get; private set; }
public object?[]? Arguments { get; private set; }

public MessagePackFormatterAttribute(Type formatterType)
{
this.FormatterType = formatterType;
this.FormatterType = formatterType ?? throw new ArgumentNullException(nameof(formatterType));
}

public MessagePackFormatterAttribute(Type formatterType, params object[] arguments)
public MessagePackFormatterAttribute(Type formatterType, params object?[]? arguments)
{
this.FormatterType = formatterType;
this.FormatterType = formatterType ?? throw new ArgumentNullException(nameof(formatterType));
this.Arguments = arguments;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable disable

using System;
using System.Buffers;
using System.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class CollectionHelpers<TCollection, TEqualityComparer>
/// <summary>
/// The delegate that will create the collection, if the typical (int count, IEqualityComparer{T} equalityComparer) constructor was found.
/// </summary>
private static Func<int, TEqualityComparer, TCollection> collectionCreator;
private static Func<int, TEqualityComparer, TCollection>? collectionCreator;

/// <summary>
/// Initializes static members of the <see cref="CollectionHelpers{TCollection, TEqualityComparer}"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public DateTime Deserialize(ref MessagePackReader reader, MessagePackSerializerO
}
}

public sealed class NativeDateTimeArrayFormatter : IMessagePackFormatter<DateTime[]>
public sealed class NativeDateTimeArrayFormatter : IMessagePackFormatter<DateTime[]?>
{
public static readonly NativeDateTimeArrayFormatter Instance = new NativeDateTimeArrayFormatter();

public void Serialize(ref MessagePackWriter writer, DateTime[] value, MessagePackSerializerOptions options)
public void Serialize(ref MessagePackWriter writer, DateTime[]? value, MessagePackSerializerOptions options)
{
if (value == null)
{
Expand All @@ -47,7 +47,7 @@ public void Serialize(ref MessagePackWriter writer, DateTime[] value, MessagePac
}
}

public DateTime[] Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
public DateTime[]? Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
if (reader.TryReadNil())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
namespace MessagePack.Formatters
{
// unfortunately, can't use IDictionary<KVP> because supports IReadOnlyDictionary.
public abstract class DictionaryFormatterBase<TKey, TValue, TIntermediate, TEnumerator, TDictionary> : IMessagePackFormatter<TDictionary>
where TDictionary : IEnumerable<KeyValuePair<TKey, TValue>>
public abstract class DictionaryFormatterBase<TKey, TValue, TIntermediate, TEnumerator, TDictionary> : IMessagePackFormatter<TDictionary?>
where TDictionary : class?, IEnumerable<KeyValuePair<TKey, TValue>>
where TEnumerator : IEnumerator<KeyValuePair<TKey, TValue>>
{
public void Serialize(ref MessagePackWriter writer, TDictionary value, MessagePackSerializerOptions options)
public void Serialize(ref MessagePackWriter writer, TDictionary? value, MessagePackSerializerOptions options)
{
if (value == null)
{
Expand All @@ -25,8 +25,8 @@ public void Serialize(ref MessagePackWriter writer, TDictionary value, MessagePa
else
{
IFormatterResolver resolver = options.Resolver;
IMessagePackFormatter<TKey> keyFormatter = resolver.GetFormatterWithVerify<TKey>();
IMessagePackFormatter<TValue> valueFormatter = resolver.GetFormatterWithVerify<TValue>();
IMessagePackFormatter<TKey>? keyFormatter = resolver.GetFormatterWithVerify<TKey>();
IMessagePackFormatter<TValue>? valueFormatter = resolver.GetFormatterWithVerify<TValue>();

int count;
{
Expand Down Expand Up @@ -69,7 +69,7 @@ public void Serialize(ref MessagePackWriter writer, TDictionary value, MessagePa
}
}

public TDictionary Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
public TDictionary? Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
if (reader.TryReadNil())
{
Expand All @@ -78,8 +78,8 @@ public TDictionary Deserialize(ref MessagePackReader reader, MessagePackSerializ
else
{
IFormatterResolver resolver = options.Resolver;
IMessagePackFormatter<TKey> keyFormatter = resolver.GetFormatterWithVerify<TKey>();
IMessagePackFormatter<TValue> valueFormatter = resolver.GetFormatterWithVerify<TValue>();
IMessagePackFormatter<TKey>? keyFormatter = resolver.GetFormatterWithVerify<TKey>();
IMessagePackFormatter<TValue>? valueFormatter = resolver.GetFormatterWithVerify<TValue>();

var len = reader.ReadMapHeader();

Expand Down Expand Up @@ -120,7 +120,7 @@ public TDictionary Deserialize(ref MessagePackReader reader, MessagePackSerializ
}

public abstract class DictionaryFormatterBase<TKey, TValue, TIntermediate, TDictionary> : DictionaryFormatterBase<TKey, TValue, TIntermediate, IEnumerator<KeyValuePair<TKey, TValue>>, TDictionary>
where TDictionary : IEnumerable<KeyValuePair<TKey, TValue>>
where TDictionary : class?, IEnumerable<KeyValuePair<TKey, TValue>>
{
protected override IEnumerator<KeyValuePair<TKey, TValue>> GetSourceEnumerator(TDictionary source)
{
Expand All @@ -129,7 +129,8 @@ protected override IEnumerator<KeyValuePair<TKey, TValue>> GetSourceEnumerator(T
}

public abstract class DictionaryFormatterBase<TKey, TValue, TDictionary> : DictionaryFormatterBase<TKey, TValue, TDictionary, TDictionary>
where TDictionary : IDictionary<TKey, TValue>
where TDictionary : class?, IDictionary<TKey, TValue>
where TKey : notnull
{
protected override TDictionary Complete(TDictionary intermediateCollection)
{
Expand All @@ -138,6 +139,7 @@ protected override TDictionary Complete(TDictionary intermediateCollection)
}

public sealed class DictionaryFormatter<TKey, TValue> : DictionaryFormatterBase<TKey, TValue, Dictionary<TKey, TValue>, Dictionary<TKey, TValue>.Enumerator, Dictionary<TKey, TValue>>
where TKey : notnull
{
protected override void Add(Dictionary<TKey, TValue> collection, int index, TKey key, TValue value, MessagePackSerializerOptions options)
{
Expand All @@ -161,7 +163,8 @@ protected override Dictionary<TKey, TValue>.Enumerator GetSourceEnumerator(Dicti
}

public sealed class GenericDictionaryFormatter<TKey, TValue, TDictionary> : DictionaryFormatterBase<TKey, TValue, TDictionary>
where TDictionary : IDictionary<TKey, TValue>, new()
where TDictionary : class?, IDictionary<TKey, TValue>, new()
where TKey : notnull
{
protected override void Add(TDictionary collection, int index, TKey key, TValue value, MessagePackSerializerOptions options)
{
Expand All @@ -175,7 +178,8 @@ protected override TDictionary Create(int count, MessagePackSerializerOptions op
}

public sealed class GenericReadOnlyDictionaryFormatter<TKey, TValue, TDictionary> : DictionaryFormatterBase<TKey, TValue, Dictionary<TKey, TValue>, TDictionary>
where TDictionary : IReadOnlyDictionary<TKey, TValue>
where TDictionary : class?, IReadOnlyDictionary<TKey, TValue>
where TKey : notnull
{
protected override void Add(Dictionary<TKey, TValue> collection, int index, TKey key, TValue value, MessagePackSerializerOptions options)
{
Expand All @@ -189,11 +193,12 @@ protected override Dictionary<TKey, TValue> Create(int count, MessagePackSeriali

protected override TDictionary Complete(Dictionary<TKey, TValue> intermediateCollection)
{
return (TDictionary)Activator.CreateInstance(typeof(TDictionary), intermediateCollection);
return (TDictionary)(Activator.CreateInstance(typeof(TDictionary), intermediateCollection) ?? throw new InvalidOperationException("Unable to create dictionary instance."));
}
}

public sealed class InterfaceDictionaryFormatter<TKey, TValue> : DictionaryFormatterBase<TKey, TValue, Dictionary<TKey, TValue>, IDictionary<TKey, TValue>>
where TKey : notnull
{
protected override void Add(Dictionary<TKey, TValue> collection, int index, TKey key, TValue value, MessagePackSerializerOptions options)
{
Expand All @@ -212,6 +217,7 @@ protected override IDictionary<TKey, TValue> Complete(Dictionary<TKey, TValue> i
}

public sealed class SortedListFormatter<TKey, TValue> : DictionaryFormatterBase<TKey, TValue, SortedList<TKey, TValue>>
where TKey : notnull
{
protected override void Add(SortedList<TKey, TValue> collection, int index, TKey key, TValue value, MessagePackSerializerOptions options)
{
Expand All @@ -225,6 +231,7 @@ protected override SortedList<TKey, TValue> Create(int count, MessagePackSeriali
}

public sealed class SortedDictionaryFormatter<TKey, TValue> : DictionaryFormatterBase<TKey, TValue, SortedDictionary<TKey, TValue>, SortedDictionary<TKey, TValue>.Enumerator, SortedDictionary<TKey, TValue>>
where TKey : notnull
{
protected override void Add(SortedDictionary<TKey, TValue> collection, int index, TKey key, TValue value, MessagePackSerializerOptions options)
{
Expand All @@ -248,6 +255,7 @@ protected override SortedDictionary<TKey, TValue>.Enumerator GetSourceEnumerator
}

public sealed class ReadOnlyDictionaryFormatter<TKey, TValue> : DictionaryFormatterBase<TKey, TValue, Dictionary<TKey, TValue>, ReadOnlyDictionary<TKey, TValue>>
where TKey : notnull
{
protected override void Add(Dictionary<TKey, TValue> collection, int index, TKey key, TValue value, MessagePackSerializerOptions options)
{
Expand All @@ -266,6 +274,7 @@ protected override Dictionary<TKey, TValue> Create(int count, MessagePackSeriali
}

public sealed class InterfaceReadOnlyDictionaryFormatter<TKey, TValue> : DictionaryFormatterBase<TKey, TValue, Dictionary<TKey, TValue>, IReadOnlyDictionary<TKey, TValue>>
where TKey : notnull
{
protected override void Add(Dictionary<TKey, TValue> collection, int index, TKey key, TValue value, MessagePackSerializerOptions options)
{
Expand All @@ -284,6 +293,7 @@ protected override Dictionary<TKey, TValue> Create(int count, MessagePackSeriali
}

public sealed class ConcurrentDictionaryFormatter<TKey, TValue> : DictionaryFormatterBase<TKey, TValue, System.Collections.Concurrent.ConcurrentDictionary<TKey, TValue>>
where TKey : notnull
{
protected override void Add(ConcurrentDictionary<TKey, TValue> collection, int index, TKey key, TValue value, MessagePackSerializerOptions options)
{
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.