最近想做一个插件式的软件给公司的监控用,初步的想法是使用C#去反射Dll,Invoke其中的方法。此文仅供开发参考,不涉及原理,98%的代码以及2%的废话。

测试Solution是这么建的(.NET FRAMEWORK 4.5.1):

C#中反射的使用(How to use reflect in CSharp)(1)

Person类代码:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 
 5 namespace PersonMoudle
 6 {
 7     public class Person
 8     {
 9         public Person()
10         {
11             Name = "Sirius";
12             Age = 25;
13             Height = 172;
14             Sex = "Middle";
15         }
16         public Person(string name, int age, float height, string sex)
17         {
18             Name = name;
19             Age = age;
20             Height = height;
21             Sex = sex;
22         }
23 
24         public string Name { get; set; }
25         public int Age { get; set; }
26         public float Height { get; set; }
27         public string Sex { get; set; }
28 
29         public void Speak(string words)
30         {
31             Console.WriteLine(words);
32         }
33         private string GetMyName()
34         {
35             return Name.Trim();
36         }
37 
38         public string GetMySex()
39         {
40             return Sex;
41         }
42 
43         public List<string> BeenCity()
44         {
45             return new List<string>
46             {
47                 "Beijing",
48                 "Jinan",
49                 "NewYork"
50             };
51         }
52 
53         public List<string> BennCity(int count)
54         {
55             return new List<string>
56             {
57                 "Beijing",
58                 "Jinan",
59                 "NewYork"
60             }.Take(count).ToList();
61         }
62     }
63 }
View Code

相关文章:

  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2021-11-11
  • 2021-07-02
  • 2021-09-29
  • 2021-04-21
  • 2021-11-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2022-12-23
  • 2021-05-31
  • 2022-03-02
相关资源
相似解决方案