WF中DependencyObject和DependencyProperty的實現

WFDependencyObjectDependencyProperty的實現

?

DependencyPropertyRegisterRegisterAttached方法,將DependencyProperty存在IDictionary中完成注冊,確保相同nameDependencyProperty在一個ownerType類型中只能有一個。

DependencyObjectGetValueSetValue的值存在IDictionary中。并預留了GetValueOverride SetValueOverride的處理。

?

Reflector看了一下源碼,下面是源碼的片段

?

[Serializable]

public sealed class DependencyProperty : ISerializable

{

??? private static IDictionary<int, DependencyProperty> dependencyProperties;

?

?? public static DependencyProperty Register(string name, Type propertyType, Type ownerType)

??? {

??????? return ValidateAndRegister(name, propertyType, ownerType, null, null, true);

??? }

?

??? public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType)

??? {

??????? return ValidateAndRegister(name, propertyType, ownerType, null, null, false);

??? }

?

??? //RegisterRegisterAttached調用ValidateAndRegister完成注冊

??? private static DependencyProperty ValidateAndRegister(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, Type validatorType, bool isRegistered)

??? {

??????? // Check ...

??????? // ...

?

??????? DependencyProperty property = new DependencyProperty(name, propertyType, ownerType, metadata, validatorType, isRegistered);

??????? lock (((ICollection)dependencyProperties).SyncRoot)

??????? {

??????????? // 使用HashCode作為Key

??????????? if (dependencyProperties.ContainsKey(property.GetHashCode()))

??????????? {

??????????????? throw new InvalidOperationException(SR.GetString("Error_DPAlreadyExist", new object[] { name, ownerType.FullName }));

??????????? }

??????????? dependencyProperties.Add(property.GetHashCode(), property);

??????? }

??????? return property;

??? }

?

??? // HashCodenameownerTypeHashCode生產,確保相同nameownerTypeDependencyProperty只能有一個。

??? public override int GetHashCode()

??? {

??????? return (this.name.GetHashCode() ^ this.ownerType.GetHashCode());

??? }

}

?

[DesignerSerializer(typeof(DependencyObjectCodeDomSerializer), typeof(CodeDomSerializer)), DesignerSerializer(typeof(WorkflowMarkupSerializer), typeof(WorkflowMarkupSerializer))]

public abstract class DependencyObject : IComponent, IDependencyObjectAccessor, IDisposable

{

??? private IDictionary<DependencyProperty, object> dependencyPropertyValues;

?

??? public object GetValue(DependencyProperty dependencyProperty)

??? {

??????? // Check...

??????? // ...

?

??????? PropertyMetadata defaultMetadata = dependencyProperty.DefaultMetadata;

?

??????? // GetValueOverride的處理

??????? if (defaultMetadata.GetValueOverride != null)

??????? {

??????????? return defaultMetadata.GetValueOverride(this);

??????? }

??????? return this.GetValueCommon(dependencyProperty, defaultMetadata);

??? }

?

??? private object GetValueCommon(DependencyProperty dependencyProperty, PropertyMetadata metadata)

??? {

??????? object boundValue;

??????? this.dependencyPropertyValues.TryGetValue(dependencyProperty, out boundValue);

?

??????? // Others...

?

??????? return boundValue;

??? }

?

??? public void SetValue(DependencyProperty dependencyProperty, object value)

??? {

??????? // Check...

??????? // ...

?

??????? PropertyMetadata defaultMetadata = dependencyProperty.DefaultMetadata;

??????? this.SetValueCommon(dependencyProperty, value, defaultMetadata, true);

??? }

?

??? internal void SetValueCommon(DependencyProperty dependencyProperty, object value, PropertyMetadata metadata, bool shouldCallSetValueOverrideIfExists)

??? {

??????? // Check...

??????? // ...

?

??????? // SetValueOverride的處理

??????? if (shouldCallSetValueOverrideIfExists && (metadata.SetValueOverride != null))

??????? {

??????????? metadata.SetValueOverride(this, value);

??????? }

??????? else

??????? {

??????????? // Others...

??????????? if (dependencyPropertyValues.ContainsKey(dependencyProperty))

??????????? {

??????????????? dependencyPropertyValues[dependencyProperty] = value;

??????????? }

??????????? else

??????????? {

??????????????? dependencyPropertyValues.Add(dependencyProperty, value);

??????????? }

??????? }

??? }

}

轉載于:https://www.cnblogs.com/xujiaoxiang/archive/2009/12/04/1616896.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379467.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379467.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379467.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

hdu2115: I Love This Game

hdu2115: http://acm.hdu.edu.cn/showproblem.php?pid2115題意&#xff1a;輸入n組名字和對應的時間&#xff08;分&#xff1a;秒&#xff09;&#xff0c;要求按時間長度由短到長排序&#xff0c;并輸出對應排名&#xff0c;若時間一樣&#xff0c;則按名字字典序排序&#…

打開eclipse出現Failed to load the JNI shared library “D:\java\jdk\bin\...\jre\bin\server\jvm.dll”如何解決?

eclipse打開的時候出現Failed to load the JNI shared library “D:\java\jdk\bin…\jre\bin\server\jvm.dll”如何解決&#xff1f;&#xff1f; 如圖所示&#xff1a; 即代表你的jdk與eclipse的位數不一樣&#xff01;&#xff01;&#xff01; 你可以查看一下eclipse和jd…

Java DataOutputStream writeUTF()方法及示例

DataOutputStream類的writeUTF()方法 (DataOutputStream Class writeUTF() method) writeUTF() method is available in java.io package. writeUTF()方法在java.io包中可用。 writeUTF() method is used to write the given string value to the basic data output stream wit…

2010年世界杯分組

A 南非 墨西哥 烏拉圭 法國 B 阿根廷 南非 韓國 希臘 C 英格蘭 美國 阿爾及利亞 斯洛文尼亞 D 德國 澳大利亞 塞爾維亞 加納 E 荷蘭 丹麥 日本 喀麥隆 F 意大利 巴拉圭 新西蘭 斯洛伐克 G 巴西 朝鮮 科特迪瓦 葡萄牙 H 西班牙 瑞士 洪都拉斯 智利 轉載于:https://www.cnblogs.c…

圓形墜落模擬算法設計

目標&#xff1a;實現一個算法&#xff0c;模擬在一個封閉二維區域&#xff0c;圓形小球朝給定方向墜落的過程&#xff0c;實現二維區域的緊密填充。 像下面這樣&#xff1a; 難點&#xff0c;及其簡單解決&#xff1a; 1.如何把粒子移動盡可能遠&#xff1f; 圖中的粒子i&…

Maven詳細教學

一、Maven簡介 maven&#xff1a;是apache下的一個開源項目&#xff0c;是純java開發&#xff0c;并且只是用來管理java項目的 依賴管理&#xff1a;就是對jar包的統一管理 可以節省空間 項目一鍵構建&#xff1a;mvn tomcat:run該代碼可以將一個完整的項目運行起來&#xff0…

Java Character.UnicodeBlock of()方法與示例

Character.UnicodeBlock類的()方法 (Character.UnicodeBlock Class of() method) of() method is available in java.lang package. of()方法在java.lang包中可用。 of() method is used to return the Unicode block containing the given parameter value or it returns null…

simpleDBM的B-link樹實現

參考的是VLDB2005的這篇論文&#xff0c;做個標記把。/Files/YFYkuner/Concurrency_control_and_recovery_for_balanced_B-link_trees.pdf 轉載于:https://www.cnblogs.com/YFYkuner/archive/2009/12/21/1629268.html

網站后臺中對html標簽的處理

