Gilad Lavian's Blog

In Development

Browse by Tags

All Tags » Framework 3.5 (RSS)
Generic EventArgs<T>
A good way for passing data with EventArgs public class EventArgs <TValue1> : EventArgs { public TValue1 Value1 { get ; set ; } public EventArgs(TValue1 value1) { Value1 = value1; } } Should you want to pass 2 values public class EventArgs <TValue1, TValue2> : EventArgs <TValue1> { public TValue2 Value2 { get ; set ; } public EventArgs(TValue1 value1, TValue2 value2) : base (value1) { Value2 = value2; } } The same goes to CancelEventArgs public class CancelEventArgs <TValue1>...
Extension Methods: IDataReader.GetValue<T>
A convenient solution to get value from IDataReader field. /// <summary> /// Gets the reader field value. /// </summary> /// <typeparam name="TField"> The type of the field. </typeparam> /// <param name="reader"> The reader. </param> /// <param name="fieldName"> Name of the field. </param> /// <returns></returns> public static TField GetValue<TField>( this IDataReader reader, string fieldName) { //Guard...
Start Detached AddIn
This Addin add new option to the debug menu for each project (When right clicking from Solution Explorer). Features Starts a new instance for the selected project. In case the project is not executable, a dialog is popped asking the user what to do. Requirements Microsoft .NET Framework 2.0 Visual Studio 2008 For more information click here . Download Version 1.0.0
SmartClient: Changing the Projects File System Structure
When creating a new smart client project by GAT (Guidance Automation Toolkit) the projects structure hierarchy on the file system is also created by the GAT. Suppose I move the projects to another location on the file system and to and include this projects in different solution, then, I try to add a new BusinessModule, I will get the following exception: Microsoft.Practices.RecipeFramework.ValueProviderException: An exception occurred during the binding of reference or execution of recipe CreateBusinessModuleCS...
LINQ To SQL - Performing Inner Join Queries
Its amazing how simple it is to create inner join queries with LINQ.   Assuming you have the AdventureWorks Database installed.   public void GetEmployeeByID( int employeeID) { AdventureWorksDataContext aw = new AdventureWorksDataContext(); aw.Log = Console.Out; var entities = from e in aw.Employees join ea in aw.EmployeeAddresses on e.EmployeeID equals ea.EmployeeID join a in aw.Addresses on ea.AddressID equals a.AddressID join c in aw.Contacts on e.ContactID equals c.ContactID where e...
LINQ To SQL - Get the SQL text query
Usually when we perform a LINQ Query on a SQL table, we don't see the actual query. Assuming you have the AdventureWorks Database installed. To see the query text, use the Log method: aw.Log = Console.Out   public List<Employee> GetEmployees() { AdventureWorksDataContext aw = new AdventureWorksDataContext(); var employees = from emps in aw.Employees select emps; aw.Log = Console.Out; return employees.ToList(); }   The result:
JOY, Visual Studio 2008 JavaScript Inteliscence Support
Yet, another great feature in Visual Studio 2008. JavaScript Inteliscence This is wonderful, i can finally write JavaScript prototypes and see them in the Inteliscence. It was so hard to write Object Oriented in VS2005 because of no Inteliscence support. To see this in action, first, I've created a new JS file called JScript.js, within i created a new class called Test(). Then i created 2 new prototypes function under Test() called DoSomthing1() and DoSomthing2(). Then i created a new instance...
LINQ - Handling Legacy Code
LINQ is for queries, no doubt about it. Yet - we can do some interesting thins with LINQ, and not just queries. For example, we all deal sometimes with legacy code inherited from some old project - so here some interesting ways to handle this code with few simple lambda expressions. For this example, I will use this Employee class: public class Employee { public Employee( string firstName) { this ._firstName = firstName; } private int _id; private string _firstName; private string _lastName; public...
WCF - IIS Integrated Security
Usually when we developing a WCF service in Intranet environment, we need to enable users to authenticate on IIS with there login credentials - Integrated Security.   Assuming we using basicHttpBinding and we host the service library on IIS web site, This can be accomplished by the following settings: < bindings > < basicHttpBinding > < binding name ="basicHttpBindingConfig" > < security mode ="TransportCredentialOnly" > < transport clientCredentialType...
WCF - Binding and Security
How do we know which binding to use and when? How do we know which security schema goes with our selected binding configuration?   There's allot of considerations with the binding configuration: Is there IIS involved. Are we going to use IIS Integrated Security. Are we going to use net.tcp binding?   There's also security issues we need to address: How we going to secure our services communication. Do we use the transport or the message layer.   Setting Features Transport Server...
LINQ to SQL Classes
One can only wish everybody to speak LINQ! The following solution demonstrate how to query database tables with object relational data classes. For this example you need to download and install the AdventureWorks Database provided by Microsoft. First, create a new console project: Open the "Server Explorer", click on the "Connect to Database" button: Select the Microsoft SQL Server: The next step is to connect to your AdventureWorks Database Server, from the "Add Connection"...