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 >>




About TheScarms
About TheScarms


Sample code
version info

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

Email this page


© Copyright 2024 TheScarms
Goto top of page