Starting in .NET 3.5, a new feature was added called Extension Methods. Microsoft defines them as: Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are a special kind of static method, but they are called as if they … Continue reading Extension Methods
Tag: Tip of the Day
The Using Pattern
When I teach and speak at conferences, one thing I stress a lot is releasing object resources as soon as possible! This allows the garbage collector to remove the object from the memory heap faster and lowers the memory footprint of the application. So, all objects that expose a finalizer should also have a method … Continue reading The Using Pattern
Checking a DataTable for Data
Whenever you retrieve a DataTable from a data source, there no guarantee that there is actual data in it. Before you start looking for rows, you should always validate that that is it's not null and also there are rows. Here is a easy way to do it using extensions. public static class DataTableExtensions … Continue reading Checking a DataTable for Data
Quickly Finding Items in Visual Studio 2010
There is a new shortcut in VS2010 that makes it really simple to find any item in your solution very quick and easy. Simply type Ctrl-Comma and this dialog will appear: Start typing what you are looking for and this will quickly list all items that contain what you have typed (similar to Google Suggest).
How to Easily Access Visual Studio Windows
Here is a great Visual Studio keyboard shortcut. Do you work with lots of VS windows and want to switch between them without grabbing the mouse? Press and hold CTRL+TAB. You’ll get a popup with all your open Visual Studio windows, including tool windows. Then you can use TAB to scroll between them, or arrow … Continue reading How to Easily Access Visual Studio Windows
Finding Controls in ASP.NET
Find ASP.NET Controls easily!
LINQ over DataSets
Did you know you can LINQ over DataSets too? Well it’s pretty easy. So if you are doing something like this: foreach (DataRow row in dt.Rows) { if (tempEvent.JobHandlerConfig.LicenseKey.Value.Equals( int.Parse(row[0].ToString()))) { valid = true; break; } } You can instead do this with LINQ: valid = dt.AsEnumerable().Where(p => p.Field<int>(0). … Continue reading LINQ over DataSets
Using Array.ForEach
Here is a tip for you. If you are doing a simple foreach against a collection like this: foreach (var se in this._scheduledItems) { se.Verified = false; } You can easily change it to one line using Array.ForEach and a Lambda expression: Array.ForEach(this._scheduledItems.ToArray(), p => p.Verified = false); Tip By: David McCarter
Retrieving Changed Properties from the Entity Framework
On a project using the Entity Framework (3.5 SP1), I was tasked with only sending "changed" or "added" values to a back-end system to keep network traffic down. After a lot of research and testing, I came up with the solution below. Use this code below: private static void FindChangedEntityProperties<T>(LocalEntityState state, ClientDataEntities context, ref IEnumerable<string> … Continue reading Retrieving Changed Properties from the Entity Framework
Easily Retrieve the Foreign Key from an Entity Framework Entity
Retrieving the foreign key from a related entity in the Entity Framework (3.5 SP1) is not very easy. Below is an extension method you can add to make it simple: public static int ForeignKey(this EntityReference entRef) { int keyval = 0; if (int.TryParse(entRef.EntityKey.EntityKeyValues[0].Value.ToString(), out keyval)) { return keyval; } else { return 0; } } … Continue reading Easily Retrieve the Foreign Key from an Entity Framework Entity

You must be logged in to post a comment.