Code Analysis

Posts   
 
    
MRW
User
Posts: 2
Joined: 17-Jan-2008
# Posted on: 11-Apr-2008 12:21:53   

We are using LLBLGen Pro 2.5, currently with the SelfServicing template, but we might be migrating to Adapter soon.

However, we have noticed that the generated code generates a lot of warnings in VS 2008 Code Analysis. cry This is a pity, because we are using Team Foundation Server and would like to use CA as part of our QA strategy. At the moment, we have to disable CA for the generated code, which means we cannot run CA over any custom code that it contains.

Are there any plans to make the generated code more "CA compliant"?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Apr-2008 15:33:24   

Would you please post a sample of these warnings?

MRW
User
Posts: 2
Joined: 17-Jan-2008
# Posted on: 11-Apr-2008 15:53:32   

Ok. Here are some examples (sorry for screwing up the layout) flushed :

**Warning 17 CA1011 : **Microsoft.Design : Consider changing the type of parameter 'entityWithNewValues' in 'FormulierCollection.UpdateMultiManyToOne(FormulierEntity, IEntity)' from 'FormulierEntity' to its base type 'IEntity'. This method appears to only require base class members in its implementation. Suppress this violation if there is a compelling reason to require the more derived type in the method signature. C:\Projects\IC2it.Zorglijn.Formulieren\IC2it.Zorglijn.Formulieren.Entities\CollectionClasses\FormulierCollection.cs 35 IC2it.Zorglijn.Formulieren.Entities

        public int UpdateMultiManyToOne(FormulierEntity entityWithNewValues, IEntity formulierTemplateDesignInstance)
        {
            FormulierDAO dao = DAOFactory.CreateFormulierDAO();
            return dao.UpdateMulti(entityWithNewValues, base.Transaction, formulierTemplateDesignInstance);
        }

**Warning 16 CA1405 : **Microsoft.Interoperability : 'FormulierCollection' is marked ComVisible(true) but has the following ComVisible(false) types in its object hierarchy: SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase1<IC2it.Zorglijn.Formulieren.Entities.EntityClasses.FormulierEntity>, SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore1<IC2it.Zorglijn.Formulieren.Entities.EntityClasses.FormulierEntity> C:\Projects\IC2it.Zorglijn.Formulieren\IC2it.Zorglijn.Formulieren.Entities\CollectionClasses\FormulierCollection.cs 5 IC2it.Zorglijn.Formulieren.Entities

**Warning 21 CA1709 : **Microsoft.Naming : Correct the casing of 'DAO' in type name 'FormulierDAO' by changing it to 'Dao'. C:\Projects\IC2it.Zorglijn.Formulieren\IC2it.Zorglijn.Formulieren.Entities\DaoClasses\FormulierDAO.cs 6 IC2it.Zorglijn.Formulieren.Entities


public partial class FormulierDAO : DaoBase

**Warning 22 CA1811 **: Microsoft.Performance : 'FormulierDAO.FormulierDAO(IInheritanceInfoProvider, DynamicQueryEngineBase, InheritanceHierarchyType, string, IEntityFactory)' appears to have no upstream public or protected callers. C:\Projects\IC2it.Zorglijn.Formulieren\IC2it.Zorglijn.Formulieren.Entities\DaoClasses\FormulierDAO.cs 9 IC2it.Zorglijn.Formulieren.Entities

/// <summary>CTor</summary>
        /// <param name="inheritanceInfoProviderToUse">Inheritance info provider to use.</param>
        /// <param name="dqeToUse">Dqe to use.</param>
        /// <param name="typeOfInheritance">Type of inheritance.</param>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="entityFactory">Entity factory.</param>
        internal FormulierDAO(IInheritanceInfoProvider inheritanceInfoProviderToUse, DynamicQueryEngineBase dqeToUse, InheritanceHierarchyType typeOfInheritance, string entityName, IEntityFactory entityFactory) : base(inheritanceInfoProviderToUse, dqeToUse, typeOfInheritance, entityName, entityFactory)
        {
        }

**Warning 25 CA1804 **: Microsoft.Performance : 'FormulierDAO.GetMultiAsDataTable(long, ISortExpression, IPredicate, IRelationCollection, int, int)' declares a variable, 'fieldsToReturn', of type 'IEntityFields', which is never used or is only assigned to. Use this variable or remove it. C:\Projects\IC2it.Zorglijn.Formulieren\IC2it.Zorglijn.Formulieren.Entities\DaoClasses\FormulierDAO.cs 6 IC2it.Zorglijn.Formulieren.Entities

public virtual DataTable GetMultiAsDataTable(long maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, int pageNumber, int pageSize)
        {
            IEntityFields fieldsToReturn = EntityFieldsFactory.CreateEntityFieldsObject(IC2it.Zorglijn.Formulieren.Entities.EntityType.FormulierEntity);
            return base.PerformGetMultiAsDataTableAction(maxNumberOfItemsToReturn, sortClauses, selectFilter, relations, pageNumber, pageSize);
        }
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 11-Apr-2008 17:08:06   

The layout is screwed up due to the copies from the vs.net error form. I've cleaned it up a bit

Keep in mind that most of these analysis results often are pretty much ignorable. Like 'Change the casing in 'LLBLGenPro' or 'DAO'. Or 'Don't prefix private member variables'. Sure microsoft, why are you doing it yourself? wink . It's not problematic to have these warnings. When you browse through all the possible settings for code analysis you'll run into contradicting rules which ... are both enabled! simple_smile Like the one where enums should be annotated with FlagsAttribute and in another section enums aren't allowed to have FlagsAttribute smile

Anyway, I've commented on them below:

MRW wrote:

Ok. Here are some examples (sorry for screwing up the layout) flushed :

**Warning 17 CA1011 : **Microsoft.Design : Consider changing the type of parameter 'entityWithNewValues' in 'FormulierCollection.UpdateMultiManyToOne(FormulierEntity, IEntity)' from 'FormulierEntity' to its base type 'IEntity'. This method appears to only require base class members in its implementation. Suppress this violation if there is a compelling reason to require the more derived type in the method signature.

        public int UpdateMultiManyToOne(FormulierEntity entityWithNewValues, IEntity formulierTemplateDesignInstance)
        {
            FormulierDAO dao = DAOFactory.CreateFormulierDAO();
            return dao.UpdateMulti(entityWithNewValues, base.Transaction, formulierTemplateDesignInstance);
        }

I could change this, though I find it a bit unnecessary. (as in: time spend on this is really wasted time as it adds no value at all. In fact it might cause a problem at runtime when the wrong entity type was passed in: you now catch that at compile time. )

**Warning 16 CA1405 : **Microsoft.Interoperability : 'FormulierCollection' is marked ComVisible(true) but has the following ComVisible(false) types in its object hierarchy: SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionBase1<IC2it.Zorglijn.Formulieren.Entities.EntityClasses.FormulierEntity>, SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore1<IC2it.Zorglijn.Formulieren.Entities.EntityClasses.FormulierEntity> C:\Projects\IC2it.Zorglijn.Formulieren\IC2it.Zorglijn.Formulieren.Entities\CollectionClasses\FormulierCollection.cs 5 IC2it.Zorglijn.Formulieren.Entities

Did you add ComVisible(true) to your generated code project? Anyway, you can safely ignore this. The runtimelib doesn't have ComVisible(true) in the assembly properties. (edit) ComVisible(true) is on by default through the compiler. Ignore this warning.

**Warning 21 CA1709 : **Microsoft.Naming : Correct the casing of 'DAO' in type name 'FormulierDAO' by changing it to 'Dao'. C:\Projects\IC2it.Zorglijn.Formulieren\IC2it.Zorglijn.Formulieren.Entities\DaoClasses\FormulierDAO.cs 6 IC2it.Zorglijn.Formulieren.Entities


public partial class FormulierDAO : DaoBase

This really isn't going to change, it will break all code previously written by it.

**Warning 22 CA1811 **: Microsoft.Performance : 'FormulierDAO.FormulierDAO(IInheritanceInfoProvider, DynamicQueryEngineBase, InheritanceHierarchyType, string, IEntityFactory)' appears to have no upstream public or protected callers. C:\Projects\IC2it.Zorglijn.Formulieren\IC2it.Zorglijn.Formulieren.Entities\DaoClasses\FormulierDAO.cs 9 IC2it.Zorglijn.Formulieren.Entities

/// <summary>CTor</summary>
        /// <param name="inheritanceInfoProviderToUse">Inheritance info provider to use.</param>
        /// <param name="dqeToUse">Dqe to use.</param>
        /// <param name="typeOfInheritance">Type of inheritance.</param>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="entityFactory">Entity factory.</param>
        internal FormulierDAO(IInheritanceInfoProvider inheritanceInfoProviderToUse, DynamicQueryEngineBase dqeToUse, InheritanceHierarchyType typeOfInheritance, string entityName, IEntityFactory entityFactory) : base(inheritanceInfoProviderToUse, dqeToUse, typeOfInheritance, entityName, entityFactory)
        {
        }

i.o.w.: dead code. We could remove that from v2.6's template.

**Warning 25 CA1804 **: Microsoft.Performance : 'FormulierDAO.GetMultiAsDataTable(long, ISortExpression, IPredicate, IRelationCollection, int, int)' declares a variable, 'fieldsToReturn', of type 'IEntityFields', which is never used or is only assigned to. Use this variable or remove it. C:\Projects\IC2it.Zorglijn.Formulieren\IC2it.Zorglijn.Formulieren.Entities\DaoClasses\FormulierDAO.cs 6 IC2it.Zorglijn.Formulieren.Entities

public virtual DataTable GetMultiAsDataTable(long maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, int pageNumber, int pageSize)
        {
            IEntityFields fieldsToReturn = EntityFieldsFactory.CreateEntityFieldsObject(IC2it.Zorglijn.Formulieren.Entities.EntityType.FormulierEntity);
            return base.PerformGetMultiAsDataTableAction(maxNumberOfItemsToReturn, sortClauses, selectFilter, relations, pageNumber, pageSize);
        }

Also dead code flushed . Will be removed in v2.6 as well.

We'll schedule a code analysis run on both paradigms in vs.net 2008 before v2.6 ships so we'll get most of these things sorted. Still, we can't possibly get 0 warnings as there's always some lame warning no-one will care about which will pop up.

Frans Bouma | Lead developer LLBLGen Pro