Click here to Skip to main content
12,350,728 members (24,088 online)
Click here to Skip to main content

Stats

46.7K views
844 downloads
60 bookmarked
Posted

Static Code Analysis

, 15 Mar 2010 CPOL
A static code analyzer building method call networks + sample applications.
Generator
bin
.noclean
Arebis.CodeAnalysis.Static.dll
Arebis.CodeGeneration.dll
Arebis.CodeGeneration.VisualStudio.dll
Arebis.CodeGenerator.dll
Arebis.Common.dll
CGen.exe
Content.cst
Content.cst.gen
COperation.cst
COperation.cst.gen
files
GeneratorMain.cst
GeneratorMain.cst.gen
Index.cst
Index.cst.gen
IndexTop.cst
IndexTop.cst.gen
SOperation.cst
SOperation.cst.gen
UIOperation.cst
UIOperation.cst.gen
Output
SampleApp
LocalTestRun.testrunconfig
ToDoApplication
Infrastructure
Properties
Service References
ToDoContract
Properties
ToDoSample.vsmdi
ToDoService
Entities.edmx
Infrastructure
Properties
ToDoSample.Service.csproj.user
ToDoSampleDb.mdf
ToDoSampleDb_log.ldf
ToDoUnitTests
Properties
Testing
ToDoSample.UnitTests.csproj.user
UnitTests
StaticCodeAnalyzer
Arebis.CodeAnalysis.Static
Arebis.CodeAnalysis.Static.csproj.user
CodeModel.cd
Processors
Rules
Properties
Arebis.Common
Arebis
Collections
Generic
Reflection
Properties
System
Collections
Generic
Net2
Threading
Net2
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Arebis.CodeAnalysis.Static;
using System.Security.Permissions;

public static class HelperExtension
{
    public static IList<ModelMethod> Sorted(this IEnumerable<ModelMethod> methods)
	{
        List<ModelMethod> result = new List<ModelMethod>(methods);
		result.Sort(new MethodComparer());
		return result;
	}

    public static string DisplayString(this ModelMethod subject)
    {
        return subject.DeclaringType.Name + "." + subject.Name;
    }

    public static string ToFilename(this ModelMethod subject, string format)
	{
        string str = subject.Signature;
		str = str.Replace("<", "[");
        str = str.Replace(">", "]");
        str = str.Replace("*", "_");
        str = str.Replace("?", "_");
        str = str.Replace(":", "_");
        str = str.Replace(" ", "");
		return String.Format(format, str);
	}

    public static string ToLink(this ModelMethod subject, string format)
    {
        return subject.ToLink(format, null);
    }

    public static string ToLink(this ModelMethod subject, string format, object options)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<a href=\"");
        sb.Append(subject.ToFilename(format));
        sb.Append("\"");
        foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(options))
            sb.AppendFormat(" {0}=\"{1}\"", prop.Name, prop.GetValue(options));
        sb.Append(">");
        sb.Append(subject.DisplayString());
        sb.Append("</a>");

        return sb.ToString();
    }

    public static string[] RequiredRoles(this ModelMethod subject)
    {
        List<string> roles = new List<string>();
        foreach (var item in Attribute.GetCustomAttributes(subject.MethodBase, typeof(PrincipalPermissionAttribute)))
            roles.Add(((PrincipalPermissionAttribute)item).Role);

        return roles.ToArray();
    }

    public static bool IsFullyImplemented(this ModelMethod subject)
    {
        return (subject.GetAllCallsMethods().WhereTagsContains("missingimplementationexception").Count() == 0);
    }
}

public class MethodComparer : System.Collections.Generic.IComparer<ModelMethod>
{
    int IComparer<ModelMethod>.Compare(ModelMethod left, ModelMethod right)
	{
		string leftname = (left.Name.Contains(".") ? left.Signature : left.DeclaringType.ToString() + "." + left.Signature);
		string rightname = (right.Name.Contains(".") ? right.Signature : right.DeclaringType.ToString() + "." + right.Signature);
		return leftname.CompareTo(rightname);
	}
}

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rudi Breedenraedt
Architect Wolters Kluwer Belgium
Belgium Belgium
Rudi is a Software Architect at Wolters Kluwer Belgium.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 15 Mar 2010
Article Copyright 2010 by Rudi Breedenraedt
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid