Browse Source

Added ObjectExtensions to ApplicationConfigurationDto

pull/3834/head
Halil İbrahim Kalkan 7 years ago
parent
commit
e9fc742b7e
  1. 3
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs
  2. 90
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs
  3. 7
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ICachedObjectExtensionsDtoService.cs
  4. 37
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizedDisplayNameDto.cs
  5. 11
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtensionDto.cs
  6. 36
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyAttributeDto.cs
  7. 19
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs
  8. 12
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs
  9. 10
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs
  10. 10
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs
  11. 12
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionConfigurationDto.cs
  12. 11
      framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionsDto.cs
  13. 10
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs
  14. 2
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs
  15. 118
      framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs
  16. 5
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/MethodParameterApiDescriptionModel.cs
  17. 127
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModelingTypeHelper.cs
  18. 5
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs
  19. 12
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs
  20. 5
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ReturnValueApiDescriptionModel.cs
  21. 3
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/TypeApiDescriptionModel.cs
  22. 2
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs
  23. 2
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs
  24. 2
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs

3
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ApplicationConfigurationDto.cs

@ -1,4 +1,5 @@
using System; using System;
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending;
using Volo.Abp.AspNetCore.Mvc.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.MultiTenancy;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations
@ -19,5 +20,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations
public MultiTenancyInfoDto MultiTenancy { get; set; } public MultiTenancyInfoDto MultiTenancy { get; set; }
public CurrentTenantDto CurrentTenant { get; set; } public CurrentTenantDto CurrentTenant { get; set; }
public ObjectExtensionsDto ObjectExtensions { get; set; }
} }
} }

90
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/CachedObjectExtensionsDtoService.cs

@ -0,0 +1,90 @@
using System.Collections.Generic;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Reflection;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending
{
public class CachedObjectExtensionsDtoService : ICachedObjectExtensionsDtoService, ISingletonDependency
{
private volatile ObjectExtensionsDto _cachedValue;
private readonly object _syncLock = new object();
public virtual ObjectExtensionsDto Get()
{
if (_cachedValue == null)
{
lock (_syncLock)
{
if (_cachedValue == null)
{
_cachedValue = GenerateCacheValue();
}
}
}
return _cachedValue;
}
protected virtual ObjectExtensionsDto GenerateCacheValue()
{
var objectExtensionsDto = new ObjectExtensionsDto
{
Modules = new Dictionary<string, ModuleExtensionDto>()
};
foreach (var moduleConfig in ObjectExtensionManager.Instance.Modules)
{
var moduleExtensionDto = objectExtensionsDto.Modules[moduleConfig.Key] = new ModuleExtensionDto
{
Objects = new Dictionary<string, ModuleObjectExtensionDto>()
};
foreach (var objectConfig in moduleConfig.Value)
{
var moduleObjectExtensionDto = moduleExtensionDto.Objects[objectConfig.Key] =
new ModuleObjectExtensionDto
{
ExtraProperties = new Dictionary<string, ModuleObjectExtraPropertyExtensionDto>()
};
foreach (var propertyConfig in objectConfig.Value.GetProperties())
{
var propertyExtensionDto = moduleObjectExtensionDto.ExtraProperties[propertyConfig.Name] =
new ModuleObjectExtraPropertyExtensionDto
{
Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(propertyConfig.Type),
TypeSimple = TypeHelper.GetSimplifiedName(propertyConfig.Type),
Attributes = new List<ModuleObjectExtraPropertyAttributeDto>(),
DisplayName = LocalizedDisplayNameDto.CreateOrNull(propertyConfig.DisplayName),
Ui = new ModuleObjectExtraPropertyUiExtensionDto
{
CreateForm = new ModuleObjectExtraPropertyUiFormExtensionDto
{
Visible = true
},
EditForm = new ModuleObjectExtraPropertyUiFormExtensionDto
{
Visible = true
},
Table = new ModuleObjectExtraPropertyUiTableExtensionDto
{
Visible = true
}
}
};
foreach (var attribute in propertyConfig.Attributes)
{
propertyExtensionDto.Attributes.Add(
ModuleObjectExtraPropertyAttributeDto.Create(attribute)
);
}
}
}
}
return objectExtensionsDto;
}
}
}

