This is the link of the style cop plugin for Resharper
http://stylecop.forresharper.org/
One of my best and favorite tool
This is the link of the style cop plugin for Resharper
http://stylecop.forresharper.org/
One of my best and favorite tool
The problem that the action context of this action sometimes didn’t appear, until this moment I didn’t know why? of course I Google everywhere but nothing helpful except that info that Resharper 6.0 doesn’t support the style cop plugin till now, which was very sad news for me anyway, here what I do to fix the problem, of course it fixed at the end but I didn’t know why??
And now its working with style copy an without style cop, Just click on the method name and the context action will appear and include the copy comments from base
Good links for more more info
http://msdn.microsoft.com/en-us/library/ee725345.aspx
http://marlongrech.wordpress.com/2008/01/08/working-with-expression-trees-part-1/
Because they generate inline JavaScript which is the same way as the web form does, this one of the reason that makes me hit the web form approach.
So why I use them isnted of I can makes a clean JQuery code to follow JavaScript Unobtrusive JavaScript which means that we should keep our JavaScript code separated in. js file, as the CSS it must be separated from the html, the JavaScript also must be separated from html
But in MVC 3 I surprised that all Ajax action not generate inline scripts and use JQuery and custom html attributes, we just reference unobtrusive-ajax.js file and of course the JQuery library, which I can consider it (unobtrusive) as a JQuery plugin, so now I really consider using Ajax helper method in my next proejct
<form onsubmit="Sys.Mvc.AsyncForm.handleSubmit(this, new Sys.UI.DomEvent(event),
{ insertionMode: Sys.Mvc.InsertionMode.replace, updateTargetId: '#myDiv' });"
onclick="Sys.Mvc.AsyncForm.handleClick(this, new Sys.UI.DomEvent(event));"
method="post" action="/Home/Save">
<input type="text" name="Name">
<input type="submit" value="Save">
</form>
<form method="post" id="form0" data-ajax-update="#myDiv" data-ajax-mode="after" data-ajax-method="POST" data-ajax="true" action="/Home/Save"> <input type="text" name="Name"> <input type="submit" value="Save"> </form>
This really show us how Microsoft not only imporove the MVC itself but also how they try to follow and lead the web community again as before
Thanks Microsoft Keep Improving
To install the package you just open tool-> Library Package Manager->Package Manager Console as the following:
Now in the NuGet Package Manager console write the following
PM>Install-Package DevMagicFake -Project MyMVCProject
This will install DevMagicFake Library and add reference to it in your MVC project, this also will add the configuration file needed in the web.config
You can install it by another way, right click on the project you want to install the library to, choose Manage NuGet Packages, the NuGet Management window will appear, just search for DevMagicFake and install it
http://msdn.microsoft.com/en-us/library/ms229042.aspx
So what is the main reason for that?
The answer is Extension Method, Microsoft extend all the Old collection like (Any Array, List<T>, Queue<T>, Stack<T>, Dictionary<T,T> etc.) with all extension methods exist in the System.LINQ, so no need to create custom collection, we just need to use IEnumerable<T> or IList<T> and then extend them at any time in my project with new extension methods, but be careful this will not break the access of the members, in other words the extension method will not be able to access the private member like in the custom collection does, but in most cases this will be good enough
We can create extension methods that apply to an interface, which allow us to call this method for each class that implement this interface, for example
If we add extension method called CalculateSalary for IEnumerable<Employee> as the following:
public static decimal CalculateSalary(this IEnumerable<Employee> empList)
{
decimal totalSalary = 0m;
foreach (var employee in empList)
{
totalSalary += employee.Salary;
}
return totalSalary;
}
So now I can create list of Employee and I will find the method exist in this list as the following:
static void Main(string[] args)
{
IEnumerable<Employee> emplloyees = new List<Employee>
{
new Employee { Id = 1, Salary = 49m },
new Employee { Id = 2, Salary = 33m },
new Employee { Id = 4, Salary = 66m }
};
Console.WriteLine(emplloyees.CalculateSalary());
Console.ReadLine();
}
Extension Method rules
I will start by talking about Func<> so what is it?
Built-in delegates that take none or one or many parameters and return one result, as we can see we have 16 overloading start from the first one that didn’t take any parameters and return one result and ending with the final one that take 15 parameters and return one result too
Remember that always the last parameter is the return parameter
Why these delegates exist? because .NET Framework use them in LINQ and Extension method so Microsoft makes them public so that we as developers can use them instead of creating new delegates with the same signature
The same as Func but it doesn’t return value (void)
So let’s see the following example:
public static int MyMethod (Func<int,int> del)
{
return del(4);
}
So we can see that this method takes a parameter as delegate, that’s mean we will pass a method as a parameter with the same signature of the delegate
So we can make method that take one int and return int as the signature of the Func (parameter) as the following method
public static int MethodParameter(int x)
{
return x += 5;
}
And then we will path it to our method (MyMethod)
MyMethod(MethodParameter))
But why we create method that we will not use it anymore??? And here the anonymous method will take place, so instead of creating method and pass it to MyMethod we will pass anonymous method with the same signature
So how to write anonymous method with the same signature? it’s very simple, we just write the method and remove the first part until the parameter and write delegate instead of the first part as the following:
So it will become as the following:delegate(int x) { return x += 5; })So now we can pass the anonymous method to MyMethod as the following:
MyMethod (delegate(int x) { return x += 5; }));So now we will convert the anonymous method to lambda expression and pass it to MyMethod but first how we can convert anonymous method to lambda expression? It’s very simple
(delegate(int x) { return x += 5; } // anonymous method (x)=> { return x += 5; } // remove delegate and int x=> { return x += 5; } // remove Parentheses because one variable x=> x += 5 // remove return and curly brackets it's one statement like ifSo now instead of pass anonymous method to MyMethod we will pass the lambda expression of the anonymous method as the following:
MyMethod (x=> x += 5));We don’t need to express the logic of our delegate in the lambda expression. We can as easily call a method, like this:
prod => EvaluateProduct(prod)If we need a lambda expression for a delegate that has multiple parameters, we must wrap the parameters in parentheses, like this:
(prod, count) => prod.Price > 20 && count > 0And finally, if we need logic in the lambda expression that requires more than one statement, we can do so by using braces ({}) and finishing with a return statement, like this:
(prod, count) => { //...multiple code statements return result; // notice here because multiple parameters we have Parentheses // and also because we have many statements we have curly brackets }
I hope it helps![]()
We can open–>Tool–>Option–>Enviroment–>Keyboard
Start search for the following items, and we will found each one has 2 items, so we will associate shortcut to the item that didn’t has:
We can also make another solution by removing MVC 2 Tool from Add Remove Program but this will make any existing MVC 2 application not be able to work, if you remove it by mistake you can install this tool again from VS2010 DVD, the tool name is VS2010ToolsMVC2.msi and can be fond under WCU\ASPNETMVC
See the video
The code for the Add interface Module as the following:
Public Module AddInterfaceModule
Sub AddInterface()
Dim interfaceName As String = Microsoft.VisualBasic.Interaction.InputBox("Name", "Add Interface")
If Not interfaceName.ToLower.EndsWith(".cs") Then
interfaceName &= ".cs"
End If
DTE.ItemOperations.AddNewItem("Visual C#\Code\Interface", interfaceName)
End Sub
End Module</pre>