mirror of https://github.com/abpframework/abp.git
Browse Source
Added the IKeyedObject interface to provide a standard way to retrieve object keys, including support for composite keys via KeyedObjectHelper. Updated IEntity, IEntityDto, and related DTOs to implement IKeyedObject, and refactored resource permission logic to use GetObjectKey for key retrieval. This change improves consistency and reliability in handling object keys across the framework.pull/24374/head
9 changed files with 81 additions and 9 deletions
@ -0,0 +1,6 @@ |
|||
namespace Volo.Abp; |
|||
|
|||
public interface IKeyedObject |
|||
{ |
|||
string? GetObjectKey(); |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Volo.Abp; |
|||
|
|||
public static class KeyedObjectHelper |
|||
{ |
|||
public static string EncodeCompositeKey(params object?[] keys) |
|||
{ |
|||
var raw = keys.JoinAsString("||"); |
|||
var bytes = Encoding.UTF8.GetBytes(raw); |
|||
var base64 = Convert.ToBase64String(bytes); |
|||
var base64Url = base64 |
|||
.Replace("+", "-") |
|||
.Replace("/", "_") |
|||
.TrimEnd('='); |
|||
|
|||
return base64Url; |
|||
} |
|||
|
|||
public static string DecodeCompositeKey(string encoded) |
|||
{ |
|||
var base64 = encoded |
|||
.Replace("-", "+") |
|||
.Replace("_", "/"); |
|||
|
|||
switch (encoded.Length % 4) |
|||
{ |
|||
case 2: base64 += "=="; break; |
|||
case 3: base64 += "="; break; |
|||
} |
|||
|
|||
var bytes = Convert.FromBase64String(base64); |
|||
var raw = Encoding.UTF8.GetString(bytes); |
|||
|
|||
return raw; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue