CA1812 = Code Analysis

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Ok, So call me dumb.

But I get a CA1812 erorr when I have a Class with Shared methods. How do I
get around this with out instantiating the class. I want it to be like a
module. Thus a static class. Which I thought I was doing be making the
methods public shared.

By the way the code works fine. But CA dosn't like it.

Any suggestions?

Thanks,
Jojo
 
Even if you don't specify a public constructor, it's still possible to
create instances of your class because compilers will emit a default public
constructor when none are declared in code. If the class only contains
static (Shared) methods then make it sealed (NotInheritable) and give it a
private constructor to prevent the compiler from emitting one.
 
But can I set a private constructor on a class that is not contained in any
other type?

Aka its simply a class in a vb file like

Private class bah

end class

--> will this not throw an error about using private at this level.
Im wanting a class that acts just like a module. I mean it all works great,
its just dumb CA dosn't like it.

Thanks,
Jojo
 
Haha , yeah call me dumb.. I wasn't thinking. I was thinking attributes not
constructors.

Once I set the constructor to private it worked great. Grr I need to get
some sleep.

Thanks so much for your help!
 
Back
Top