Skip to content

Commit

Permalink
Merge pull request #7916 from abpframework/cotur/api-scripting
Browse files Browse the repository at this point in the history
PropertyNameGenerator moved to static class
  • Loading branch information
hikalkan committed Mar 2, 2021
2 parents 3b633f6 + dc95eab commit c4b48bd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static PropertyApiDescriptionModel Create(PropertyInfo propertyInfo)
return new PropertyApiDescriptionModel
{
Name = propertyInfo.Name,
JsonName = AbpApiProxyScriptingOptions.PropertyNameGenerator.Invoke(propertyInfo),
JsonName = AbpApiProxyScriptingConfiguration.PropertyNameGenerator.Invoke(propertyInfo),
Type = ApiTypeNameHelper.GetTypeName(propertyInfo.PropertyType),
TypeSimple = ApiTypeNameHelper.GetSimpleTypeName(propertyInfo.PropertyType),
IsRequired = propertyInfo.IsDefined(typeof(RequiredAttribute), true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Reflection;

namespace Volo.Abp.Http.ProxyScripting.Configuration
{
public static class AbpApiProxyScriptingConfiguration
{
public static Func<PropertyInfo, string> PropertyNameGenerator { get; set; }

static AbpApiProxyScriptingConfiguration()
{
PropertyNameGenerator = propertyInfo =>
{
var jsonPropertyNameAttribute = propertyInfo.GetSingleAttributeOrNull<System.Text.Json.Serialization.JsonPropertyNameAttribute>(true);
if (jsonPropertyNameAttribute != null)
{
return jsonPropertyNameAttribute.Name;
}
var jsonPropertyAttribute = propertyInfo.GetSingleAttributeOrNull<Newtonsoft.Json.JsonPropertyAttribute>(true);
if (jsonPropertyAttribute != null)
{
return jsonPropertyAttribute.PropertyName;
}
return null;
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
using System;
using System.Collections.Generic;
using System.Reflection;

namespace Volo.Abp.Http.ProxyScripting.Configuration
{
public class AbpApiProxyScriptingOptions
{
public IDictionary<string, Type> Generators { get; }

public static Func<PropertyInfo, string> PropertyNameGenerator { get; set; }

static AbpApiProxyScriptingOptions()
{
PropertyNameGenerator = propertyInfo =>
{
var jsonPropertyNameAttribute = propertyInfo.GetSingleAttributeOrNull<System.Text.Json.Serialization.JsonPropertyNameAttribute>(true);
if (jsonPropertyNameAttribute != null)
{
return jsonPropertyNameAttribute.Name;
}
var jsonPropertyAttribute = propertyInfo.GetSingleAttributeOrNull<Newtonsoft.Json.JsonPropertyAttribute>(true);
if (jsonPropertyAttribute != null)
{
return jsonPropertyAttribute.PropertyName;
}
return null;
};
}

public AbpApiProxyScriptingOptions()
{
Generators = new Dictionary<string, Type>();
Expand Down

0 comments on commit c4b48bd

Please sign in to comment.