7
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ICachedObjectExtensionsDtoService.cs

@ -0,0 +1,7 @@
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending
{
public interface ICachedObjectExtensionsDtoService
{
ObjectExtensionsDto Get();
}
}

37
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/LocalizedDisplayNameDto.cs

@ -0,0 +1,37 @@
using System;
using JetBrains.Annotations;
using Volo.Abp.Localization;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending
{
[Serializable]
public class LocalizedDisplayNameDto
{
public string Name { get; set; }
public string Resource { get; set; }
[CanBeNull]
public static LocalizedDisplayNameDto CreateOrNull(ILocalizableString localizableString)
{
if (localizableString is LocalizableString localizableStringInstance)
{
return new LocalizedDisplayNameDto
{
Name = localizableStringInstance.Name,
Resource = LocalizationResourceNameAttribute.GetName(localizableStringInstance.ResourceType)
};
}
if (localizableString is FixedLocalizableString fixedLocalizableString)
{
return new LocalizedDisplayNameDto
{
Name = fixedLocalizableString.Value,
};
}
return null;
}
}
}

11
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtensionDto.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending
{
[Serializable]
public class ModuleObjectExtensionDto
{
public Dictionary<string, ModuleObjectExtraPropertyExtensionDto> ExtraProperties { get; set; }
}
}

36
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyAttributeDto.cs

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Reflection;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending
{
[Serializable]
public class ModuleObjectExtraPropertyAttributeDto
{
public string Type { get; set; }
public string TypeSimple { get; set; }
public Dictionary<string, object> Configuration { get; set; }
public static ModuleObjectExtraPropertyAttributeDto Create(Attribute attribute)
{
var attributeType = attribute.GetType();
var dto = new ModuleObjectExtraPropertyAttributeDto
{
Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(attributeType),
TypeSimple = TypeHelper.GetSimplifiedName(attributeType),
Configuration = new Dictionary<string, object>()
};
if (attribute is StringLengthAttribute stringLengthAttribute)
{
dto.Configuration["MaximumLength"] = stringLengthAttribute.MaximumLength;
dto.Configuration["MinimumLength"] = stringLengthAttribute.MinimumLength;
}
//TODO: Others!
return dto;
}
}
}

19
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyExtensionDto.cs

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending
{
[Serializable]
public class ModuleObjectExtraPropertyExtensionDto
{
public string Type { get; set; }
public string TypeSimple { get; set; }
public LocalizedDisplayNameDto DisplayName { get; set; }
public ModuleObjectExtraPropertyUiExtensionDto Ui { get; set; }
public List<ModuleObjectExtraPropertyAttributeDto> Attributes { get; set; }
}
}

12
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiExtensionDto.cs

@ -0,0 +1,12 @@
using System;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending
{
[Serializable]
public class ModuleObjectExtraPropertyUiExtensionDto
{
public ModuleObjectExtraPropertyUiTableExtensionDto Table { get; set; }
public ModuleObjectExtraPropertyUiFormExtensionDto CreateForm { get; set; }
public ModuleObjectExtraPropertyUiFormExtensionDto EditForm { get; set; }
}
}

10
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiFormExtensionDto.cs

@ -0,0 +1,10 @@
using System;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending
{
[Serializable]
public class ModuleObjectExtraPropertyUiFormExtensionDto
{
public bool Visible { get; set; }
}
}

10
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ModuleObjectExtraPropertyUiTableExtensionDto.cs

@ -0,0 +1,10 @@
using System;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending
{
[Serializable]
public class ModuleObjectExtraPropertyUiTableExtensionDto
{
public bool Visible { get; set; }
}
}

