Geeks With Blogs
David Brown The Web Development Guy April 2009 Entries
Easy Access to AssemblyInfo.cs attributes
For my current project, I've implemented a Shared AssemblyInfo.cs file, mostly because every project is from the same company and share some common version numbers. In one of my console applications, I needed to construct a header using the Assembly Title and Copyright information from my SharedAssemblyInfo.cs file. To achieve this, I added the following to the end of SharedAssemblyInfo.cs: namespace MyNamespace { public static class AssemblyInfo { public static string Title { get { var attr = GetAssemblyAttribute<Ass... ......

Posted On Monday, April 6, 2009 3:38 PM

Convert a BitArray to byte[] in C#
Here's an extension method that packs a C# BitArray to a byte array: public static byte[] ToByteArray(this BitArray bits) { int numBytes = bits.Count / 8; if (bits.Count % 8 != 0) numBytes++; byte[] bytes = new byte[numBytes]; int byteIndex = 0, bitIndex = 0; for (int i = 0; i < bits.Count; i++) { if (bits[i]) bytes[byteIndex] |= (byte)(1 << (7 - bitIndex)); bitIndex++; if (bitIndex == 8) { bitIndex = 0; byteIndex++; } } return bytes; } Special thanks to the good people at StackOverflow! ......

Posted On Sunday, April 5, 2009 3:23 PM

Copyright © David Brown | Powered by: GeeksWithBlogs.net