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

 

Custom FxCop Rule - Do not use MSFlexGrid Interop

All of the older VB6 and even VB5 ActiveX controls can be used in VB.NET. To use these older COM controls, .NET uses the interoperability layer and creates an interop dll. If you add an older control, such as the MS FlexGrid in this example, to a VB.NET application and compile it, you will see an Interop.MSFlexGrid.dll in the bin folder. To spot a reference to an older component in FxCop, look at the list of referenced assemblies.

C# code for custom FxCop rule:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Cci;
using Microsoft.FxCop.Sdk;
using Microsoft.FxCop.Sdk.Introspection;

public class DoNotUseMSFlexGridInterop : BaseMigrationIntrospectionRule
{
    public DoNotUseMSFlexGridInterop()
        : base("DoNotUseMSFlexGridInterop")
    {
    }
    public override ProblemCollection Check(Module module)
    {
        if (module == null)
            return base.Check(module);

        AssemblyReferenceList asmRefList = module.AssemblyReferences;
        foreach (AssemblyReference asmReference in asmRefList)
        {
            if (asmReference.Name.ToUpper().Contains("MSFLEXGRIDLIB"))
            {
                base.Problems.Add(new Problem(GetResolution(module.Name), module));
            }
        }

        return base.Problems;
    }
}

Rule definition in the XML rules file:

<Rule TypeName="DoNotUseMSFlexGridInterop" 
          Category="VBMigration" CheckId="AA1001">
    <Name>
        Do not use 'Interop.MSFlexGridLib' namespace
    </Name>
    <Description>
        Avoid dependency on the COM Interop for the older MSFlexGrid
    </Description>
    <Url>
        http://www.thescarms.com/
    </Url>
    <Resolution>
        '{0}' has imported the namespace 'Interop.MSFlexGridLib'. 
         Replace the Microsoft FlexGrid 6.0 with equivalent .NET control.
    </Resolution>
    <MessageLevel Certainty="99">
        Warning
    </MessageLevel>
    <FixCategories>
        NonBreaking
    </FixCategories>
    <Owner />
<Rule>

 

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