Browse Source

Merge branch 'dev' of https://github.com/abpframework/abp into dev

pull/23619/head
Alper Ebiçoğlu 1 year ago
parent
commit
ceeeaf519e
  1. 17
      docs/en/modules/cms-kit/index.md
  2. 31
      framework/src/Volo.Abp.Core/Volo/Abp/Reflection/TypeHelper.cs
  3. 31
      framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs

17
docs/en/modules/cms-kit/index.md

@ -72,6 +72,23 @@ CMS kit packages are designed for various usage scenarios. If you check the [CMS
- `Volo.CmsKit.Public.*` packages contain the functionalities used in public websites where users read blog posts or leave comments. - `Volo.CmsKit.Public.*` packages contain the functionalities used in public websites where users read blog posts or leave comments.
- `Volo.CmsKit.*` (without Admin/Public suffix) packages are called as unified packages. Unified packages are shortcuts for adding Admin & Public packages (of the related layer) separately. If you have a single application for administration and public web site, you can use these packages. - `Volo.CmsKit.*` (without Admin/Public suffix) packages are called as unified packages. Unified packages are shortcuts for adding Admin & Public packages (of the related layer) separately. If you have a single application for administration and public web site, you can use these packages.
## Integrating Public and Admin Packages in a Unified Application
If you are using a single application for both admin and public web site, it's important to configure the global layout settings appropriately. By default, the layout is set for a **Public Website**, which is suitable for public-facing pages. However, when your application serves both admin and public pages, you should explicitly set the global layout for all CMS Kit pages.
To do this, add a `_ViewStart.cshtml` file to your web project at `/Pages/Public/CmsKit/_ViewStart.cshtml` and configure the layout as shown below:
```html
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@inject IThemeManager ThemeManager
@{
// default: GetPublicLayout()
Layout = ThemeManager.CurrentTheme.GetApplicationLayout();
}
```
> The `_ViewStart.cshtml` file is used to set the layout for all pages in the `CmsKit` folder.
## Internals ## Internals
### Table / collection prefix & schema ### Table / collection prefix & schema

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

@ -80,6 +80,37 @@ public static class TypeHelper
return false; return false;
} }
public static TProperty? ChangeTypePrimitiveExtended<TProperty>(object? value)
{
if (value == null)
{
return default;
}
if (IsPrimitiveExtended(typeof(TProperty), includeEnums: true))
{
var conversionType = typeof(TProperty);
if (IsNullable(conversionType))
{
conversionType = conversionType.GetFirstGenericArgumentIfNullable();
}
if (conversionType == typeof(Guid))
{
return (TProperty)TypeDescriptor.GetConverter(conversionType).ConvertFromInvariantString(value.ToString()!)!;
}
if (conversionType.IsEnum)
{
return (TProperty)Enum.Parse(conversionType, value.ToString()!);
}
return (TProperty)Convert.ChangeType(value, conversionType, CultureInfo.InvariantCulture);
}
throw new AbpException("ChangeTypePrimitiveExtended<TProperty> does not support non-primitive types. Use non-generic GetProperty method and handle type casting manually.");
}
public static bool IsNullable(Type type) public static bool IsNullable(Type type)
{ {
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);

31
framework/src/Volo.Abp.ObjectExtending/Volo/Abp/Data/HasExtraPropertiesExtensions.cs

@ -26,34 +26,9 @@ public static class HasExtraPropertiesExtensions
public static TProperty? GetProperty<TProperty>(this IHasExtraProperties source, string name, TProperty? defaultValue = default) public static TProperty? GetProperty<TProperty>(this IHasExtraProperties source, string name, TProperty? defaultValue = default)
{ {
var value = source.GetProperty(name); return TypeHelper.ChangeTypePrimitiveExtended<TProperty>(
if (value == null) source.GetProperty(name, (object?) defaultValue)
{ ) ?? defaultValue;
return defaultValue;
}
if (TypeHelper.IsPrimitiveExtended(typeof(TProperty), includeEnums: true))
{
var conversionType = typeof(TProperty);
if (TypeHelper.IsNullable(conversionType))
{
conversionType = conversionType.GetFirstGenericArgumentIfNullable();
}
if (conversionType == typeof(Guid))
{
return (TProperty)TypeDescriptor.GetConverter(conversionType).ConvertFromInvariantString(value.ToString()!)!;
}
if (conversionType.IsEnum)
{
return (TProperty)Enum.Parse(conversionType, value.ToString()!);
}
return (TProperty)Convert.ChangeType(value, conversionType, CultureInfo.InvariantCulture);
}
throw new AbpException("GetProperty<TProperty> does not support non-primitive types. Use non-generic GetProperty method and handle type casting manually.");
} }
public static TSource SetProperty<TSource>( public static TSource SetProperty<TSource>(

Loading…
Cancel
Save