C#特性替代设置方法 [英] c# property override Set method

查看:105
本文介绍了C#特性替代设置方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像下面的一类,我要重写的设定值学校,Country..etc ..属性时,有人设置一个值,我不希望改变学生类,但我需要做到这一点的基类,并把它作为一个泛型方法

I have a class like the below, I want to override the set value of "School,Country..etc.." property when some one sets a value , i don't want to change the student class but i need to do it in the base class and use it as a generic method

public class Student : BaseClass
{
       public String School { get; set; }
       public String Country{ get; set; }
}



即:
当某一个设定
Student.School =哈佛
我需要把它保存为结果
Student.School =我的哈佛自定义值;

请注意:
基本上调用OnPropertyChanged在基类,而不是主类

推荐答案

如果你想用的方面去做,然后尝试的 Postsharp

If you want to do it with aspects, then try Postsharp

这篇关于C#特性替代设置方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