This article describes the operation of a method-based static code analyzer for .NET that constructs in-memory method call networks of compiled assemblies. You will also see a concrete application of static code analysis to generate a website providing easy insights on a sample application.
- codeanalyzerandtodosample.zip
- CodeAnalyzer and Sample Solution.sln
- Generate.cmd
- Generator
- Output
- Blank.html
- co_CreateToDoItem(int,string,Nullable[DateTime])_ToDoItem.html
- co_DeleteToDoItem(int)_void.html
- co_FindUserByName(string)_User.html
- co_GetToDoItem(int)_ToDoItem.html
- co_GetUser(int)_User.html
- co_ListAllToDoItems()_IEnumerable[ToDoItem].html
- co_ListAllUsers()_IEnumerable[User].html
- co_ListDoneItemsForUser(int)_IEnumerable[ToDoItem].html
- co_ListToDoItemsForUser(int)_IEnumerable[ToDoItem].html
- co_ListUsersMatching(string)_IEnumerable[User].html
- co_MarkToDoItemDone(int)_void.html
- co_UpdateToDoItem(int,string,Nullable[DateTime])_void.html
- CodeModel.css
- CodeModel.js
- Content.html
- Index.html
- IndexTop.html
- so_CreateToDoItem(int,string,Nullable[DateTime])_ToDoItem.html
- so_DeleteToDoItem(int)_void.html
- so_FindUserByName(string)_User.html
- so_GetUser(int)_User.html
- so_ListAllUsers()_List[User].html
- so_ListDoneItemsForUser(int)_List[ToDoItem].html
- so_ListToDoItemsForUser(int)_List[ToDoItem].html
- so_ListUsersMatching(string)_List[User].html
- so_MarkToDoItemDone(int)_void.html
- so_UpdateToDoItem(int,string,Nullable[DateTime])_ToDoItem.html
- ui_CreateNewToDoItemClicked(object,System.Windows.RoutedEventArgs)_void.html
- ui_DeleteClicked(object,System.Windows.RoutedEventArgs)_void.html
- ui_InitializeComponent()_void.html
- ui_MarkDoneClicked(object,System.Windows.RoutedEventArgs)_void.html
- ui_RefreshToDoItems()_void.html
- ui_SaveClicked(object,System.Windows.RoutedEventArgs)_void.html
- ui_ToDoItemSelected(object,System.Windows.Controls.SelectionChangedEventArgs)_void.html
- ui_UserSelected(object,System.Windows.Controls.SelectionChangedEventArgs)_void.html
- ui_WindowLoaded(object,System.Windows.RoutedEventArgs)_void.html
- SampleApp
- LocalTestRun.testrunconfig
- ToDoApplication
- ToDoContract
- ToDoSample.vsmdi
- ToDoService
- ToDoUnitTests
- StaticCodeAnalyzer
- Arebis.CodeAnalysis.Static
- Arebis.Common
|
<?xml version="1.0" encoding="utf-8" ?>
<analyzer
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblies>
<!-- Include the mscorlib.dll to have access to the NotImplementedException constructor methods -->
<assembly file="mscorlib.dll" />
<!-- Include the client-tier assemblies -->
<filepatterns path="..\SampleApp\ToDoApplication\bin\Debug">
<add value="*.exe" />
<add value="*.dll" />
</filepatterns>
<!-- Include the service-tier assemblies -->
<filepatterns path="..\SampleApp\ToDoService\bin\Debug">
<add value="*.dll" />
</filepatterns>
<!-- Include the unittest assemblies -->
<filepatterns path="..\SampleApp\ToDoUnitTests\bin\Debug">
<add value="*.dll" />
</filepatterns>
</assemblies>
<!-- Set the language in which to express method signatures to C# and
consider the given namespaces as imported -->
<language code="C#">
<import namespace="System" />
<import namespace="System.Collections" />
<import namespace="System.Collections.Generic" />
<import namespace="ToDoSample.Contract" />
<import namespace="ToDoSample.Service"/>
</language>
<processors>
<!-- The specialmethodsprocessor adds tags "constructor" (and others) to methods to ease
processing by the rule based processor -->
<specialmethodsprocessor handler="Arebis.CodeAnalysis.Static.Processors.SpecialMethodsProcessor" />
<!-- The rule based processor with its rules -->
<rulesprocessor handler="Arebis.CodeAnalysis.Static.Processors.RulesProcessor">
<definitions>
<assembly path="bin\Arebis.CodeAnalysis.Static.dll" />
</definitions>
<rulesets>
<ruleset name="_skip">
<!-- the _skip tag has special meaning for the rule based processor: methods matching this rule are not processed further -->
<namerule like="System.Windows.Markup.IComponentConnector.Connect" target="Method" />
</ruleset>
<ruleset name="uioperation">
<basetyperule type="System.Windows.Controls.Control"/>
<tagrule name="accessor" reverse="true"/>
<tagrule name="constructor" reverse="true"/>
</ruleset>
<ruleset name="serviceoperationdefinition">
<attributerule type="System.ServiceModel.ServiceContractAttribute" target="Type" />
<modifierrule modifiers="Interface" target="Type" />
</ruleset>
<ruleset name="serviceoperationimplementation">
<attributerule type="System.ServiceModel.ServiceBehaviorAttribute" target="Type" />
<tagrule name="constructor" reverse="true"/>
</ruleset>
<ruleset name="explicitimplements">
<!-- Explicit interface implementations have methodnames containing dots -->
<namerule match=".*\..*" target="Method"/>
</ruleset>
<ruleset name="componentoperation">
<modifierrule modifiers="FamANDAssem" target="Method"/>
<modifierrule modifiers="Static" target="Method"/>
<namerule target="Type" like="*ComponentManager"/>
<tagrule name="constructor" reverse="true"/>
</ruleset>
<ruleset name="systemexception">
<basetyperule type="System.Exception"/>
<namerule target="Type" like="System.*"/>
</ruleset>
<ruleset name="applicationexception">
<basetyperule type="System.Exception"/>
<tagrule name="constructor"/>
<tagrule name="systemexception" reverse="true"/>
</ruleset>
<ruleset name="missingimplementationexception">
<basetyperule type="System.NotImplementedException"/>
<tagrule name="constructor"/>
</ruleset>
<ruleset name="unittest">
<attributerule type="Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute" target="Method"/>
</ruleset>
<ruleset name="defaultimplementation">
<!-- Methods with the serviceoperationimplementation tag are connected to their interface definition -->
<tagrule name="serviceoperationimplementation"/>
</ruleset>
<ruleset name="leafmethod">
<!-- Exceptions are made leaf to break the link to the supertype constructor -->
<tagrule name="applicationexception"/>
</ruleset>
<ruleset name="leafmethod">
<!-- We are not interested in the methodcalls within the System namespace -->
<namerule target="Type" like="System.*"/>
</ruleset>
</rulesets>
</rulesprocessor>
<!-- The defaultimplementationprocessor connects methods with the defaultimplementation tag to their interface definition -->
<defaultimplementationprocessor handler="Arebis.CodeAnalysis.Static.Processors.DefaultImplementationProcessor" />
<!-- The defaultmethodprocessor connects methods with the defaultmethod to their types constructor (not used here) -->
<defaultmethodprocessor handler="Arebis.CodeAnalysis.Static.Processors.DefaultMethodProcessor" />
<!-- The virtualmethodprocessor connects virtual methods to their base definition if it has the baseimplementation tag (not used here) -->
<virtualmethodprocessor handler="Arebis.CodeAnalysis.Static.Processors.VirtualMethodProcessor" />
<!-- The leafmethodprocessor disconnects methods with the leafmethod tag -->
<leafmethodprocessor handler="Arebis.CodeAnalysis.Static.Processors.LeafMethodProcessor" />
</processors>
</analyzer>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.