笔记 Activator.CreateInstance(Type)
这段代码取自NopCommerce 3.80 的 权限列表初始化代码
dynamic provider = Activator.CreateInstance(providerType);
文件位置 Presentation\Nop.Web\Controllers\InstallController.cs
//register default permissions
//var permissionProviders = EngineContext.Current.Resolve<ITypeFinder>().FindClassesOfType<IPermissionProvider>();
var permissionProviders = new
List<Type>();
permissionProviders.Add(typeof(StandardPermissionProvider));
foreach (var providerType in permissionProviders)
{
dynamic provider = Activator.CreateInstance(providerType);
EngineContext.Current.Resolve<IPermissionService>().InstallPermissions(provider);
}
方法定义
//
// 摘要:
// 使用指定类型的默认构造函数来创建该类型的实例。
//
// 参数:
// type:
// 要创建的对象的类型。
//
// 返回结果:
// 对新创建对象的引用。
//
public
static
object CreateInstance(Type type);
笔记 Activator.CreateInstance(Type)的更多相关文章
- Activator.CreateInstance 方法 (Type) 的用法
转自:http://www.cnblogs.com/lmfeng/archive/2012/01/30/2331666.html Activator.CreateInstance 方法 (Type) ...
- Type.GetType反射的对象创建Activator.CreateInstance
/// <summary> /// 获取对应类的实现 /// </summary> /// <param name="libname">< ...
- C# Activator.CreateInstance()方法使用
C#在类工厂中动态创建类的实例,所使用的方法为: 1. Activator.CreateInstance (Type) 2. Activator.CreateInstance (Type, Objec ...
- 注意Activator.CreateInstance两个重载方法的性能
今天扩展一个Type的扩展方法New: public static object New(this Type type, params object[] args) { Guard.ArgumentN ...
- C# Activator.CreateInstance()
C#在类工厂中动态创建类的实例,所使用的方法为: 1. Activator.CreateInstance (Type) 2. Activator.CreateInstance (Type, Objec ...
- (转) C# Activator.CreateInstance()方法使用
C#在类工厂中动态创建类的实例,所使用的方法为: 1. Activator.CreateInstance (Type) 2. Activator.CreateInstance (Type, Objec ...
- C#中Activator.CreateInstance()方法用法分析
本文实例讲述了C#中Activator.CreateInstance()方法用法. Activator 类 包含特定的方法,用以在本地或从远程创建对象类型,或获取对现有远程对象的引用. C#在类工厂中 ...
- cSharp:use Activator.CreateInstance with an Interface?
///<summary> ///数据访问工厂 ///生成時間2015-2-13 10:54:34 ///塗聚文(Geovin Du) /// (利用工厂模式+反射机制+缓存机制,实现动态创 ...
- Assembly.CreateInstance和Activator.CreateInstance
本来是在设计模式中的工厂方法,在实现抽象工厂时,用到了一直都不熟悉的反射. namespace Factory { public abstract class Factory { public abs ...
随机推荐
- @Html.AntiForgeryToken() 源码分析,表单防伪码的生成
源码来自MVC4@Html.AntiForgeryToken() 源码分析 public MvcHtmlString AntiForgeryToken() { return new MvcHtmlSt ...
- 用SQL数据库做多表关联应怎样设计库结构20170527
http://77857.blog.51cto.com/67857/143872/ 多表关联的话表之间必须得存在关系才行呢,这样建立外键约束就行了, 关系表中插入主表的主键做外键. 假设表1学生表st ...
- Ubuntu16.04启动xtion pro live报错
william@william-System-Product-Name:~$ roslaunch openni2_launch openni2.launch ... logging to /home/ ...
- PAT1089【归并排序】
这题略...恶心.. 他说归并排序依次是相邻有序两块合并,而一向打惯了递归??? #include <bits/stdc++.h> using namespace std; typedef ...
- java二分法查找实现代码
package util; class BinarySearch { static int binarySearch(int[] array,int goal){//传入排好序的数组和目标数字 int ...
- 清北刷题冲刺 11-03 a.m
纸牌 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...
- 2017-10-4 清北刷题冲刺班p.m
P102zhx a [问题描述]你是能看到第一题的 friends 呢.——hja两种操作:1.加入一个数.2.询问有多少个数是?的倍数.[输入格式]第一行一个整数?,代表操作数量.接下来?行,每行两 ...
- 为CentOS下的Docker安装配置python3【转】
* 安装python3以及docker yum install docker docker pull centos service docker start systemctl enable dock ...
- springboot 简单使用shiro登录
首先引入需要的pom <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shir ...
- 如何使用JMETER从JSON响应中提取数据
如果你在这里,可能是因为你需要使用JMeter从Json响应中提取变量. 好消息!您正在掌握掌握JMeter Json Extractor的权威指南.作为Rest API测试指南的补充,您将学习掌握J ...