惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Last Watchdog
The Last Watchdog
博客园 - 司徒正美
L
LangChain Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
Microsoft Security Blog
Microsoft Security Blog
Cyberwarzone
Cyberwarzone
Project Zero
Project Zero
M
MIT News - Artificial intelligence
NISL@THU
NISL@THU
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
T
Tenable Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Troy Hunt's Blog
月光博客
月光博客
大猫的无限游戏
大猫的无限游戏
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Scott Helme
Scott Helme
Recent Announcements
Recent Announcements
S
Secure Thoughts
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
aimingoo的专栏
aimingoo的专栏
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
Hacker News - Newest:
Hacker News - Newest: "LLM"
雷峰网
雷峰网
Attack and Defense Labs
Attack and Defense Labs
A
About on SuperTechFans
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
Martin Fowler
Martin Fowler
V2EX - 技术
V2EX - 技术
S
Securelist
Microsoft Azure Blog
Microsoft Azure Blog
N
Netflix TechBlog - Medium
B
Blog RSS Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
PCI Perspectives
PCI Perspectives
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hacker News: Front Page

博客园 - 油纸伞

假如m是奇数,且m>=3,证明m(m² -1)能被8整除 SharpSvn操作 -- 获取Commit节点列表 GetRelativePath获取相对路径 Dictionary(支持 XML 序列化),注意C#中原生的Dictionary类是无法进行Xml序列化的 Winform中Checkbox与其他集合列表类型之间进行关联 Image(支持 XML 序列化),注意C#中原生的Image类是无法进行Xml序列化的 修复使用<code>XmlDocument</code>加载含有DOCTYPE的Xml时,加载后增加“[]”字符的错误 使用序列化来Clone对象 [转]PowerDesigner15生成Hibernate 用户自定义类型的隐式转换 知识加油站 知识加油站 Top K算法详细解析 C#值类型和引用类型 Oracle分区技术 对Oracle表分区的一点认识 oracle创建分区表 数据库大表的优化:采用蔟表(clustered tables)及蔟索引(Clustered Index) 2008年.Net编程人员工具参照
Net3.5及以上版本INotifyPropertyChanged接口的友好用法
油纸伞 · 2012-03-26 · via 博客园 - 油纸伞

1、核心类BaseNotifyPropertyChanged ,主要用来封装NotifyProperty的执行方法

View Code

 1     public abstract class BaseNotifyPropertyChanged : INotifyPropertyChanged
 2     {
 3         public event PropertyChangedEventHandler PropertyChanged;
 4 
 5         protected void RaisePropertyChanged<T>(
 6             Expression<Func<T>> propertyExpresssion)
 7         {
 8             if (propertyExpresssion == null)
 9             {
10                 throw new ArgumentNullException("propertyExpression");
11             }
12 
13             var memberExpression = propertyExpresssion.Body as MemberExpression;
14             if (memberExpression == null)
15             {
16                 throw new ArgumentException("PropertySupport_NotMemberAccessExpression_Exception""propertyExpression");
17             }
18 
19             var property = memberExpression.Member as PropertyInfo;
20             if (property == null)
21             {
22                 throw new ArgumentException("PropertySupport_ExpressionNotProperty_Exception""propertyExpression");
23             }
24 
25             string propertyName = property.Name;
26             object propertyValue = property.GetValue(thisnull);
27 
28             var getMethod = property.GetGetMethod(true);
29             if (getMethod.IsStatic)
30             {
31                 throw new ArgumentException("PropertySupport_StaticExpression_Exception""propertyExpression");
32             }
33             this.RaisePropertyChanged(propertyName);
34         }
35 
36         private void RaisePropertyChanged(string propertyName)
37         {
38             if (PropertyChanged != null)
39                 PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));
40         }
41     }

     说明:abstract 是为了其他人不能直接初始化该类。

2、Example

View Code

 1     public class User : BaseNotifyPropertyChanged
 2     {
 3         private string name;
 4         public string Name
 5         {
 6             get { return name; }
 7             set
 8             {
 9                 name = value;
10                 RaisePropertyChanged(() => this.Name);
11             }
12         }
13     }

 So is easy