Skip to content

Commit

Permalink
Changed JsonConverterCtorAttribute to use type parameter instead of g…
Browse files Browse the repository at this point in the history
…eneric parameter to support .net framework
  • Loading branch information
JKorf committed Dec 8, 2024
1 parent 591c1dd commit 8260c26
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,25 @@ namespace CryptoExchange.Net.Converters.SystemTextJson
/// <summary>
/// Attribute for allowing specifying a JsonConverter with constructor parameters
/// </summary>
/// <typeparam name="T"></typeparam>
[AttributeUsage(AttributeTargets.Property)]
public class JsonConverterCtorAttribute<T> : JsonConverterAttribute where T : JsonConverter
public class JsonConverterCtorAttribute : JsonConverterAttribute
{
private readonly object[] _parameters;
private readonly Type _type;

/// <summary>
/// ctor
/// </summary>
public JsonConverterCtorAttribute(params object[] parameters) => _parameters = parameters;
public JsonConverterCtorAttribute(Type type, params object[] parameters)
{
_type = type;
_parameters = parameters;
}

/// <inheritdoc />
public override JsonConverter CreateConverter(Type typeToConvert)
{
return (T)Activator.CreateInstance(typeof(T), _parameters);
return (JsonConverter)Activator.CreateInstance(_type, _parameters);
}
}

Expand Down

0 comments on commit 8260c26

Please sign in to comment.