Examples:
1) internal class UninstantiatedInternalClass
{
public void display ()
{
Console.WriteLine ("Display...");
}
public static void Main (string [] args)
{
}
}
This is bad.
2) internal class InstantiatedInternalClass
{
public void display ()
{
Console.WriteLine ("Display...");
}
public static void Main (string [] args)
{
InstantiatedInternalClass i = new
InstantiatedInternalClass ();
i.display ();
}
}
This is good.
3) using System;
using System.Runtime.CompilerServices;
[assembly:InternalsVisibleToAttribute("MyAssembly")]
internal class UninstantiatedVisibleInternalClass
{
internal UninstantiatedVisibleInternalClass ()
{
}
public void display ()
{
Console.WriteLine ("Display...");
}
}
This should not raise error as the class is visible to other
assemblies, it is possible to have been instantiated there.
4) static internal class StaticClassThatCannotBeInstantiated
{
public static void display ()
{
Console.WriteLine ("Display..");
}
public static void Main (string [] args)
{
}
}
This should not generate an error as the class is static and so
cannot be instantiated.
5) internal class Book
{
public static Book Create()
{
return new Book();
}
}
This is bad because instance is returned by the method that is
never used.
Link for the rule is:
http://mono-soc-2007.googlecode.com/svn/trunk/nidhi/rules/Gendarme.Rules.Performance/AvoidUninstantiatedInternalClassesRule.cs
Link for test-cases is:
http://mono-soc-2007.googlecode.com/svn/trunk/nidhi/rules/Gendarme.Rules.Performance/Test/AvoidUninstantiatedInternalClassesTest.cs
> Reference:http://blogs.msdn.com/fxcop/archive/2007/08/09/what-rules-do-microsof...