Programming

Single or Array Enum JSON Converter

Single or array enum JSON converter. In addition to the SingleOrArrayConverter mentioned previously I’ve also created a version to translate enums to/from JSON using the name of the enum rather than it’s value as is the default. public class SingleOrArrayEnumConverter<T> : JsonConverter { public override bool CanConvert(Type objectType) { return Read more…

By Shinigami, ago
Programming

Single or Array JSON Converter

Single or array JSON converter. Often APIs will have actions where one of the parameters can be either a single object or an array of objects, in order to correctly serialize objects to JSON which can be accepted by the API a custom JsonConverter is needed. This code is borrowed Read more…

By Shinigami, ago
Programming

Comparing List Objects

Comparing objects between 2 different lists to determine which have different properties. I have a list of EventType objects with the following definition. public class EventType { public int EventTypeId { get; set; } public string EventTypeDesc { get; set; } public DateTime CreateDate { get; set; } public int Read more…

By Shinigami, ago
Programming

SQL Stored Procedure In .NET

I generally end up forgetting how to return results from a SQL stored procedure within .NET so I figured I’d put it here for reference. public static List<Blog> GetBlogSummaries() { List<Blog> blogs = new List<Blog>(); using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["BlogDatabase"].ConnectionString)) { using (SqlCommand command = new SqlCommand("sp__get_blog_summaries")) { command.CommandType Read more…

By Shinigami, ago