当前位置: 首页 > news >正文

自己有网站 做app凡科建站代理

自己有网站 做app,凡科建站代理,做电子书网站,武汉手机网站建设公司最近又要找工作,很多东西要复习。打算写下面试时的复习的东西做成一个系列,先从WPF开始 DependencyProperty 1. The diffirenc between DependencyProperty and CLR Property The CLR property is just a wrapper around private variables. The idea of…

最近又要找工作,很多东西要复习。打算写下面试时的复习的东西做成一个系列,先从WPF开始

DependencyProperty

1. The diffirenc between DependencyProperty and CLR Property

 The CLR property is just a wrapper around private variables.

 The idea of DependencyProperty is to compute the value of property based on external inputs.

 

 Here is a simple prototype of DependyProperty

Public class DependencyProperty

{

    Internal static Dictionary<object, DependencyProperty> RegisteredDps=new Dictionary<object,DependencyProperty>();

    Internal string Name;

    Internal object Value;

    Internal object HashCode;

    Private DependencyProperty(string name,Type propertyType, Type ownerType, object defaultValue)

     {

          This.Name=name;

          This.Value=defaultValue;

          This.HashCode=name.GetHashCode^ownerType.GetHashCode;

    }

    Public static DependencyProperty Register(string name,Type propertyType, Type ownerType,object defaultValue)

    {

         DependencyProperty dp=new DependencyProperty(name,propertyType,ownerType,defaultValue);

         RegisterdDps.Add(dp.HashCode,dp);

        Return dp;

    }

}

 

Public class DependencyObject

{

     Public static readonly DependencyProperty NameProperty=DependencyProperty.Register(“name”,typeof(string),typeof(DependencyObject),string.empty);

 

     Public object GetValue(DependencyProperty dp)

     {

          Return DependencyProperty.RegistedDps[dp.HashCode].Value;

}

Public object SetValue(DependencyProperty dp,object value)

{

      DependencyProperty.RegistedDps[dp.HashCode].Value=value;

}

 

Public string Name

{

       get{return GetValue(NameProperty).ToString()}

      set{SetValue(NameProperty,value);}

}

}

All DependencyObjects share one DependencyProperty, if one object changed dp value, all the others will change.

So the DependencyObject Add effective conception

Improved DependencyObject with _effectiveValue

 

Public class DependencyProperty

{

     Internal static Dictionary<object, DependencyProperty> RegisteredDps=new Dictionary<object,DependencyProperty>();

   Internal string Name;

     Internal int Index;

   Internal object Value;

     Internal object HashCode;

   Private static int globalIndex=0;

  Private DependencyProperty(string name,Type propertyType, Type ownerType, object defaultValue)

     {

          This.Name=name;

          This.Value=defaultValue;

          This.HashCode=name.GetHashCode^ownerType.GetHashCode;

}

Public static DependencyProperty Register(string name,Type propertyType, Type ownerType,object defaultValue)

{

      DependencyProperty dp=new DependencyProperty(name,propertyType,ownerType,defaultValue);

    globalIndex++;

    dp.Index=globalIndex;

      RegisterdDps.Add(dp.HashCode,dp);

    Return dp;

}

}

 

 

Internal struct EffectiveValueEntry

{

       Internal int PropertyIndex{get;set;}

       Internal object Value{get;set;}

}

Public class DependencyObject

{

Private List<EffectiveValueEntry> effectiveValues=new List<EffectiveValueEntry>();

     Public static readonly DependencyProperty NameProperty=DependencyProperty.Register(“name”,typeof(string),typeof(DependencyObject),string.empty);

 

     Public object GetValue(DependencyProperty dp)

     {

          EffectiveValueEntry effectiveValue=effectiveValues.FirstOrDefault((i)=>i.PropertyIndex=dp.Index);

          If(effectiveValue.PropertyIndex!=0)

          {

                Return effectiveValue.Value;

}

Else

{

          Return DependencyProperty.RegistedDps[dp.HashCode].Value;

}

}

Public object SetValue(DependencyProperty dp,object value)

{

EffectiveValueEntry effectiveValue=effectiveValues.FirstOrDefault((i)=>i.PropertyIndex=dp.Index);

          If(effectiveValue.PropertyIndex!=0)

          {

                effectiveValue.Value=value;

}

      Else

      {

EffectiveValueEntry effectiveValue=new EffectiveValueEntry(){PropertyIndex=dp.Index; Value=value;}

}

      }

 

Public string Name

{

       get{return GetValue(NameProperty).ToString()}

      set{SetValue(NameProperty,value);}

}

}

Problem: Derived class can override field in parent class

Improved

Public class PropertyMetaData

{

         Public Type Type{get;set;};

         Public object Value{get;set;}

         Public PropertyMetaData(object defaultValue)

         {

                   This.Value=defaultValue;

}

}

 

Public class DependencyProperty

