Skip to content

Instantly share code, notes, and snippets.

View Turtlator's full-sized avatar

Brendan Graham Turtlator

View GitHub Profile
@Turtlator
Turtlator / SQLEnumTable.cs
Last active May 12, 2020 05:53
Create an SQL script for a table variable holding Enum values
public string EnumTable<T>() where T: Enum
{
var DeclareTable = $"DECLARE @{typeof(T).Name} TABLE ( Id INT, Value NVARCHAR(50) )\n";
var insert = $"INSERT INTO @{typeof(T).Name} (Id, Value)\nVALUES";
var values = Enum.GetValues(typeof(T))
.Cast<T>()
.Select(v => $"({Convert.ToInt32(v)}, '{v.ToString()}')");
return DeclareTable + insert + string.Join(",\r\n", values);
}
@Turtlator
Turtlator / gist:5362526
Created April 11, 2013 11:07
Testing genius
<TestMethod()>
Public Sub TestPushTooMany()
Dim stack As Stack(Of Double) = New Stack(Of Double)(1)
Try
stack.Push(123.456)
stack.Push(89.123)
Assert.Fail("Should not reach this point")
Catch ex As Exception