最近做一個CMS&#xff0c;后臺中需要使用在線編輯器對新聞進行編輯&#xff0c;然后發表。我用的在線編輯器是CKEditorCKFinder。也許是我為了讓CKEditor更本地化吧&#xff0c;改了很多。后來發現在CKEditor中對文字設置字體、顏色、字號大小時文字的<span>標簽會出現N…

Java Calendar getActualMaximum()方法與示例

日歷類的getActualMaximum()方法 (Calendar Class getActualMaximum() method) getActualMaximum() method is available in java.util package. getActualMaximum()方法在java.util包中可用。 getActualMaximum() method is used to return the maximum value that the given …

軟件研發人員考核的十項基本原則(轉)

軟件研發人員考核的十項基本原則 作者: 任甲林 來源: 萬方數據 軟件研發人員的考核一直是軟件企業管理的難點筆者在長期的研發管理實踐與咨詢實踐中總結了進行軟件研發人員考核的一些基本原則。(1) 要體現公司的價值觀公司的價值觀體現了公司認可什么類型的人員&#xff1f;…

2012.7.24---C#(2)

學習過了C#的基本屬性函數后&#xff0c;接下來的學習我覺得比較重要。C#是一種面向對象的語言&#xff0c;下面復習一下面向對象中的一些名詞。 類&#xff1a;把一些系列東西&#xff0c;把他們的共同的屬性和方法抽象出來&#xff0c;給他起一個名字就是XXX類。類中定義…

匯編語言-001(BYTE、DUP、WORD 、DWORD 、QWORD 、TBYTE 、REAL )

1 : 基礎匯編語言展示 .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dwExitCode:DWORD.code main PROCmov eax,5add eax,6INVOKE ExitProcess,0 main ENDP END main2:基礎匯編語言展示增加變量的訪問 .386 .model flat,stdcall .stack 4096 ExitProcess PROTO,dw…

<各國地圖輪廓app>技術支持

如在app使用過程中遇到任何問題&#xff0c;請與開發者聯系caohechunhotmail.com

Java BigDecimal longValueExact()方法與示例

BigDecimal類longValueExact()方法 (BigDecimal Class longValueExact() method) longValueExact() method is available in java.math package. longValueExact()方法在java.math包中可用。 longValueExact() method is used to convert this BigDecimal to an exact long val…

c#中的多線程同步

在處理多線程同步問題的時候&#xff0c;我們一般有臨界區&#xff0c;互斥量&#xff0c;信號量和消息機制等幾種解決方案&#xff0c;在c#中可以非常方便的使用它們來實現進程的同步。下面我就常用的lock,Monitor和Mutex幾種來說明如何實現進程的同步。 lock和Monitor依靠一種…

ffplay SDL_OpenAudio (2 channels, 44100 Hz): WASAPI can‘t initialize audio client“

windows下&#xff1a; ffplay 提示"SDL_OpenAudio (2 channels, 44100 Hz): WASAPI can’t initialize audio client" 添加環境變量&#xff1a;SDL_AUDIODRIVERdirectsound

js 正則表達式,正整數

var ss "3.333";var type /^[0-9]*[1-9][0-9]*$/;var re new RegExp(type);alert(ss.match(re));if (ss.match(re) null) {alert("請輸入大于零的整數!");return;} 轉載于:https://www.cnblogs.com/lingxzg/archive/2012/08/02/2620543.html

java 根據類名示例化類_Java即時類| EpochSecond()方法的示例

java 根據類名示例化類EpochSecond()方法的即時類 (Instant Class ofEpochSecond() method) Syntax: 句法&#xff1a; public static Instant ofEpochSecond(long sec_val);public static Instant ofEpochSecond(long sec_val, long nanos_adjust);ofEpochSecond() method is…

java中Date()類型輸入數據的處理

對于Date類型的數據&#xff0c;需要輸入生日存入相應數據庫中 private Date birthday;// 生日package com.pdsu.mybatis.pojo;import java.io.Serializable; import java.util.Date;public class User implements Serializable {/*** */private static final long serialVers…