c# - Assembly.CreateInstance 和 Activator.CreateInstance 之间的区别?

标签 c# reflection assemblies

这些调用有什么区别?

最佳答案

没有。 Assembly.CreateInstance 实际上在幕后调用了 Activator.CreateInstance。

在 Assembly.CreateInstance 上使用反射器:

public object CreateInstance(string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes)
{
    Type type = this.GetType(typeName, false, ignoreCase);
    if (type == null)
    {
        return null;
    }
    return Activator.CreateInstance(type, bindingAttr, binder, args, culture, activationAttributes);
}

关于c# - Assembly.CreateInstance 和 Activator.CreateInstance 之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1833615/

相关文章:

c# - 在哪里放置 InternalsVisibleTo

c# - 从本地数据库更改为托管在服务器上的 SQL Server

c# - 在 Visual Studio 中启用 TagHelper Intellisense 支持

java - 是否可以找到特定方法内的方法调用列表?

.net - 解析程序集合格名称?

.net - 如何在登台服务器中调试 .net dll 程序集

c# - 表单关闭前保存更改

c# - JContainer、JObject、JToken和Linq混淆

c# - 您如何使用反射获取类及其基类(在层次结构中向上)的所有属性? (C#)

Android、method.invoke 在 SDK 26、Oreo 中崩溃?