mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.9 KiB
63 lines
1.9 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace Squidex.Infrastructure
|
|
{
|
|
public sealed class RefToken : IEquatable<RefToken>
|
|
{
|
|
public string Type { get; }
|
|
|
|
public string Identifier { get; }
|
|
|
|
public RefToken(string type, string identifier)
|
|
{
|
|
Guard.NotNullOrEmpty(type, nameof(type));
|
|
Guard.NotNullOrEmpty(identifier, nameof(identifier));
|
|
|
|
Type = type.ToLowerInvariant();
|
|
|
|
Identifier = identifier;
|
|
}
|
|
|
|
public static RefToken Parse(string input)
|
|
{
|
|
Guard.NotNullOrEmpty(input, nameof(input));
|
|
|
|
var parts = input.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
if (parts.Length < 2)
|
|
{
|
|
throw new ArgumentException("Input must have more than 2 parts divided by colon.", nameof(input));
|
|
}
|
|
|
|
return new RefToken(parts[0], string.Join(":", parts.Skip(1)));
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{Type}:{Identifier}";
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return Equals(obj as RefToken);
|
|
}
|
|
|
|
public bool Equals(RefToken other)
|
|
{
|
|
return other != null && (ReferenceEquals(this, other) || (Type.Equals(other.Type) && Identifier.Equals(other.Identifier)));
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return (Type.GetHashCode() * 397) ^ Identifier.GetHashCode();
|
|
}
|
|
}
|
|
}
|
|
|