Resharper & Entity Framework Generated Code
18/05/2011Been looking for a way to get Resharper to ignore the code that is generated by Entity Framework for a while. Sure, I can ignore the entire project, but since we also had some repo/Unit Of Work implementations in the same project, that’s really not an option.
The final solution was to edit the code generating T4 (.tt) templates of Entity Framework to wrap the code in a custom region, i.e. ”EF Generated code”.
void BeginNamespace(string namespaceName, CodeGenerationTools code){ CodeRegion region = new CodeRegion(this); if (!String.IsNullOrEmpty(namespaceName)) {#>#region EF Generated Code //<- right herenamespace <#=code.EscapeNamespace(namespaceName)#>{<#+ PushIndent(CodeRegion.GetIndent(1)); }}
void EndNamespace(string namespaceName){ if (!String.IsNullOrEmpty(namespaceName)) { PopIndent();#>}#endregion //<- and here<#+ }}
Then tell Resharper to simply skip checking anything that is within region ”EF Generated Code” from ReSharper -> Options -> Generated Code
Done!