Skip to content

Instantly share code, notes, and snippets.

View WebApiHelpers.cs
public static class WebApiHelpers
{
public static string ToJson(Object model)
{
var serializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
return JsonConvert.SerializeObject(model, serializerSettings);
}
View StringToIntList.cs
var ids = @"1,2
3
asf
4 5";
Regex rx = new Regex(@"(\d+)",
RegexOptions.Compiled | RegexOptions.IgnoreCase);
MatchCollection matches = rx.Matches(ids);
var listIds = new List<int>();
foreach (Match match in matches)
@edqwerty1
edqwerty1 / asyncFetch.js
Created Sep 18, 2018
JS fetch async examples with error handling and comparison to promise.
View asyncFetch.js
// Old
function handleErrors(response) {
if (!response.ok) {
throw Error(response.statusText);
}
return response;
}
// GET
fetch(`/myAPI/GetMethod?param=${this.param}`, {