Check if a Type is declared public in CSharp
Description
The following code shows how to check if a Type is declared public.
Example
//from w w w. ja va 2s . c o m
using System;
namespace SystemType
{
public class MyTestClass
{
}
public class MyClass
{
public static void Main(string []args)
{
bool myBool = false;
MyTestClass myTestClassInstance = new MyTestClass();
Type myType = myTestClassInstance.GetType();
myBool = myType.IsPublic;
Console.WriteLine("\nIs {0} public? {1}.", myType.FullName, myBool.ToString ());
}
}
}
The code above generates the following result.