public static void Main() {
User user = new User();
Type a = typeof(User);
Type usertype = Type.GetType("com.atguigu.fate.lin.User");
Type t1 = user.GetType();
PropertyInfo[] properties = t1.GetProperties();
foreach (PropertyInfo item in properties) {
Console.WriteLine(item.Name);
}
Console.WriteLine("-----------------------------");
FieldInfo[] fields = t1.GetFields();
foreach (FieldInfo item in fields) {
Console.WriteLine(item.Name);
}
Console.WriteLine("-----------------------------");
MethodInfo[] methods = t1.GetMethods();
foreach (MethodInfo item in methods) {
Console.WriteLine(item.Name);
}
Console.WriteLine("-----------------------------");
ConstructorInfo[] constructors = t1.GetConstructors();
foreach (ConstructorInfo item in constructors) {
Console.WriteLine(item.Name);
}
Console.WriteLine("-----------------------------");
User user1 = (User)Activator.CreateInstance(t1);
User user2 = Activator.CreateInstance<User>();
PropertyInfo idproperty=t1.GetProperty("Id");
idproperty.SetValue(user2, 1);
FieldInfo[] fields1 = t1.GetFields(BindingFlags.Instance|BindingFlags.NonPublic);
PropertyInfo nameproperty = t1.GetProperty("Name");
nameproperty.SetValue(user1,"--");
object name = nameproperty.GetValue(user2);
Assembly util = Assembly.LoadFile(@"D:\BaiduNetdiskDownload\2020-11-20\WinReflectionAndDelegate\DbUtility\bin\Debug\DbUtility.dll");
Assembly util = Assembly.Load("DbUtility");
Assembly util = Assembly.LoadFrom("DbUtility.dll");
Type help = util.GetType("DbUtility.SqlHelper");
object x1 = util.CreateInstance("DbUtility.SqlHelper");
MethodInfo method = help.GetMethod("ExecuteNonQuery",new Type[]{typeof(string),typeof(int),typeof(SqlParameter[]) });
method.Invoke(null,new object[]{ "INSERT INTO UserX VALUES (3,'liusu2');" ,1,null});
ConstructorInfo constructor = t1.GetConstructor(new Type[]{typeof(int)});
object x2 = constructor.Invoke(new object[]{233});
Console.WriteLine(x2);
}
delegate int Add(int n1,int n2);
delegate void Show(string msg);
public class Program {
private void ShowMsg(string msg){
Console.WriteLine(msg);
}
private void ShowInfo(string msg) {
Console.WriteLine(msg);
}
private void ShowMsgNew(string msg) {
Console.WriteLine(msg);
}
private void ShowMsgNew2(string msg) {
Console.WriteLine(msg);
}
private int AddNums(int n1, int n2){
return n1 + n2;
}
private int Add(int n1, int n2) {
return n1 + n2;
}
public static void Main() {
Program p = new Program();
p.Test();
}
public void Test(){
Add add = new Add(AddNums);
int x1 = add.Invoke(1,1);
int x2 = add(1, 1);
Add add1 = AddNums;
int x4 =add1(5, 7);
int x3 = Add(4, 6);
Show show = ShowMsg;
show += ShowInfo;
show += ShowMsgNew;
show += ShowMsgNew2;
show -= ShowMsgNew2;
show("唯我超电磁炮永世长存!");
Action a1 = () => {
Console.WriteLine("----");
};
Action<int> a3 = a => {
int x = a;
int y = a + x + 12;
Console.WriteLine("----");
};
Action<int,string,decimal> a2 = (a,b,c) => {
};
Func<int> x5 = () => {
return 0;
};
Add x6 = delegate (int x, int y) {
return x + y;
};
Func<string,int> x7 = (x) => {
return 'x';
};
}
public event Action AddHandler;
}