David Brown

The Web Development Guy
posts - 5, comments - 27, trackbacks - 0

My Links

News

View David Brown's profile on LinkedIn

Twitter












Tag Cloud

Archives

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...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Monday, April 06, 2009 3:38 PM | Feedback (3) |

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!...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Sunday, April 05, 2009 3:23 PM | Feedback (8) |

Powered by: