A collection of objects and utilities for working with Magic: The Gathering services and data. I would frequently have to write classes and objects when writing projects that worked with Magic cards, and have collected some here for ease of consumption and re-use
Instructions can be found on the NuGet page for this repository.
The generator project will download data from MTGJson and create classes that can be used like enums for all the various MTG values.
var deckName = "Tron";
var fileName = $"{deckName}.txt";
var filePath = "./path/to/deck/files";
var fileContents = await File.ReadAllLinesAsync(Path.Combine(filePath, fileName));
var (deck, errors) = Deck.Parse(fileContents, name);
You can use the Edition.TryParse()
static method to parse a set name or code into a complete object
var (successful, value) = Edition.TryParse("Kaldheim");
if ( successful ) {
Console.WriteLine(value);
}
Kaldheim (KHM)
var (successful, value) = Edition.TryParse("M11");
if ( successful ) {
Console.WriteLine(value);
}
Magic 2011 (M11)
You can use the MultiverseId.TryParse()
static method to parse an Id into a valid format
var id = (MultiverseId)12345;
Console.WriteLine(id.ToString());
12345
var id = (MultiverseId)(-321);
System.ArgumentException: Required input id cannot be negative. (Parameter 'id')