Do not use extension method syntax
This commit is contained in:
Родитель
ab35db5b0a
Коммит
d0b140960c
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче