using System;
using System.Reflection;
namespace attributeTest
{
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct)]
public class AuthorAttribute : System.Attribute
{
public string name { get; set; }
public double verson { get; set; }
public AuthorAttribute(string nm, double vr)
{
this.name = nm;
this.verson = vr;
}
}
[Author("xiaozhang", 2.0)]
public class A
{
private double a;
public B b { get; set; }
public double getdoubleina()
{
return a;
}
public A(double a) { this.a = a; b = new B("xiaozhang"); }
}
publi
C# 反射获得字段 和 修改字段的方法
最新推荐文章于 2024-05-22 14:35:18 发布
本文演示了如何使用C#的反射来获取和修改类的字段及属性值。通过`GetProperties()`获取属性,使用`GetValue()`和`SetValue()`方法读写属性值。同时展示了获取和修改私有字段值的示例,以及如何利用`GetCustomAttributes()`获取类上的自定义特性。

最低0.47元/天 解锁文章
1267

被折叠的 条评论
为什么被折叠?



