.Net - Peter's Software House

Browse by Tags

All Tags » .Net (RSS)

Convert or Cast?

In my previous post I looked at the performance difference between GetType() and typeof . Today I compared the use of Convert against casting to types from object .  I found that Convert takes between 3.5 and 5.8 times longer than a straight cast. The reason I was checking this is that I am busy reviewing some code and was surprised to find Convert.ToDecimal and Convert.ToString etc… all over the code base, so I just wanted to see if this was done for some reason I was unaware of and to my great...
Posted by Pieter | with no comments
Filed under: ,

System.Type.GetType or typeof

System.Type.GetType is more than 7 times slower (on my dual core machine) than typeof . There are times when GetType is useful, but if the Type is well known to you then use typeof . use: Type aType = typeof(DateTime); instead of: System.Type.GetType("System.DateTime") Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Pieter | with no comments
Filed under:

Pex 0.7

I've been so busy over the last couple of weeks that I completely missed the release of Pex 0.7 as announced by Nikilai . The team also released a draft document on Parameterized Unit Test Patterns which is a pretty good read. If you do Unit Testing in the .NET space then you need to have a look at Pex . No go and Test. Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Pieter | 1 comment(s)
Filed under: , , ,

RPO v1.0 Released

What is the RPO? The RPO (Runtime Page Optimizer) speeds up ASP.NET and SharePoint websites. Its simple. We automated 8 of the guidelines set out in Yahoo's "Best practices for speeding up your site" and checked these with the creators of YSlow to make sure the RPO gives you the fastest website ever. Try the RPO now from www.getrpo.com . Technical background The RPO (Runtime Page Optimizer) is a software component for IIS 6/7 web servers  that speeds up ASP.NET and SharePoint websites...
Posted by Pieter | 1 comment(s)
Filed under: , ,

Get access to Active Directory Properties

Here's a nice sample of how to get access to things like if an Account has been disabled or to get the Password Expiration Date.  You will need the Interop.ActiveDs.dll for this code to work. using System; using System.Security.Principal; using System.Diagnostics; using System.DirectoryServices; using System.DirectoryServices.ActiveDirectory; using System.Text.RegularExpressions; namespace ConsoleApplication1 { class Program { static void Main( string [] args) { foreach (IdentityReference...
Posted by Pieter | with no comments
Filed under:

Code Access Security and .NET Framework Versions

This is a note to myself. First of all you do not get the .NET Framework 2.0 Configuration Tool as part of the .NET 2.0 Framework.  You have to install the .NET 2.0 SDK to get it.  This is different from .NET 1.1 where the '.NET Framework 1.1 Configuration Tool' is installed with shortcuts in Administrative Tools. So now if you are setting CAS setting through the 'Microsoft .NET Framework 1.1 Configuration' tool, but still get SecurityExceptions, then you need to check if...
Posted by Pieter | with no comments
Filed under:

Equality Pattern from Resharper

I was just reading this blog entry on how Resharper can auto generate equality members. This is a pretty nice pattern to follow even when doing this by hand. Here is the class it was created for: public class Fooberry { public string Foo { get; set; } public string Bar { get; set; } }   public override bool Equals( object obj) { if (ReferenceEquals( null , obj)) return false ; if (ReferenceEquals( this , obj)) return true ; if (obj.GetType() != typeof (Fooberry)) return false ; return Equals...
Posted by Pieter | with no comments
Filed under:

Using Linq to Filter a list

So yesterday I made this post on applying a filter or map on a list.  Now let’s have a look at how we can do this with Linq. First the list: List< string > list = new List< string >(); list.Add( "Anne" ); list.Add( "Brian" ); list.Add( "Pieter" ); list.Add( "Wayne" ); list.Add( "Shane" ); list.Add( "Susan" ); list.Add( "Xavier" ); Plain old Linq: // Plain old Linq var linqFiltered = from item in list where item...
Posted by Pieter | with no comments
Filed under: ,

Filter and Map in C#

I was reading this post by Sarah Taraporewalla .  And I immediately wanted to see if I could do this with C#. Here are my results for Filter : using System; using System.Collections.Generic;   namespace TestFilter { static class Program { static void Main( string [] args) { // Add a whole bunch of names FilteredList list = new FilteredList(); list.Add( "Anne" ); list.Add( "Brian" ); list.Add( "Pieter" ); list.Add( "Wayne" ); list.Add( "Shane"...
Posted by Pieter | 3 comment(s)
Filed under:

Omea Pro 3.0a

I’ve been running Omea Pro 3.0a for a couple of weeks now.  And to be honest I think it performs better than 2.2, but that is a very subjective view. Some of the changes I have noticed are what looks like new plugins:   and the Debug menu (part of the Debug & Instrumentation plugin): Just realised while searching that the code name for 3.0 is Grenache and that they have done some work on performance, read about it here: http://www.jetbrains.net/confluence/display/OMEA/Omea+Grenache...
Posted by Pieter | with no comments
Filed under:

Unit Test Adapter threw exception

When trying to run my tests on a project I was working on I ran into the following error: Unit Test Adapter threw exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information… This happened after I setup all my projects to have a strong name.  And the solution is straight forward:  Go to the test run config and set the Re-signing key file to the same key you use to strong name your...
Posted by Pieter | with no comments
Filed under: , , ,

Yea! SP1 for VS 2008 and .NET FX 3.5 has been released

So as you all should know by now, Service Pack 1 for Visual Studio 2008 and .NET Framework 3.5 has been released. Here are all the downloads: Visual Studio 2008 SP1 .NET Framework 3.5 SP1 Visual Studio 2008 Express Editions with SP1 Visual Studio Team System 2008 Team Foundation Server SP1 Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!
Posted by Pieter | with no comments
Filed under: , ,

Performance Counters are Easy

Yes they are! I had a requirement on a project that the final product needed to support a certain number of users and transactions per hour or something like that.  But when asked nobody knew how they were going to measure this or even test.  So I thought, hey performance counter must be the solution for this.  Then I worried that it was going to be a nightmare to implement.  Man was I wrong.  I was looking at the SvnBridge code and found how they implemented performance...
Posted by Pieter | with no comments
Filed under:

Check Email with RegEx

I needed to validate an Email address and I found this site: How to find or Validate and Email Address I then created and Extension and used the RFC2822 version: 1: public static bool IsEmailValid( this string email) 2: { 3: if ( string .IsNullOrEmpty(email)) 4: { 5: return false ; 6: } 7: Regex pattern = new Regex( @"(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|" "(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-...
Posted by Pieter | 2 comment(s)
Filed under:

Loving Extensions

I saw a post recently where Christopher Bennage talks about his little friend, Enum<T> .   Christopher said that the code was so simple he was almost ashamed of it.  No need to be ashamed dude, the simplest code is the best code! ;) I thing this is actually an area where Extentions can be used very effectively. 1: public static TEnum ConvertTo<TEnum>( this string source) 2: { 3: // Validate type of TEnum 4: Type typeOfEnum = typeof (TEnum); 5: if (typeOfEnum.BaseType !...
Posted by Pieter | 1 comment(s)
Filed under:
More Posts Next page »