Inject custom type conversion to .NET library classes

You can change the registered TypeConverter for something using TypeDescriptor.AddAttributes; this isn’t quite the same as Convert.ChangeType, but it may suffice: using System; using System.ComponentModel; static class Program { static void Main() { TypeDescriptor.AddAttributes(typeof(Guid), new TypeConverterAttribute( typeof(MyGuidConverter))); Guid guid = Guid.NewGuid(); TypeConverter conv = TypeDescriptor.GetConverter(guid); byte[] data = (byte[])conv.ConvertTo(guid, typeof(byte[])); Guid newGuid = (Guid)conv.ConvertFrom(data); } … Read more

“Cannot implicitly convert type ‘System.Guid?’ to ‘System.Guid’.” – Nullable GUID

The ADO.NET API has some problems when it comes to handling nullable value types (i.e. it simply doesn’t work correctly). We’ve had no end of issues with it, and so have arrived at the conclusion that it’s best to manually set the value to null, e.g. myNewRow.myGuidColumn = myGuid == null ? (object)DBNull.Value : myGuid.Value … Read more

WIX Autogenerate GUID *?

Product/@Id=”*” randomly generates a new GUID, which is sufficient for product codes. Component/@Guid=”*” calculates a GUID that stays the same as long as your target path stays the same, which is necessary to comply with component rules.

tech