C# Class Com.Aote.ObjectTools.CustomTypeHelper

Inheritance: System.Windows.DependencyObject, ICustomTypeProvider, INotifyPropertyChanged, INotifyDataErrorInfo, IInitable
Show file Open project: DuBin1988/restv2 Class Usage Examples

Public Properties

Property Type Description
_errors string>.Dictionary

Protected Properties

Property Type Description
_customPropertyValues object>.Dictionary

Public Methods

Method Description
Add ( PropertySetter ps ) : void
AddProperty ( string name ) : void

给对象添加一条属性描述,属性类型为默认的字符串型

AddProperty ( string name, Type propertyType ) : void

给对象添加一条属性描述,属性类型为给定类型

AddProperty ( string name, Type propertyType, List attributes ) : void

给对象添加一条属性描述,属性类型为给定类型,并可以附加一个声明列表,给属性加声明。 这个方法一般不会调用。

FindResource ( string name ) : object
GetCustomType ( ) : Type

获取客户类型,如果获取时,不存在,就建立一个,这样,每个没有实体类型的对象就做到了一个对象一个类。

GetErrors ( string propertyName ) : System.Collections.IEnumerable

获取属性的错误信息列表,由于我们只保留属性的一条错误信息,在属性错误表中 获取到这个属性的一条错误信息,转换成列表,返回。

GetProperties ( ) : System.Reflection.PropertyInfo[]

获取所有属性信息,包括自定义的,也包括clr属性。

GetProperty ( string name ) : PropertyInfo

根据名称,获取一条属性信息,即可以获取自定义属性,也可以获取clr属性。

GetPropertyInfos ( ) : List
GetPropertyValue ( string propertyName ) : object
Init ( object ui ) : void
NotError ( string propertyName ) : void

当属性值经过校验,发现没有错误时,调用这个方法,通知外部某个属性没有错误了。

OnError ( string propertyName, string msg ) : void

某个属性发生了错误,在错误信息列表里进行注册

OnErrorsChanged ( string propertyName ) : void
OnInitFinished ( ) : void
OnPropertyChanged ( string info ) : void
SetCustomType ( CustomType type ) : void

设置对象类型,从CustomTypes中找到类型的对象,可以调用这个方法设置对象类型。

SetPropertyValue ( string propertyName, object value, bool isNew ) : void
SetPropertyValue ( string propertyName, object value, bool isNew, bool isDefault ) : void

设置对象的动态属性值,clr属性值的设置不在这里处理。设置动态属性值之前,首先要进行各种校验。 为了在界面上体现对象的最新属性,即使属性值校验有问题,也会将错误值设置给属性。

SetValue ( string propertyName, object value ) : void
Validate ( string propertyName, object value ) : bool

校验执行过程,先检查是否有不能为空的校验,在看数据类型是否合适,最后调用配置的校验规则进行校验。

Protected Methods

Method Description
OnDynamicPropertyChanged ( string info ) : void

Private Methods

Method Description
OnLoaded ( ) : void
ValidateValue ( object value, PropertySetter setter ) : bool

用配置的属性值校验规则校验属性值,校验规则用javascript代码书写。为了方便在xaml中书写, 用and代替&&,用or代替||,用^代替小于号,在调用javascript前注意转换。

ValidateValueType ( object value, Type type ) : bool

校验属性类型,主要调用类型本身的IsAssignableFrom方法看类型之间的兼容性。 其中,空值不用校验,空值可以赋给任何类型。

Method Details

Add() public method

public Add ( PropertySetter ps ) : void
ps PropertySetter
return void

AddProperty() public method

给对象添加一条属性描述,属性类型为默认的字符串型
public AddProperty ( string name ) : void
name string 属性名
return void

AddProperty() public method

给对象添加一条属性描述,属性类型为给定类型
public AddProperty ( string name, Type propertyType ) : void
name string 属性名
propertyType System.Type 属性类型
return void

AddProperty() public method

给对象添加一条属性描述,属性类型为给定类型,并可以附加一个声明列表,给属性加声明。 这个方法一般不会调用。
public AddProperty ( string name, Type propertyType, List attributes ) : void
name string 属性名
propertyType System.Type 属性类型
attributes List 属性的声明
return void

FindResource() public method

public FindResource ( string name ) : object
name string
return object

GetCustomType() public method

获取客户类型,如果获取时,不存在,就建立一个,这样,每个没有实体类型的对象就做到了一个对象一个类。
public GetCustomType ( ) : Type
return System.Type

GetErrors() public method

获取属性的错误信息列表,由于我们只保留属性的一条错误信息,在属性错误表中 获取到这个属性的一条错误信息,转换成列表,返回。
public GetErrors ( string propertyName ) : System.Collections.IEnumerable
propertyName string 要获取错误信息的属性名称
return System.Collections.IEnumerable

GetProperties() public method

获取所有属性信息,包括自定义的,也包括clr属性。
public GetProperties ( ) : System.Reflection.PropertyInfo[]
return System.Reflection.PropertyInfo[]

GetProperty() public method

根据名称,获取一条属性信息,即可以获取自定义属性,也可以获取clr属性。
public GetProperty ( string name ) : PropertyInfo
name string
return System.Reflection.PropertyInfo

GetPropertyInfos() public method

public GetPropertyInfos ( ) : List
return List

GetPropertyValue() public method

public GetPropertyValue ( string propertyName ) : object
propertyName string
return object

Init() public method

public Init ( object ui ) : void
ui object
return void

NotError() public method

当属性值经过校验,发现没有错误时,调用这个方法,通知外部某个属性没有错误了。
public NotError ( string propertyName ) : void
propertyName string 错误消失的属性名称
return void

OnDynamicPropertyChanged() protected method

protected OnDynamicPropertyChanged ( string info ) : void
info string
return void

OnError() public method

某个属性发生了错误,在错误信息列表里进行注册
public OnError ( string propertyName, string msg ) : void
propertyName string 属性名
msg string 错误信息
return void

OnErrorsChanged() public method

public OnErrorsChanged ( string propertyName ) : void
propertyName string
return void

OnInitFinished() public method

public OnInitFinished ( ) : void
return void

OnPropertyChanged() public method

public OnPropertyChanged ( string info ) : void
info string
return void

SetCustomType() public method

设置对象类型,从CustomTypes中找到类型的对象,可以调用这个方法设置对象类型。
public SetCustomType ( CustomType type ) : void
type CustomType
return void

SetPropertyValue() public method

public SetPropertyValue ( string propertyName, object value, bool isNew ) : void
propertyName string
value object
isNew bool
return void

SetPropertyValue() public method

设置对象的动态属性值,clr属性值的设置不在这里处理。设置动态属性值之前,首先要进行各种校验。 为了在界面上体现对象的最新属性,即使属性值校验有问题,也会将错误值设置给属性。
public SetPropertyValue ( string propertyName, object value, bool isNew, bool isDefault ) : void
propertyName string 属性名
value object 属性值
isNew bool 新建时,即使校验错误,也要给数据
isDefault bool 设置默认值时,不发生动态属性改变事件
return void

SetValue() public method

public SetValue ( string propertyName, object value ) : void
propertyName string
value object
return void

Validate() public method

校验执行过程,先检查是否有不能为空的校验,在看数据类型是否合适,最后调用配置的校验规则进行校验。
public Validate ( string propertyName, object value ) : bool
propertyName string 属性名
value object 属性值
return bool

Property Details

_customPropertyValues protected property

protected Dictionary _customPropertyValues
return object>.Dictionary

_errors public property

属性及其错误列表,key为属性名,value为属性错误信息。
public Dictionary _errors
return string>.Dictionary