Skip to content

Instantly share code, notes, and snippets.

@mgroves
Created November 1, 2014 15:05
Show Gist options
  • Save mgroves/6546786885107eb504ed to your computer and use it in GitHub Desktop.
Save mgroves/6546786885107eb504ed to your computer and use it in GitHub Desktop.
using System;
using Android.Content;
using Newtonsoft.Json;
namespace LBMobileX
{
public static class IntentExtensions
{
/// <summary>
/// Serializes an object into the intent
/// </summary>
/// <param name="name">Name of the extra</param>
/// <param name="value">Object that will be serialized</param>
/// <typeparam name="T">Type of object being serialized.</typeparam>
public static void PutExtra<T>(this Intent @this, string name, T value) {
@this.PutExtra (name, JsonConvert.SerializeObject(value));
}
public static Type GetExtra<T>(this Intent @this, string name) {
return JsonConvert.DeserializeObject<T> (@this.GetStringExtra (name));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment