public static T Base64 <T>(string encoded) where T : unmanaged { try { byte[] bytes = Convert.FromBase64String(encoded); return(Unsafe.FromBytes <T>(bytes)); } catch (Exception) { return(default(T)); } }
public static T Base64 <T>(string encoded) where T : struct { try { byte[] bytes = RawBase64(encoded); return(Unsafe.FromBytes <T>(bytes)); } catch (Exception) { return(default(T)); } }
public static bool Base64Out <T>(string encoded, out T ret) where T : unmanaged { try { byte[] bytes = Convert.FromBase64String(encoded); Unsafe.FromBytes(bytes, out ret); return(true); } catch (Exception) { ret = default(T); return(false); } }
/// <summary> Attempt to convert a GZipped, Base64 <see cref="string"/> into a struct </summary> /// <typeparam name="T"> Generic type of parameter to unpack </typeparam> /// <param name="encoded"> Encoded GZipped, Base64 <see cref="string"/> </param> /// <param name="ret"> Return location </param> /// <returns> True if successful, false if failure, /// and sets <paramref name="ret"/> to the resulting unpacked data, or default, respectively. </returns> public static bool TryGZipBase64 <T>(string encoded, out T ret) where T : struct { try { byte[] bytes = GZipBase64(encoded); Unsafe.FromBytes(bytes, out ret); return(true); } catch (Exception) { ret = default(T); return(false); } }