Skip to content

Instantly share code, notes, and snippets.

@Immerseit
Immerseit / BinaryFormatter
Created December 14, 2012 11:07
Sample of a normal Serialize / Deserialize .NET objects to Byte array (and back)
//
// Convert a object to byte array
//
ObjectType _theObject; // Populates from somewhere
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
formatter.Serialize(ms, _theObject);
byte[] bytes = ms.ToArray();
FileStream fs = new FileStream("dummy.bin", FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
@Immerseit
Immerseit / Autofac-Register
Created September 9, 2013 19:48
A simple Autofac implementation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Autofac;
namespace Throwit.Business.SomeObjects
{
@Immerseit
Immerseit / Object2Xml.cs
Created September 21, 2011 21:13
A Readable way to create a simple C# Class and Serialize to XML
namespace Object2Serializer
{
/// 2011-09-21 XmlSerialization
/// This class content (definition) was created due to a third-partys serialized stream of text (xml alike)
/// With data from i.e. a database, the lists Graph and Set should be populated. And then
/// .GenerateXmlText() will do the whole work! Easy extendable with GenerateJson and so on.
/// As a little side note. There are just three lines in the Serialize-method to make a xml-standard.
public static partial class Program
{