摘要:反射
XXXXX obj = new XXXXX();
Type tp = obj.GetType();
System.Reflection.PropertyInfo pinfo = tp.GetProperty("xxxx"); //获取obj对象的指定名称为xxxx的属性
object value = pinfo.GetValue(obj,null); //获取xxxx属性的值
System.Reflection.PropertyInfo[] pinfos = tp.GetProperties(); //获取obj对象的所有属性
System.Reflection.MethodInfo minfo = tp.GetMethod("yyyy"); //获取指定名称为yyyy的方法
minfo.Invoke(obj, null); //调用yyyy方法,若有参数则将null换为该方法的参数
System.Reflection.MethodInfo[] minfos = tp.GetMethods(); //获取obj对象的所有方法
System.Reflection.FieldInfo finfo = tp.GetField("zzzz"); //获取obj对象的指定zzzz名称的字段
object value = finfo.GetValue(obj, null); //获取zzzz字段的值
System.Reflection.FieldInfo[] finfos = tp.GetFields(); //获取obj对象的所有字段
Assembly assembly = Assembly.GetExecutingAssembly();
// 获取程序集元数据
AssemblyCopyrightAttribute copyright = (AssemblyCopyrightAttribute)AssemblyCopyrightAttribute.GetCustomAttribute(assembly, typeof(AssemblyCopyrightAttribute));
DLLCopyright = copyright.Copyright;
AssemblyDescriptionAttribute description = (AssemblyDescriptionAttribute)AssemblyDescriptionAttribute.GetCustomAttribute(assembly, typeof(AssemblyDescriptionAttribute));
DLLDescription = description.Description;
AssemblyTitleAttribute title = (AssemblyTitleAttribute)AssemblyTitleAttribute.GetCustomAttribute(assembly, typeof(AssemblyTitleAttribute));
DLLTitle = title.Title;
AssemblyFileVersionAttribute version = (AssemblyFileVersionAttribute)AssemblyFileVersionAttribute.GetCustomAttribute(assembly, typeof(AssemblyFileVersionAttribute));
DLLVersion = version.Version;
System.Version version1 = (System.Version)System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
DLLVersionR = version1.Revision.ToString();
load dll
FileStream Fs = new FileStream(lpFileName, FileMode.Open);
fs = (Stream)Fs;
byte[] buffer = new byte[(int)fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
return buffer;
載入
MyAssembly = Assembly.Load(buffer );
實力畫 Type[] type = MyAssembly.GetTypes();
foreach (Type t in type)
{
if (t.Name == ClassName)//t.Namespace == Namespace &&
return MyInstance = Activator.CreateInstance(t);
}
===================
搞了C#
現在來學學維修筆電