CloudBuilder/CloudBuilder.Gui/KryptonButtonExtensions.cs
owenchen 1c0c83af5f ow
2026-05-12 10:09:31 +08:00

38 lines
1.4 KiB
C#

using CloudBuilder;
using CloudBuilder.Gui;
using Microsoft.AspNetCore.Authorization;
namespace Krypton.Toolkit
{
public static class KryptonButtonExtensions
{
public static void Set(this KryptonButton kryptonButton,
string permissionName,
Operate permissionMode)
{
GetProvider().SetCustomAttribute(kryptonButton, permissionName, permissionMode);
}
public static void Set(this KryptonButton kryptonButton, string permissionName, string dependentDetailName, Operate permissionMode)
{
GetProvider().SetCustomAttribute(kryptonButton, permissionName, dependentDetailName, permissionMode);
}
public static void Set(this KryptonButton kryptonButton, string permissionName, string dependentDetailName)
{
GetProvider().SetCustomAttribute(kryptonButton, permissionName, dependentDetailName);
}
public static BindingContextCustomAttribute GetCustomAttribute(this KryptonButton kryptonButton)
{
return GetProvider().GetCustomAttribute(kryptonButton);
}
private static BindingContextAttributeProvider GetProvider()
{
return ServiceHelper.GetService<BindingContextAttributeProvider>() ??
throw new InvalidOperationException("BindingContextAttributeProvider is not registered in the service GetProvider().");
}
}
}