Created
June 3, 2019 18:37
-
-
Save fdrobidoux/fbcae4a1f2bfc475763d94ce7abab2a3 to your computer and use it in GitHub Desktop.
Dumb rectangle extension I wasted time on.
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
using Microsoft.Xna.Framework; | |
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace MonoTycoon.Core.Physics | |
{ | |
public static class RectangleExtensions | |
{ | |
private const string BASE_FORMAT_STR = "{0} {{ {1} }}"; | |
private const string PROP_FORMAT_STR = "{0}: {1}"; | |
public static string ToString(this Rectangle thisRect) | |
{ | |
string output = ""; | |
var liste = new Dictionary<string, Func<object>> { | |
{ "X", () => thisRect.X }, | |
{ "Y", () => thisRect.Y }, | |
{ "Width", () => thisRect.Width }, | |
{ "Height", () => thisRect.Height } | |
}; | |
var enumerator = liste.GetEnumerator(); | |
enumerator.MoveNext(); | |
for (var i = enumerator.Current; enumerator.MoveNext(); i = enumerator.Current) | |
{ | |
if (output.Length > 0) | |
output += "; "; | |
output += string.Format(PROP_FORMAT_STR, i.Key, i.Value.Invoke()); | |
} | |
return string.Format(BASE_FORMAT_STR, output); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment