-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60dcd5c
commit c98e589
Showing
4 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace TrombLoader.CustomTracks; | ||
|
||
public class ExtraData | ||
{ | ||
private Identifier _identifier; | ||
private JObject _contents; | ||
|
||
public ExtraData(Identifier identifier, JObject contents) | ||
{ | ||
_identifier = identifier; | ||
_contents = contents; | ||
} | ||
|
||
public Identifier Identifier => _identifier; | ||
public JObject GetJsonObject() => _contents; | ||
public JToken this[string key] => _contents[key]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Text.RegularExpressions; | ||
using Newtonsoft.Json; | ||
|
||
namespace TrombLoader.CustomTracks; | ||
|
||
public class Identifier | ||
{ | ||
private static readonly Regex IdentifierRegex = new(@"^([a-zA-Z_-]+):([a-zA-Z0-9_-]+)$"); | ||
|
||
public string Namespace { get; } | ||
public string Path { get; } | ||
|
||
public Identifier(string @namespace, string path) | ||
{ | ||
Namespace = @namespace; | ||
Path = path; | ||
} | ||
|
||
[JsonConstructor] | ||
public Identifier(string identifier) | ||
{ | ||
var m = IdentifierRegex.Match(identifier); | ||
if (!m.Success) throw new ArgumentException("Invalid identifier string: " + identifier); | ||
|
||
Namespace = m.Captures[0].Value; | ||
Path = m.Captures[1].Value; | ||
} | ||
|
||
public override string ToString() => $"{Namespace}:{Path}"; | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
return (Namespace.GetHashCode() * 397) ^ Path.GetHashCode(); | ||
} | ||
} | ||
|
||
protected bool Equals(Identifier other) | ||
{ | ||
return Namespace == other.Namespace && Path == other.Path; | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) return false; | ||
if (ReferenceEquals(this, obj)) return true; | ||
if (obj.GetType() != this.GetType()) return false; | ||
return Equals((Identifier)obj); | ||
} | ||
|
||
public static Identifier Parse(string identifier) => new(identifier); | ||
} |