Friday

convert object to string

 
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using CSharp.Core;
using CSharp.Core.Utility;

// serializing object into byte array
public static byte[] RawSerializeEx(object anything)
{
int rawsize = Marshal.SizeOf(anything);
byte[] rawdatas = new byte[rawsize];
GCHandle handle = GCHandle.Alloc(rawdatas, GCHandleType.Pinned);
IntPtr buffer = handle.AddrOfPinnedObject();
Marshal.StructureToPtr(anything, buffer, false);
handle.Free();
return rawdatas;
}


// serializing object into string
public static string RawSerializeStr(object anything)
{
byte[] des2 = RawSerializeEx(anything);
ASCIIEncoding utf82 = new ASCIIEncoding();
string uf82 = utf82.GetString(des2);
return uf82;
}

No comments:

test smtp server with powershell

Send-MailMessage -SMTPServer smtp.domain.com -To [email protected] -From [email protected] -Subject "This is a test email" -Body ...