12
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionConfigurationDto.cs

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending
{
[Serializable]
public class ModuleExtensionDto
{
public Dictionary<string, ModuleObjectExtensionDto> Objects { get; set; }
}
}

11
framework/src/Volo.Abp.AspNetCore.Mvc.Contracts/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/ObjectExtending/ObjectExtensionsDto.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending
{
[Serializable]
public class ObjectExtensionsDto
{
public Dictionary<string, ModuleExtensionDto> Modules { get; set; }
}
}

10
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApplicationConfigurations/AbpApplicationConfigurationAppService.cs

@ -8,6 +8,7 @@ using System.Globalization;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations.ObjectExtending;
using Volo.Abp.AspNetCore.Mvc.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.MultiTenancy;
using Volo.Abp.Authorization; using Volo.Abp.Authorization;
using Volo.Abp.Features; using Volo.Abp.Features;
@ -30,6 +31,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations
private readonly ISettingDefinitionManager _settingDefinitionManager; private readonly ISettingDefinitionManager _settingDefinitionManager;
private readonly IFeatureDefinitionManager _featureDefinitionManager; private readonly IFeatureDefinitionManager _featureDefinitionManager;
private readonly ILanguageProvider _languageProvider; private readonly ILanguageProvider _languageProvider;
private readonly ICachedObjectExtensionsDtoService _cachedObjectExtensionsDtoService;
public AbpApplicationConfigurationAppService( public AbpApplicationConfigurationAppService(
IOptions<AbpLocalizationOptions> localizationOptions, IOptions<AbpLocalizationOptions> localizationOptions,
@ -41,7 +43,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations
ISettingProvider settingProvider, ISettingProvider settingProvider,
ISettingDefinitionManager settingDefinitionManager, ISettingDefinitionManager settingDefinitionManager,
IFeatureDefinitionManager featureDefinitionManager, IFeatureDefinitionManager featureDefinitionManager,
ILanguageProvider languageProvider) ILanguageProvider languageProvider,
ICachedObjectExtensionsDtoService cachedObjectExtensionsDtoService)
{ {
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
_abpAuthorizationPolicyProvider = abpAuthorizationPolicyProvider; _abpAuthorizationPolicyProvider = abpAuthorizationPolicyProvider;
@ -51,6 +54,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations
_settingDefinitionManager = settingDefinitionManager; _settingDefinitionManager = settingDefinitionManager;
_featureDefinitionManager = featureDefinitionManager; _featureDefinitionManager = featureDefinitionManager;
_languageProvider = languageProvider; _languageProvider = languageProvider;
_cachedObjectExtensionsDtoService = cachedObjectExtensionsDtoService;
_localizationOptions = localizationOptions.Value; _localizationOptions = localizationOptions.Value;
_multiTenancyOptions = multiTenancyOptions.Value; _multiTenancyOptions = multiTenancyOptions.Value;
} }
@ -67,8 +71,8 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations
CurrentUser = GetCurrentUser(), CurrentUser = GetCurrentUser(),
Setting = await GetSettingConfigAsync(), Setting = await GetSettingConfigAsync(),
MultiTenancy = GetMultiTenancy(), MultiTenancy = GetMultiTenancy(),
CurrentTenant = GetCurrentTenant() CurrentTenant = GetCurrentTenant(),
ObjectExtensions = _cachedObjectExtensionsDtoService.Get()
}; };
} }

2
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs

