mirror of https://github.com/abpframework/abp.git
7 changed files with 107 additions and 28 deletions
@ -0,0 +1,24 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming |
||||
|
{ |
||||
|
public class ThemeDictionary : Dictionary<Type, ThemeInfo> |
||||
|
{ |
||||
|
public ThemeInfo Add<TTheme>() |
||||
|
where TTheme : ITheme |
||||
|
{ |
||||
|
return Add(typeof(TTheme)); |
||||
|
} |
||||
|
|
||||
|
public ThemeInfo Add(Type themeType) |
||||
|
{ |
||||
|
if (ContainsKey(themeType)) |
||||
|
{ |
||||
|
throw new AbpException("This theme is already added before: " + themeType.AssemblyQualifiedName); |
||||
|
} |
||||
|
|
||||
|
return this[themeType] = new ThemeInfo(themeType); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
using System; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming |
||||
|
{ |
||||
|
public class ThemeInfo |
||||
|
{ |
||||
|
public Type ThemeType { get; } |
||||
|
|
||||
|
public string Name { get; } |
||||
|
|
||||
|
public ThemeInfo([NotNull] Type themeType) |
||||
|
{ |
||||
|
Check.NotNull(themeType, nameof(themeType)); |
||||
|
|
||||
|
if (!typeof(ITheme).IsAssignableFrom(themeType)) |
||||
|
{ |
||||
|
throw new AbpException($"Given {nameof(themeType)} ({themeType.AssemblyQualifiedName}) should be type of {typeof(ITheme).AssemblyQualifiedName}"); |
||||
|
} |
||||
|
|
||||
|
ThemeType = themeType; |
||||
|
Name = ThemeNameAttribute.GetName(themeType); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming |
||||
|
{ |
||||
|
[AttributeUsage(AttributeTargets.Class)] |
||||
|
public class ThemeNameAttribute : Attribute |
||||
|
{ |
||||
|
public string Name { get; set; } |
||||
|
|
||||
|
public ThemeNameAttribute(string name) |
||||
|
{ |
||||
|
Name = name; |
||||
|
} |
||||
|
|
||||
|
public static string GetName(Type themeType) |
||||
|
{ |
||||
|
return themeType |
||||
|
.GetCustomAttributes(true) |
||||
|
.OfType<ThemeNameAttribute>() |
||||
|
.FirstOrDefault()?.Name ?? themeType.Name; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,14 +1,14 @@ |
|||||
using Volo.Abp.Collections; |
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Mvc.UI.Theming |
|
||||
{ |
{ |
||||
public class ThemingOptions |
public class ThemingOptions |
||||
{ |
{ |
||||
public TypeList<ITheme> Themes { get; } |
public ThemeDictionary Themes { get; } |
||||
|
|
||||
|
public string DefaultThemeName { get; set; } |
||||
|
|
||||
public ThemingOptions() |
public ThemingOptions() |
||||
{ |
{ |
||||
Themes = new TypeList<ITheme>(); |
Themes = new ThemeDictionary(); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue