Skip to content

Instantly share code, notes, and snippets.

@hagbarddenstore
Created July 17, 2014 11:56
Show Gist options
  • Save hagbarddenstore/2084b7dbae661fc384ba to your computer and use it in GitHub Desktop.
Save hagbarddenstore/2084b7dbae661fc384ba to your computer and use it in GitHub Desktop.
ReSharper template to create .NET exceptions that are serializable.
namespace $NAMESPACE$
{
[System.SerializableAttribute]
public class $NAME$ : System.Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="$NAME$"/> class.
/// </summary>
public $NAME$()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="$NAME$"/> class.
/// </summary>
/// <param name="message">
/// The message.
/// </param>
public $NAME$(string message)
: base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="$NAME$"/> class.
/// </summary>
/// <param name="message">
/// The message.
/// </param>
/// <param name="innerException">
/// The inner exception.
/// </param>
public $NAME$(string message, System.Exception innerException)
: base(message, innerException)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="$NAME$"/> class.
/// </summary>
/// <param name="info">
/// The info.
/// </param>
/// <param name="context">
/// The context.
/// </param>
public $NAME$(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
: base(info, context)
{
// TODO: Retrieve each property defined in this class from the info variable like this: PropertyName = info.GetString("PropertyName");
}
/// <summary>
/// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with information about the exception.
/// </summary>
/// <param name="info">
/// The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.
/// </param>
/// <param name="context">
/// The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.
/// </param>
/// <exception cref="T:System.ArgumentNullException">
/// The <paramref name="info"/> parameter is a null reference (Nothing in Visual Basic).
/// </exception>
/// <filterpriority>2</filterpriority>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*"/>
/// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter"/>
/// </PermissionSet>
[System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.Demand, SerializationFormatter = true)]
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
{
if (info == null)
{
throw new System.ArgumentNullException("info");
}
// TODO: Save each property defined in this class into the info variable like this: info.AddValue("PropertyName", PropertyName);
base.GetObjectData(info, context);
}
}
}
@hagbarddenstore
Copy link
Author

$NAMESPACE$ should use the "Default namespace for current file" and be marked as not editable.
$NAME$ should use "Current file name without extension".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment