【发布时间】:2016-03-27 09:32:56
【问题描述】:
正如标题所说,我如何确定一个特定的类是公共的还是私有的?
我尝试了多种方法,但均未成功,并且在此站点中找不到此问题的任何答案。
using System;
namespace ReflectionPublicClass
{
public class Program
{
private class Jedi
{
public int MidiChlorians { get; set; }
}
static void Main(string[] args)
{
Type type = typeof(Jedi);
try
{
Jedi obi = (Jedi)Activator.CreateInstance(type);
// If public class do something
// If private do something else
}
catch (Exception)
{
throw;
}
}
}
}
【问题讨论】:
-
你到底尝试了什么?为此使用反射。
-
如果一个类是私有的,那么它肯定是不可访问的。
-
如何确定?你在哪里有这个班?你能显示一些代码吗?
-
@CodeCaster 我添加了一些代码
-
System.Type 有一个IsPublic property ...