Do not use extension method syntax

This commit is contained in:
Andrew Arnott 2021-08-21 12:17:30 -06:00
Родитель ab35db5b0a
Коммит d0b140960c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: A9B9910CDCCDA441
4 изменённых файлов: 37 добавлений и 31 удалений

Просмотреть файл

@ -1,16 +0,0 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Reflection;
namespace MessagePack.Generator.Tests
{
internal static class AssemblyExtensions
{
public static IFormatterResolver GetResolverInstance(this Assembly assembly, string name)
{
var resolverType = assembly.GetType(name);
return (IFormatterResolver)resolverType.GetField("Instance", BindingFlags.Static | BindingFlags.Public).GetValue(null);
}
}
}

Просмотреть файл

@ -66,7 +66,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `[]`
var seq = new Sequence<byte>();
@ -140,7 +140,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `[-1, "foobar"]`
var seq = new Sequence<byte>();

Просмотреть файл

@ -67,7 +67,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `{ }`.
var seq = new Sequence<byte>();
@ -132,7 +132,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `{ "A": -1, "B": "foobar" }`.
var seq = new Sequence<byte>();
@ -192,7 +192,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `{ "A": -1, "B": "foobar" }`.
var seq = new Sequence<byte>();
@ -252,7 +252,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `{ }`.
var seq = new Sequence<byte>();
@ -309,7 +309,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build an empty data.
var seq = new Sequence<byte>();
@ -375,7 +375,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `{ "A": -1 }`
var seq = new Sequence<byte>();
@ -449,7 +449,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `{ "A": -1, "B": "foobar" }`
var seq = new Sequence<byte>();
@ -518,7 +518,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `{ "A": -1, "B": "foobar" }`
var seq = new Sequence<byte>();
@ -583,7 +583,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `{ "A": -1, "B": "foobar" }`
var seq = new Sequence<byte>();
@ -649,7 +649,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `{ "A": -1, "B": "foobar" }`
var seq = new Sequence<byte>();
@ -718,7 +718,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `{ "A": -1, "B": "foobar" }`
var seq = new Sequence<byte>();
@ -785,7 +785,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `{ "A": -1 }`
var seq = new Sequence<byte>();
@ -847,7 +847,7 @@ namespace TempProject
var options = MessagePackSerializerOptions.Standard
.WithResolver(CompositeResolver.Create(
StandardResolver.Instance,
assembly.GetResolverInstance("TempProject.Generated.Resolvers.TempProjectResolver")));
TestUtilities.GetResolverInstance(assembly, "TempProject.Generated.Resolvers.TempProjectResolver")));
// Build `{ "A": -1 }`
var seq = new Sequence<byte>();

Просмотреть файл

@ -0,0 +1,22 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Reflection;
namespace MessagePack.Generator.Tests
{
internal static class TestUtilities
{
/// <summary>
/// Fetches the static instance of the named resolver, by its <see langword="public" /> <see langword="static"/> <c>Instance</c> property.
/// </summary>
/// <param name="assembly">The assembly to retrieve the resolver from.</param>
/// <param name="name">The full name of the resolver.</param>
/// <returns>The resolver.</returns>
internal static IFormatterResolver GetResolverInstance(Assembly assembly, string name)
{
var resolverType = assembly.GetType(name);
return (IFormatterResolver)resolverType.GetField("Instance", BindingFlags.Static | BindingFlags.Public).GetValue(null);
}
}
}