Domanda

I have a class that looks like the following:

Public Class Utilities
    Public Shared Function blah(userCode As String) As String
        'doing some stuff
    End Function
End Class

I'm running FxCop 10 on it and it says:

"Because type 'Utilities' contains only 'static' (
'Shared' in Visual Basic) members, add a default private 
constructor to prevent the compiler from adding a default 
public constructor."

Ok, you're right Mr. FxCop, I'll add a private constructor:

Private Utilities()

Now I'm having:

"It appears that field 'Utilities.Utilities' is 
never used or is only ever assigned to. Use this field 
or remove it."

Any ideas of what should I do to get rid of both warnings?

È stato utile?

Soluzione

In C# this problem would be handled by marking the class as static, e.g.

public static class Utilities
{
   ...
}

A static class can only contain static (in VB shared) members.

I believe the equivalent in VB.NET is to use a module.

See Marking A Class Static in VB.NET.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top