Skip to content

A collection of Magic: The Gathering related data and classes

License

Notifications You must be signed in to change notification settings

Greven145/MTG.Objects

Repository files navigation

MTG.Objects

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

MTG.Objects CI/CD Quality Gate Status

How to install

Instructions can be found on the NuGet page for this repository.

Generator project

The generator project will download data from MTGJson and create classes that can be used like enums for all the various MTG values.

Samples

Deck Parsing

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);

Value Objects

Edition

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)

MultiverseId

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')

About

A collection of Magic: The Gathering related data and classes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published