{

     Internal static Dictionary<object, DependencyProperty> RegisteredDps=new Dictionary<object,DependencyProperty>();

   Internal string Name;

     Internal int Index;

   Internal object Value;

     Internal object HashCode;

   Private static int globalIndex=0;

     Private List<PropertyMetaData> metaDataMap=new List<PropertyMetaData>();

Private PropertyMetaData defaultMetaData;

  Private DependencyProperty(string name,Type propertyType, Type ownerType, object defaultValue)

     {

          This.Name=name;

          This.Value=defaultValue;

          This.HashCode=name.GetHashCode^ownerType.GetHashCode;

          PropertyMetaData metadata=new PropertyMetaData(defaultValue){Type=ownerType};

          metaDataMap.Add(metaData);

          defaultMetaData=metadata;

}

Public static DependencyProperty Register(string name,Type propertyType, Type ownerType,object defaultValue)

{

      DependencyProperty dp=new DependencyProperty(name,propertyType,ownerType,defaultValue);

    globalIndex++;

    dp.Index=globalIndex;

      RegisterdDps.Add(dp.HashCode,dp);

    Return dp;

}

 

Public void OverrideMetaData(Type forType,PropertyMetaData metaData)

{

      metadata.Type=forType;

      metaDataMap.Add(metaData);

}

 

Public PropertyMetaData GetMetaData(Type type)

{

      PropertyMetaData metadata=metaDataMap.FirstOrDefault((i)=>type.isSubClassOf(i.Type));

      If(metadata==null)

           Return defaultMetaData;

      Else

           Return metadata;

}

}

 

 

Public class DependencyObject

{

Private List<EffectiveValueEntry> effectiveValues=new List<EffectiveValueEntry>();

     Public static readonly DependencyProperty NameProperty=DependencyProperty.Register(“name”,typeof(string),typeof(DependencyObject),string.empty);

 

     Public object GetValue(DependencyProperty dp)

     {

          EffectiveValueEntry effectiveValue=effectiveValues.FirstOrDefault((i)=>i.PropertyIndex=dp.Index);

          If(effectiveValue.PropertyIndex!=0)

          {

                Return effectiveValue.Value;

}

Else

{

          Return DependencyProperty.RegistedDps[dp.HashCode].GetMetaData(this.getType()).Value;

}

}

Public object SetValue(DependencyProperty dp,object value)

{

EffectiveValueEntry effectiveValue=effectiveValues.FirstOrDefault((i)=>i.PropertyIndex=dp.Index);

          If(effectiveValue.PropertyIndex!=0)

          {

                effectiveValue.Value=value;

}

      Else

      {

EffectiveValueEntry effectiveValue=new EffectiveValueEntry(){PropertyIndex=dp.Index; Value=value;}

}

      }

 

Public string Name

{

       get{return GetValue(NameProperty).ToString()}

      set{SetValue(NameProperty,value);}

}

}

Then we can define a new DependencyObject instance

Public class SubDenpendencyObject:DependencyObject

{

         Static SubDependencyObject()

         {

                   NameProperty.OverrideMetaData(typeof(SubDependencyProperty),new PropertyMetaData(“SubName”));

}

}

http://www.cnblogs.com/Zhouyongh/archive/2009/09/10/1564099.html

转载于:https://www.cnblogs.com/sift/p/3566324.html

http://www.lbrq.cn/news/2598625.html

相关文章:

  • 搭建网站 阿里云网站建设优化的技巧
  • 鞍山网站建设鞍山百度推广代理怎么加盟
  • dreamweaver安装包株洲seo快速排名
  • 网站建设公司机构爱站网长尾关键词搜索
  • 网站建设题目以及答案营销方式方案案例
  • 网站开发及企业推广51趣优化网络seo工程师教程
  • 西宁企业网站营销推广软文营销文章
  • 中国能建平台淘宝seo排名优化的方法
  • 网站开发工程师简历百度竞价推广方案范文
  • 如何外贸seo网站建设电商网站设计
  • 惠州建设局官方网站淘宝标题优化网站
  • web网站开发流程全国各大新闻网站投稿
  • 个人备案网站能做商城吗整合营销方案怎么写
  • asp网站伪静态教程上海推广seo
  • 启迪网站建设重庆seo教程搜索引擎优化
  • 站群网站内容恢复正常百度
  • 本地唐山网站建设windows优化大师要会员
  • 网站代百度指数平台
  • 嘉定区做网站网店培训
  • c 博客网站开发教程宁波网站推广网站优化
  • 程序员做项目的网站网络seo啥意思
  • 武汉网站服务站长工具平台
  • 学校网站模板html线上营销手段有哪些
  • 建筑网站do网站页面设计模板
  • 网站建设第三方平台网络推广有效果吗
  • 做网站在手机显示怎么很乱国外媒体报道
  • 上海新媒体运营公司排名厦门seo总部电话
  • 镇江做网站哪家公司好网络营销做得比较好的企业
  • 红河企业网络推广外包手机优化助手
  • 网站几几年做的怎么查百度竞价开户3000
  • Python包安全工程实践:构建安全可靠的Python生态系统
  • 字符串匹配--KMP算法
  • 数据结构(三)双向链表
  • 14.Home-新鲜好物和人气推荐实现
  • 【学习笔记】Manipulate-Anything(基于视觉-语言模型的机器人自动化操控系统)
  • 基于SpringBoot的OA办公系统的设计与实现