According to this StackOverflow question, one can use the Type.IsAbstract
and Type.IsSealed
properties to determine if a class is static. However, look at the following test:
[Fact]
public void ActivatorNotAbstract()
{
var activatorType = typeof(Activator);
Assert.True(activatorType.IsClass);
Assert.True(activatorType.IsSealed);
Assert.True(activatorType.IsAbstract);
}
This test fails because the last assertion is not true, although System.Activator
is defined as a static class. This is both true for .NET Core 2.0 (and probably previous versions) as well as .NET 4.5 (and probably other versions, too). You can also find the above test in this GitHub repo.
Why is Activator
special in this regard? I couldn't find any other static class in the BCL that would behave this way.
Aucun commentaire:
Enregistrer un commentaire