// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Data; using System.Data.SqlTypes; using System.IO; using Microsoft.SqlServer.Server; namespace CLRUDT { [Serializable] [SqlUserDefinedType(Format.UserDefined,IsByteOrdered=true,MaxByteSize=255)] public struct FullName : INullable, IBinarySerialize { public string FirstName { get; set; } public string LastName { get; set; } public bool IsNull { get; set; } public static FullName Null { get { return new FullName { FirstName = "", LastName = "", IsNull = true }; } } public override string ToString() { return IsNull ? "NULL" : string.Format("{0} {1}", FirstName, LastName); } [SqlMethod(OnNullCall = false)] public static FullName Parse(SqlString s) { string[] parts = s.ToString().Split(' '); return new FullName { FirstName = parts[0], LastName = parts[1], IsNull = false }; } public void Read(BinaryReader r) { FirstName = r.ReadString(); LastName = r.ReadString(); IsNull = r.ReadBoolean(); } public void Write(BinaryWriter w) { w.Write(FirstName); w.Write(LastName); w.Write(IsNull); } } }