.Net Framework

Methods to verify, are DataTables or DataSets the same.

I wanted to verify, are DataTables in DataSets the same. I found a few similar implementations on StackOverflow, but the one that I've selected (http://stackoverflow.com/q... didn't work and returned unexpectedly false, when comparing two cells with the same values tbl1.Rows[i][c] 2 object {long} tbl2.Rows[i][c] 2 object {long} tbl1.Rows[i][c] == tbl2.Rows[i][c] false I found, that it should be used Equals instead of ==. Equals(tbl1.Rows[i][c], ......

Number of Unit test projects in Visual Studio solution

Some time ago I have discussion with my co-worker how to organize test projects. Should we have a single test project that does all sorts of things and references every project?It is good to have one integration test dll, but for unit tests, what is the point merging everything into one.In ideal world I agree that small independent projects are better. Unfortunately we have solution size limitations From http://stackoverflow.com/qu... ......

Do NOT Change "Copy Local” project references to false, unless understand subsequences.

To optimize performance of visual studio build I've found multiple recommendations to change CopyLocal property for dependent dlls to false,e.g. From http://stackoverflow.com/qu... CopyLocal? For sure turn this offhttp://stackoverflow.com... set the Copy Local property to false and enforce this via a custom msbuild stephttp://codebetter.com/p... ......

Select First Row In Group using Custom Comparer

We have a requirement for a list of itineraries with multple itinerary items show only single itinerary in the list with details of one of the items selected based on some custom sorting logic. So I needed to group by itinerary ID and sort by custom Comparison and select the first in each group. Below is a LinqPad file that I've used for testing: void Main() { // http://smehrozalam.wordpres... // http://stackoverflow.com/qu... ......

Serializable attribute is not related to XmlSerializer.

.Net has several methods of serialization and sometimes it causes a lot of confusion even for experienced programmers. I believe the best article to describe the different methods is Aaron Skonnard’s Serialization in Windows Communication Foundation(MSDN Magazine > Issues > 2006 > August) (by some reason it’s not highly rated by Google and other articles are coming first for Serialization related requests) There is also a brief comparison table in StackOverflow What are the differences between ......

Validating an email address

I needed to validate customer email addresses. Many articles suggested to use different regEx , but they are not the same and not easy to identify, which is the best. So i decided to use MailAddress, which throw exception if MS implemented validation failed. It world be good if the class would provide Validate or TryParse method to avoid costly exception. /// <summary> /// //// Validating E-mail address /// </summary> public static class MailHelper { //TODO: use Reflector or find some ......

Implementations of HTML TidyLib for .Net

I was considering to add the HtmlValidator class to codeplex, but noticed that there are a few different implementations of HTML TidyLib for .Net. Not sure if any of them support my requirement to validate only structural errors, i.e. unmatched(not closed) open tags and unmatched(extra) close tags. But standard Tidy functionality will be good for most of users. 1. TidyManaged (https://github.com/markbea... Recent development (June 12, 2010), Positive reviews(e.g. here),Not much user ......

JavaScriptSerializer extension DeserializeDictionary

When I've tried to deserialize dictionary whis strongly typed(and not string) keys, I've got an exception similar to the following Type 'System.Collections.Generic... System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d5... mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934... is not supported for serialization/deserialization of a dictionary, keys must be strings or objects. // Type Dictionary`2 ......

Serialization error when property is declared as base class, but populated by derived class

I've receive quite generic error Message : Type 'MyclassType' with data contract name 'MyclassType:http://schemas... is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.Type : System.Runtime.Serializatio... mscorlib, Version=4.0.0.0, Culture=neutral, ......

Upgrading PostSharp from ver 2.1 to new version 3.0

I was upgrading our solutions from PostSharp 2 to PostSharp 3. The small solution based on cache attribute from http://cache.codeplex.com/ was upgraded without any problems.Upgrading my main solution by installing nuget package PostSharp also was quite well. The only annoying thing was that installer added RequiresPostsharp.cs file to all projects, that already had SkipPostSharp=true setting and I had manually remove themThe issue was reported athttp://support.sharpcraft... ......

AddIfNotNull collection extensions

I want to post a few recently created collection extensions to write in one line, what otherwise takes 2 or more public static void AddIfNotNull( this IList coll, T newItem) where T : class { if (newItem != null) { coll.Add(newItem); } } public static void AddRangeIfNotNullOrEmpty( this List coll, IEnumerable newItems) where T : class { if (!newItems.IsNullOrEmptySeq... { coll.AddRange(newItems); } } public static void AddIfNotContains( this Dictionary dictionary, TKey key, TValue value) { if ......

EntLIb editor corrupts config files

I've tried to use Microsoft Enterprise Library(EntLIb) editor, as it was suggested in http://weblogs.asp.net/suku... but after changes all comments in config files were removed. Always consider to move any Enterprise Library configurations to a separate file before editing ......

Adding PostSharp to new projects, when it's installed for some projects in solution.

Recently I've posted my experience with installation of PostSharp Once PostSharp is installed in solution's packages folder for some project(s), I often need to add PostSharp to another project in the same solutionSection "Adding PostSharp to your project using PostSharp HQ" of documentation described the process quite well.I only want to add that the actual location of PostSharp HQ ( if it was installed from NuGet) is[solution root ]packages\PostSharp.2.1.7.1... ......

Helper method to Replace/Remove characters that do not match the Regular Expression

I have a few fields, that use regEx for validation. In case if provided field has unaccepted characters, I don't want to reject the whole field, as most of validators do, but just remove invalid characters. I am expecting to keep only Character Classes for allowed characters and created a helper method to strip unaccepted characters. The allowed pattern should be in Regex format, expect them wrapped in square brackets. function will insert a tilde after opening squere bracket , according to http://stackoverflow.com/qu... ......

PostSharp deployment to build machine- use Setup installation, not NuGet package.

PostSharp has well documented different methods of installation. I've chosen installing NuGet packages, because according to Deploying PostSharp into a Source Repository NuGet is the easiest way to add PostSharp to a project without installing the product on every machine. However it didn't work well for me. I've added PostSharp NuGet package to one project in the solution. When I wanted to use PostSharp in other project, Visual Studio tab showed that PostSharp is not enabled for this project I've ......

Convert collections of enums to collection of strings and vice versa

Recently I needed to convert collections of strings, that represent enum names, to collection of enums, and opposite, to convert collections of enums to collection of strings. I didn’t find standard LINQ extensions.However, in our big collection of helper extensions I found what I needed - just with different names: /// <summary> /// Safe conversion, ignore any unexpected strings/// Consider to name as Convert extension /// </summary> /// <typeparam name="EnumType"></typ... ......

Using PostSharp.Toolkit.Diagnostics, when not all developers have Pro licenses.

We have only couple of developers who are using PostSharp.Toolkit.Diagnostics and having PostSharp Pro license .However ther are much more developers , who are building our solution, but do not required Toolkit.Diagnostics XmlMulticast features, that are referred in %ProjName%.psproj file.As a workaround I've suggested to to replace locally psproj file with dummy, that doesn't have XmlMulticast(PostSharp feature that available only in Pro edition).If a developer doesn't have PostSharp Pro license, ......

VAB ValidationResults Extensions

We've started to actively used Microsoft Enterprise Library Validation Enterprise Block ( VAB) and I was surprised , that a few commonly used operations are not supplied(or I haven't found them) out of the box.See two extensions, that make use of VAB simplerpublic static class ValidationResultsExtensions { public static string CombinedMessage( this ValidationResults results) { string errorMessage = ( from res in results select String.Format(" {0}:{1} ", res.Key, res.Message)).ToDelimitedSt... ";"); ......

Using CollectionNotEmptyValidator

We recently started to use Microsoft Enterprise Library Validation Enterprise Block (VAB) to check interfaces between modules. One of the properties to validate is array of values, that should be not empty, and shoul include one of expected values. I found CollectionNotEmptyValidator at http://www.eggheadcafe.com/... that allows to validate the property to satisfy part of requirements. The class ......

C# tip: do not use “is” type, if you will need cast “as” later

We have a debate with one of my collegues, is it agood style to check, if the object of particular style, and then cast as this type. The perfect answer of Jon Skeet and answers in Cast then check or check then cast? confirmed my point.//good var coke = cola as CocaCola; if (coke != null) { // some unique coca-cola only code } //worse if (cola is CocaCola) { var coke = cola as CocaCola; // some unique coca-cola only code here. } ......

Full .Net Framework Archive

«October»
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678