How to control appearance of ‘:’ in time zone offset when parsing/formatting Datetime

Doesn’t look like there is anything built-in (you can use zz, but that leaves out the minutes). You can roll your own by instantiating a DateTimeFormatInfo, setting TimeSeparator to string.Empty and using that as the IFormatProvider when calling DateTime.ToString (and make the call explicit, if it is not already). But frankly, using Replace to remove … Read more

Can Ruby import a .NET dll?

While IronRuby will make short work of talking to your .NET dll (it’ll be literally no code at all), it was abandoned by microsoft, and it never got a large enough open source community to keep it going after that event. I wouldn’t recommend it these days Regarding the COM solution, this may actually be … Read more

Best solution for XmlSerializer and System.Drawing.Color

The simplest method uses this at it’s heart: String HtmlColor = System.Drawing.ColorTranslator.ToHtml(MyColorInstance); It will just convert whatever the color is to the standard hex string used by HTML which is just as easily deserialized using: Color MyColor = System.Drawing.ColorTranslator.FromHtml(MyColorString); That way you’re just working with bog standard strings…

Is the CallerMemberName attribute in 4.5 “able to be faked”?

Yes, you can, exactly as you could use LINQ and .NET 2, as you said. I use the following in a .NET 4.0 project with the VS2012 compiler with success: namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] public sealed class CallerMemberNameAttribute : Attribute { } } Be very careful that everyone on … Read more

Counting bits set in a .Net BitArray Class

This is my solution based on the “best bit counting method” from public static Int32 GetCardinality(BitArray bitArray) { Int32[] ints = new Int32[(bitArray.Count >> 5) + 1]; bitArray.CopyTo(ints, 0); Int32 count = 0; // fix for not truncated bits in last integer that may have been set to true with SetAll() ints[ints.Length – 1] … Read more