c# - 是否可以在 C# 中获取属性的所有引用?
问题描述
我想编写一个脚本来显示类属性的所有引用(类似于在 Visual Studio 中按 F12)。
它应该在 powershell 中运行或作为 C# .net 控制台应用程序运行。
该脚本的主要任务是删除 DataContext 中未使用的 DataModel。
非常感谢!
解决方案
似乎您想使用反射来获取类的引用。
我在控制台应用程序中制作了一个代码示例。您可以检查它是否对您有用。
class Program
{
static void Main(string[] args)
{
Student stu = new Student();
Type type = stu.GetType();
var members = type.GetMembers().ToList();
foreach (var item in members)
{
Console.WriteLine(item);
}
}
}
public class Student
{
public string Name { get; set; }
public int Age { get; set; }
public void SayHello(string Name)
{
Console.WriteLine("Hello , I am {0}",Name);
}
public int ClassID { get; set; }
}
结果:
推荐阅读
- python - Python pip install:错误:包目录'b'不存在
- python - 我可以在 kivy 的按钮文本区域中执行简单的数学加法/减法吗?
- c# - 如何使用 C# 在下拉列表中显示 Excel 工作表名称
- c# - Gridcolumn 中的单选按钮不会触发绑定
- angular - 无法将对象添加到 Firebase
- excel-formula - 如何使用 vba 将 2 个暗色范围相乘
- javascript - 在议程日视图中添加事件
- c++ - 如果我们不在 C++ 中传递大小变量,则通过函数查找数组的大小
- php - 为什么我的方程式返回错误的响应
- swift - Flutter iOS add2pp 模型 PlatformChannel 配置