Skip to content

Instantly share code, notes, and snippets.

@PaulGreenwell
PaulGreenwell / VB.NET Format SDK Error
Created September 25, 2013 06:04
VB.Net example for extracting the content from AccountRight API SDK error messages
Protected Sub OnError(uri As System.Uri, ex As System.Exception)
'Display thr formatted message
Select Case ex.GetType()
Case GetType(System.Net.WebException)
MessageBox.Show(FormatMessage(CType(ex, System.Net.WebException)))
Case GetType(MYOB.AccountRight.SDK.ApiCommunicationException)
MessageBox.Show(FormatMessage(CType(ex.InnerException, System.Net.WebException)))
Case GetType(MYOB.AccountRight.SDK.ApiOperationException)
MessageBox.Show(ex.Message)
@PaulGreenwell
PaulGreenwell / C# Format SDK Error Message
Created September 25, 2013 06:02
C# example for extracting the content from AccountRight API SDK error messages
protected void OnError(Uri uri, Exception ex)
{
//Display the formatted message
switch (ex.GetType().Name)
{
case "WebException":
MessageBox.Show(FormatMessage((WebException) ex));
break;
case "ApiCommunicationException":
MessageBox.Show(FormatMessage((WebException) ex.InnerException));
@PaulGreenwell
PaulGreenwell / VB.Net ToJson extension class
Created September 25, 2013 04:23
VB.Net extension class that serialises and object to JSON
Imports System.IO
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Converters
Imports System.Runtime.CompilerServices
Public Module JsonExtensions
<Extension()>
Public Function ToJson(ByVal entity As Object) As String
Dim serializer = New JsonSerializer()
@PaulGreenwell
PaulGreenwell / C# ToJson extension class
Created September 25, 2013 04:20
Sample C# extension to serialise a class to JSON
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public static class JsonExtensions
{
public static string ToJson(this object entity)
{
var serializer = new JsonSerializer();
serializer.Converters.Add(new StringEnumConverter());