c#.net 中有没类似JAVA的 Class.for("...") 的用法,用来返回 class
typeof(类型)
对象.GetType()
Type.GetType("类型名字符串")
如果问题解决,麻烦点下我的回答右边的采纳,谢谢
using System;
using System.Reflection;
namespace Test{
class Test{
public void test(){
Type type=Assembly.GetType("Test.A"); //获取 类型
objects a=Activator.CreateInstance(type); //创建类型。
}
}
class A{
pulic string A{get;set;}
}
}
扩展阅读https://www.cnblogs.com/wangchuang/p/4923621.html
ps:代码多,不想写。文章里,包括了怎么通过方法名调用等。
搜索关键词: C# 反射机制 ,C# 动态调用,C# Appdomain , C# MarshalByRefObject ,C# 远程通信。按照这些关键词去翻看博客园相关文章,很有用。
再给篇 : http://blog.csdn.net/xiaoxian8023/article/details/8715837 这是热部署,动态编译相关
objects 改为 object ,手抖,打多了。。最好把C# 的程序集看看。。。