frostfs-sdk-csharp/src/FrostFS.SDK.Client/ApeRules/ChainTarget.cs
Pavel Gross 195854a45b [#30] Client: Add object model for Rules
Signed-off-by: Pavel Gross <p.gross@yadro.com>
2025-02-12 17:27:30 +03:00

63 lines
1.7 KiB
C#

using System;
using Frostfs.V2.Ape;
namespace FrostFS.SDK.Client;
public struct FrostFsChainTarget(FrostFsTargetType type, string name) : IEquatable<FrostFsChainTarget>
{
private ChainTarget? chainTarget;
public FrostFsTargetType Type { get; } = type;
public string Name { get; } = name;
internal ChainTarget GetChainTarget()
{
return chainTarget ??= new ChainTarget
{
Type = GetTargetType(Type),
Name = Name
};
}
private static TargetType GetTargetType(FrostFsTargetType type)
{
return type switch
{
FrostFsTargetType.Undefined => TargetType.Undefined,
FrostFsTargetType.Namespace => TargetType.Namespace,
FrostFsTargetType.Container => TargetType.Container,
FrostFsTargetType.User => TargetType.User,
FrostFsTargetType.Group => TargetType.Group,
_ => throw new ArgumentException("Unexpected value for TargetType", nameof(type)),
};
}
public override readonly bool Equals(object obj)
{
if (obj == null || obj is not FrostFsChainTarget)
return false;
return Equals((FrostFsChainTarget)obj);
}
public readonly bool Equals(FrostFsChainTarget other)
{
return Type == other.Type && Name.Equals(other.Name, StringComparison.Ordinal);
}
public override readonly int GetHashCode()
{
return Name.GetHashCode() ^ (int)Type;
}
public static bool operator ==(FrostFsChainTarget left, FrostFsChainTarget right)
{
return left.Equals(right);
}
public static bool operator !=(FrostFsChainTarget left, FrostFsChainTarget right)
{
return !(left == right);
}
}