@ -206,7 +206,7 @@ namespace Volo.Abp.AspNetCore.Mvc
/* TODO: Add interfaces /* TODO: Add interfaces
*/ */
var typeName = ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(type); var typeName = TypeHelper.GetFullNameHandlingNullableAndGenerics(type);
if (applicationModel.Types.ContainsKey(typeName)) if (applicationModel.Types.ContainsKey(typeName))
{ {

118
framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using JetBrains.Annotations;
namespace Volo.Abp.Reflection namespace Volo.Abp.Reflection
{ {
@ -146,5 +147,122 @@ namespace Volo.Abp.Reflection
return null; return null;
} }
public static string GetFullNameHandlingNullableAndGenerics([NotNull] Type type)
{
Check.NotNull(type, nameof(type));
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
return type.GenericTypeArguments[0].FullName + "?";
}
if (type.IsGenericType)
{
var genericType = type.GetGenericTypeDefinition();
return $"{genericType.FullName.Left(genericType.FullName.IndexOf('`'))}<{type.GenericTypeArguments.Select(GetFullNameHandlingNullableAndGenerics).JoinAsString(",")}>";
}
return type.FullName;
}
public static string GetSimplifiedName([NotNull] Type type)
{
Check.NotNull(type, nameof(type));
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
return GetSimplifiedName(type.GenericTypeArguments[0]) + "?";
}
if (type.IsGenericType)
{
var genericType = type.GetGenericTypeDefinition();
return $"{genericType.FullName.Left(genericType.FullName.IndexOf('`'))}<{type.GenericTypeArguments.Select(GetSimplifiedName).JoinAsString(",")}>";
}
if (type == typeof(string))
{
return "string";
}
else if (type == typeof(int))
{
return "number";
}
else if (type == typeof(long))
{
return "number";
}
else if (type == typeof(bool))
{
return "boolean";
}
else if (type == typeof(char))
{
return "string";
}
else if (type == typeof(double))
{
return "number";
}
else if (type == typeof(float))
{
return "number";
}
else if (type == typeof(decimal))
{
return "number";
}
else if (type == typeof(DateTime))
{
return "string";
}
else if (type == typeof(DateTimeOffset))
{
return "string";
}
else if (type == typeof(TimeSpan))
{
return "string";
}
else if (type == typeof(Guid))
{
return "string";
}
else if (type == typeof(byte))
{
return "number";
}
else if (type == typeof(sbyte))
{
return "number";
}
else if (type == typeof(short))
{
return "number";
}
else if (type == typeof(ushort))
{
return "number";
}
else if (type == typeof(uint))
{
return "number";
}
else if (type == typeof(ulong))
{
return "number";
}
else if (type == typeof(IntPtr))
{
return "number";
}
else if (type == typeof(UIntPtr))
{
return "number";
}
return type.FullName;
}
} }
} }

5
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/MethodParameterApiDescriptionModel.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Reflection; using System.Reflection;
using Volo.Abp.Reflection;
namespace Volo.Abp.Http.Modeling namespace Volo.Abp.Http.Modeling
{ {
@ -29,8 +30,8 @@ namespace Volo.Abp.Http.Modeling
{ {
Name = parameterInfo.Name, Name = parameterInfo.Name,
TypeAsString = parameterInfo.ParameterType.GetFullNameWithAssemblyName(), TypeAsString = parameterInfo.ParameterType.GetFullNameWithAssemblyName(),
Type = parameterInfo.ParameterType != null ? ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(parameterInfo.ParameterType) : null, Type = parameterInfo.ParameterType != null ? TypeHelper.GetFullNameHandlingNullableAndGenerics(parameterInfo.ParameterType) : null,
TypeSimple = parameterInfo.ParameterType != null ? ModelingTypeHelper.GetSimplifiedName(parameterInfo.ParameterType) : null, TypeSimple = parameterInfo.ParameterType != null ? TypeHelper.GetSimplifiedName(parameterInfo.ParameterType) : null,
IsOptional = parameterInfo.IsOptional, IsOptional = parameterInfo.IsOptional,
DefaultValue = parameterInfo.HasDefaultValue ? parameterInfo.DefaultValue : null DefaultValue = parameterInfo.HasDefaultValue ? parameterInfo.DefaultValue : null
}; };

127
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModelingTypeHelper.cs

@ -1,127 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
namespace Volo.Abp.Http.Modeling
{
public static class ModelingTypeHelper
{
public static string GetFullNameHandlingNullableAndGenerics([NotNull] Type type)
{
Check.NotNull(type, nameof(type));
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
return type.GenericTypeArguments[0].FullName + "?";
}
if (type.IsGenericType)
{
var genericType = type.GetGenericTypeDefinition();
return $"{genericType.FullName.Left(genericType.FullName.IndexOf('`'))}<{type.GenericTypeArguments.Select(GetFullNameHandlingNullableAndGenerics).JoinAsString(",")}>";
}
return type.FullName;
}
public static string GetSimplifiedName([NotNull] Type type)
{
Check.NotNull(type, nameof(type));
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
return GetSimplifiedName(type.GenericTypeArguments[0]) + "?";
}
if (type.IsGenericType)
{
var genericType = type.GetGenericTypeDefinition();
return $"{genericType.FullName.Left(genericType.FullName.IndexOf('`'))}<{type.GenericTypeArguments.Select(GetSimplifiedName).JoinAsString(",")}>";
}
if (type == typeof(string))
{
return "string";
}
else if (type == typeof(int))
{
return "number";
}
else if (type == typeof(long))
{
return "number";
}
else if (type == typeof(bool))
{
return "boolean";
}
else if (type == typeof(char))
{
return "string";
}
else if (type == typeof(double))
{
return "number";
}
else if (type == typeof(float))
{
return "number";
}
else if (type == typeof(decimal))
{
return "number";
}
else if (type == typeof(DateTime))
{
return "string";
}
else if (type == typeof(DateTimeOffset))
{
return "string";
}
else if (type == typeof(TimeSpan))
{
return "string";
}
else if (type == typeof(Guid))
{
return "string";
}
else if (type == typeof(byte))
{
return "number";
}
else if (type == typeof(sbyte))
{
return "number";
}
else if (type == typeof(short))
{
return "number";
}
else if (type == typeof(ushort))
{
return "number";
}
else if (type == typeof(uint))
{
return "number";
}
else if (type == typeof(ulong))
{
return "number";
}
else if (type == typeof(IntPtr))
{
return "number";
}
else if (type == typeof(UIntPtr))
{
return "number";
}
return type.FullName;
}
}
}

5
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ParameterApiDescriptionModel.cs

@ -1,4 +1,5 @@
using System; using System;
using Volo.Abp.Reflection;
namespace Volo.Abp.Http.Modeling namespace Volo.Abp.Http.Modeling
{ {
@ -34,8 +35,8 @@ namespace Volo.Abp.Http.Modeling
{ {
Name = name, Name = name,
NameOnMethod = nameOnMethod, NameOnMethod = nameOnMethod,
Type = type != null ? ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(type) : null, Type = type != null ? TypeHelper.GetFullNameHandlingNullableAndGenerics(type) : null,
TypeSimple = type != null ? ModelingTypeHelper.GetSimplifiedName(type) : null, TypeSimple = type != null ? TypeHelper.GetSimplifiedName(type) : null,
IsOptional = isOptional, IsOptional = isOptional,
DefaultValue = defaultValue, DefaultValue = defaultValue,
ConstraintTypes = constraintTypes, ConstraintTypes = constraintTypes,

12
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs

@ -21,18 +21,18 @@ namespace Volo.Abp.Http.Modeling
if (TypeHelper.IsEnumerable(propertyInfo.PropertyType, out var itemType, includePrimitives: false)) if (TypeHelper.IsEnumerable(propertyInfo.PropertyType, out var itemType, includePrimitives: false))
{ {
typeName = $"[{ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(itemType)}]"; typeName = $"[{TypeHelper.GetFullNameHandlingNullableAndGenerics(itemType)}]";
simpleTypeName = $"[{ModelingTypeHelper.GetSimplifiedName(itemType)}]"; simpleTypeName = $"[{TypeHelper.GetSimplifiedName(itemType)}]";
} }
else if (TypeHelper.IsDictionary(propertyInfo.PropertyType, out var keyType, out var valueType)) else if (TypeHelper.IsDictionary(propertyInfo.PropertyType, out var keyType, out var valueType))
{ {
typeName = $"{{{ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(keyType)}:{ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(valueType)}}}"; typeName = $"{{{TypeHelper.GetFullNameHandlingNullableAndGenerics(keyType)}:{TypeHelper.GetFullNameHandlingNullableAndGenerics(valueType)}}}";
simpleTypeName = $"{{{ModelingTypeHelper.GetSimplifiedName(keyType)}:{ModelingTypeHelper.GetSimplifiedName(valueType)}}}"; simpleTypeName = $"{{{TypeHelper.GetSimplifiedName(keyType)}:{TypeHelper.GetSimplifiedName(valueType)}}}";
} }
else else
{ {
typeName = ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(propertyInfo.PropertyType); typeName = TypeHelper.GetFullNameHandlingNullableAndGenerics(propertyInfo.PropertyType);
simpleTypeName = ModelingTypeHelper.GetSimplifiedName(propertyInfo.PropertyType); simpleTypeName = TypeHelper.GetSimplifiedName(propertyInfo.PropertyType);
} }
return new PropertyApiDescriptionModel return new PropertyApiDescriptionModel

5
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ReturnValueApiDescriptionModel.cs

@ -1,4 +1,5 @@
using System; using System;
using Volo.Abp.Reflection;
using Volo.Abp.Threading; using Volo.Abp.Threading;
namespace Volo.Abp.Http.Modeling namespace Volo.Abp.Http.Modeling
@ -21,8 +22,8 @@ namespace Volo.Abp.Http.Modeling
return new ReturnValueApiDescriptionModel return new ReturnValueApiDescriptionModel
{ {
Type = ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(unwrappedType), Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(unwrappedType),
TypeSimple = ModelingTypeHelper.GetSimplifiedName(unwrappedType) TypeSimple = TypeHelper.GetSimplifiedName(unwrappedType)
}; };
} }
} }

3
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/TypeApiDescriptionModel.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Linq; using System.Linq;
using Volo.Abp.Reflection;
namespace Volo.Abp.Http.Modeling namespace Volo.Abp.Http.Modeling
{ {
@ -32,7 +33,7 @@ namespace Volo.Abp.Http.Modeling
var typeModel = new TypeApiDescriptionModel var typeModel = new TypeApiDescriptionModel
{ {
IsEnum = type.IsEnum, IsEnum = type.IsEnum,
BaseType = baseType != null ? ModelingTypeHelper.GetFullNameHandlingNullableAndGenerics(baseType) : null BaseType = baseType != null ? TypeHelper.GetFullNameHandlingNullableAndGenerics(baseType) : null
}; };
if (typeModel.IsEnum) if (typeModel.IsEnum)

2
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfiguration.cs

@ -2,7 +2,7 @@
namespace Volo.Abp.ObjectExtending namespace Volo.Abp.ObjectExtending
{ {
public class ModuleObjectExtensionConfiguration : Dictionary<string, object> public class ModuleObjectExtensionConfiguration : Dictionary<string, ModuleEntityObjectExtensionConfiguration>
{ {
} }

2
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationDictionary.cs

@ -2,7 +2,7 @@
namespace Volo.Abp.ObjectExtending namespace Volo.Abp.ObjectExtending
{ {
public class ModuleObjectExtensionConfigurationDictionary : Dictionary<string, object> public class ModuleObjectExtensionConfigurationDictionary : Dictionary<string, ModuleObjectExtensionConfiguration>
{ {
} }

2
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/ObjectExtending/ModuleObjectExtensionConfigurationExtensions.cs

@ -14,7 +14,7 @@ namespace Volo.Abp.ObjectExtending
var configuration = objectConfiguration.GetOrAdd( var configuration = objectConfiguration.GetOrAdd(
objectName, objectName,
() => new ModuleEntityObjectExtensionConfiguration() () => new ModuleEntityObjectExtensionConfiguration()
) as ModuleEntityObjectExtensionConfiguration; );
configureAction(configuration); configureAction(configuration);

Loading…
Cancel
Save