Generics

There are 7 entries for the tag Generics
I've discovered what was causing problems with TestDriven.Net and it isn't ReSharper. I had recently refactored my test fixtures and now I have a few that make use of generics BaseTest<T>. I had run into a problem with TD.Net before regarding generics and had to rearrange my classes (I had two classes in one file) to get it to work. I don't remember the details and I am still having problems getting it to work now. Regardless, R# is off the hook. And as an added bonus, R# doesn't appear to ......
I recently added a new page to my application that is very similar in behavior to a page I had already completed a couple months back. In fact, the similarities propagate down through the business and data layers as well. Because of this, I was able to introduce some base classes to limit duplication. In fact, I started all of this with a generic base test class. All of the base classes (with generics) were pretty straight forward. However, generics wouldn't help me when it came to the UI (aspx). ......
Before I get started on Generic Classes in .Net, I'd like to give credit to CopySourceAsHtml for my new formatting of code blocks in my blog. I made some of my own enhancements, but I'd still be using the boring black on yellow formatting without CSAH. To learn how to get it to work on VS2008, go here (be sure to read the comments if you are running on XP). We've all used generic classes without thinking much about it. I use List<T> extensively (perhaps abusively). I really only discovered ......
It seems that enums might be the neglected step-child when it comes to Generics and Extensions. I've tried defining generics that are constrained to enums. No luck. I faced much frustration trying to get my generic methods to work. I finally came up with a method that meets my need. But, I had to add a little bit of run-time type checking. Instead of repeating Enum.Parse throughout my code, I wanted to create a simple generic extension method that would do it for me. I just discovered that my extension ......
So, I've settled on a pattern that I found somewhere on the web to safely override Equals. I don't remember where I found it, and there are certainly many other good implementations (probably better than mine). Regardless, I found that I do have a repeating pattern. I decided to set out to limit this duplication if I could. Here is what I came up with. 1: public static bool SafeEquals<T>( this T left, object right, Predicate<T> test ) 2: { 3: if( right != null && right.GetType().Equals( ......
The string.Join method can come in handy when you want a comma separated list of strings. However, there's a major limitation. To use it, you must provide a one-dimensional string array. What if you have a collection of objects and you want to "Join" a property on the objects (e.g., a comma separated list of IDs). Well, since I couldn't find anything within the framework that would do this for me, I wrote an extension method that meets my need. Updated from James Curran's suggestion in the comments. ......
It seems that I have encountered a scenario where many aspects of C# 2.0+ come into play. I needed to handle conversion from an IDataReader.GetValue() result to a generic type, including Nullable<>. It took me a while to figure it out and with a little help from this snippet, I was quite please with the result. So, I decided to share. 1: private static T NullValue<T>( object testValue, T nullValue ) 2: { 3: T returnValue; 4: if( testValue is DBNull ) 5: { 6: returnValue = nullValue; 7: ......