Search Amazon:

Page 5 of 10               << Previous  1  2  3  4  5  6  7  8  9  10  Next >>

 

Custom FxCop Rule - Do Use the VB Compatibility Namespace

The Microsoft VisualBasic Compatability namespace is used to invoke older VB6 functionality in VB.NET code. To use this namespace, you need to set a reference to it. So to test for this we can look at the assemblies referenced by our assembly.

C# code for custom FxCop rule:

using System;
using Microsoft.Cci;
using Microsoft.FxCop.Sdk;
using Microsoft.FxCop.Sdk.Introspection;

public class DoNotUseVBCompatibilityNamespace : BaseMigrationIntrospectionRule
{
    public DoNotUseVBCompatibilityNamespace()
        : base("DoNotUseVBCompatibilityNamespace")
    {
    }

    public override ProblemCollection Check(Module module)
    {
        if (module == null)
            return base.Check(module);

        AssemblyReferenceList refList = module.AssemblyReferences;
        foreach (AssemblyReference reference in refList)
        {
            if (reference.Name.ToUpper().Contains("MICROSOFT.VISUALBASIC.COMPATIBILITY"))
                base.Problems.Add(new Problem(GetResolution(module.Name), module));
        }

        return base.Problems;
    }
}

Rule definition in the XML rules file:

<Rule TypeName="DoNotUseVBCompatibilityNamespace" 
          Category="VBMigration" CheckId="AA1001">
    <Name>
        Do not use 'Microsoft.VisualBasic.Compatibility' namespace
    </Name>
    <Description>
        Avoid dependency on the Microsoft.VisualBasic.Compatibility namespace
    </Description>
    <Url>
        http://www.thescarms.com/
    </Url>
    <Resolution>
        '{0}' has imported the namespace of 'Microsoft.VisualBasic.Compatibility' or 
        'Microsoft.VisualBasic.Compatibility.Data'. Replace the code that references this 
        namespace with the .NET equivalent
    </Resolution>
    <MessageLevel Certainty="99">
        Warning
    </MessageLevel>
    <FixCategories>
        NonBreaking
    </FixCategories>
    <Owner />
<Rule>

 

Page 5 of 10               << Previous  1  2  3  4  5  6  7  8  9  10  Next >>

Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Comments: 1 Items to Show:     

     
Id:  1 Posted:  5/6/2007 4:41:00 PM By:  PSMACCHIA
With the CQL language provided with NDepend, coding this rule is as simple as:

WARN IF Count > 0 IN SELECT METHODS WHERE IsDirectlyUsing "Microsoft.VisualBasic.Compatibility"

http://www.NDepend.com
 
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms