ImageVerifierCode 换一换
格式:DOCX , 页数:50 ,大小:340.65KB ,
资源ID:10580225      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10580225.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Caliburn笔记.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Caliburn笔记.docx

1、Caliburn笔记Caliburn笔记 此框架地址如下.先来学习一下其中的一些概念.一.启动时加载服务一切还是从容器开始,Caliburn提供了一个默认的Ioc容器,当然也可以用第三方的,如下我们学习的目标则是了解Caliburn为我们提供了多少的功能服务,这些就是我们所需要了解的二.Microsoft.Practices.ServiceLocation单例模式在此框架中得到重用,使得到处可以使用依赖注入的功能三.基本容器服务层以上是基本已注册的服务1. IServiceLocator 用于获取全局Service2. SimpleContainer 一个实现IContainer接口的容器3.

2、 IContainer 一个空容器,其继承了IConfigurator4. IConfigurator ConfigureWith方法为第三方Ioc容器提供注册扩展CaliburnFramework .ConfigureCore() .WithPresentationFramework() .Start();以上ConfigureCore则完成了上面的部分的主要配置四.基本核心服务当容器创建完成后,就好开始添加核心服务了ConfigureCore方法会返回一个CoreConfiguration类,CoreConfiguration负责注册核心服务以上是系统核心服务,基本还是看不到wpf的影子,

3、属于基层1. DefaultThreadPool=IThreadPool 提供一个多线程操作的线程池方法管理2. MethodFactory=IMethodFactory 顾名思义,用于创建IMethod的工厂3. EventHandlerFactory 用于创建事件4. Execute.SimpleDispatcher=IDispatcher 用于执行UI线程操作的服务5. DefaultAssemblySource=IAssemblySource 集合操作对Assembly进行一个检查到此为止ConfigureCore方法真正完成五.UI服务层接下来才是重头戏,一下分篇幅讲Caliburn

4、笔记-元数据(Metadata)管理(wpf框架) 在.net中允许我们使用元数据(即Attribute),在使用Action时,结合元数据可以为框架功能提供一些便利.caliburn提供了很多的元数据,其皆继承自IMetadata接口,该接口即一个空元数据标记接口而已,继承此接口的元数据则表明为属于caliburn功能范围内的元数据,方便管理.IMetadataContainer接口提供了对IMetadata的管理MetadataContainer为IMetadataContainer默认实现,继承MetadataContainer的类则均具有管理元数据的功能/ / An implement

5、ation of ./ public class MetadataContainer : PropertyChangedBase, IMetadataContainer private List _metadata; / / Adds the metadata from the provided member to the collection. / / The member. protected virtual void AddMetadataFrom(MemberInfo member) member.GetCustomAttributes(true) .OfType() .Apply(A

6、ddMetadata); / / Adds metadata to the store. / / The metadata. public virtual void AddMetadata(IMetadata metadata) if(_metadata = null) _metadata = new List(); _metadata.Add(metadata); / / Retrieves metadata from the store. / / / public virtual T GetMetadata() where T : IMetadata return _metadata =

7、null ? default(T) : _metadata.OfType().FirstOrDefault(); / / Gets the matching metadata. / / The type to match. / The matches public virtual IEnumerable GetMatchingMetadata() where T : IMetadata return _metadata = null ? new List() : _metadata.OfType(); Caliburn笔记-Action的创建(wpf框架) 若一个对象被设置成为DataCont

8、ext,该对象的方法称之为Action,caliburn通过附加属性来绑定这些Action,首先则需要获取绑定对象的方法.如下示例对象,则有4个方法.Rescue(GeneralRescue)public class Calculator /Note: This rescue catches exceptions thrown by this method. /Rescue(ActionSpecificRescue) /Note: Preview indicates something that will happen before execution of the action. /Note

9、: If AffectsTriggers = false, then this filter will not effect the state of the UI in real time. / Preview(CanDivide) /Note: The return value is bound to the UI if present. public int Divide(int left, int right) return left / right; /Note: See Preview filter. public bool CanDivide(int left, int righ

10、t) return right != 0; /Note: See class level rescue filter. public void GeneralRescue(Exception ex) MessageBox.Show(ex.Message); /Note: See rescue filter on Divide method. public void ActionSpecificRescue(Exception ex) MessageBox.Show(Divide Action: + ex.Message); Action只包含公开方法,并不包含属性与事件等,所以需要对象成员进行

11、过滤.如下逻辑protected virtual IEnumerableIGrouping SelectMethods(Type targetType) return from method in targetType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) where method.DeclaringType != typeof(object) & !method.ContainsGenericParameters & !method.Name.StartsWith(get_)

12、 & !method.Name.StartsWith(set_) & !method.Name.StartsWith(remove_) & !method.Name.StartsWith(add_) & method.GetParameters().All(x = !x.IsOut) group method by method.Name into groups select groups;方法与Action的转换完成方法过滤后,为了添加功能,还要对方法进行转换.首先根据方法,创建一个IMethod.然后创建Action.当然Action还有其他功能,这里分为同步与异步.protected v

13、irtual IAction CreateAction(IActionHost host, MethodInfo methodInfo) var method = _methodFactory.CreateFrom(methodInfo); var asyncAtt = method.GetMetadata(); var filters = host.GetFilterManager(method); TryAddCanExecute(filters, method); if(asyncAtt = null) return new SynchronousAction(method, _mess

14、ageBinder, filters); return new AsynchronousAction(method, _messageBinder, filters, asyncAtt.BlockInteraction);创建好以后再将其保存,创建过程由实现IActionFactory接口的ActionFactory完成.public IEnumerable CreateFor(IActionHost host) var actions = new List(); var methodGroups = SelectMethods(host.TargetType); foreach(var me

15、thodGroup in methodGroups) var methodList = methodGroup.ToList(); if(methodList.Count = 1) actions.Add(CreateAction(host, methodList0); else var overloadedAction = new OverloadedAction(methodGroup.Key); foreach(var methodInfo in methodList) overloadedAction.AddOverload(CreateAction(host, methodInfo)

16、; actions.Add(overloadedAction); return actions;Caliburn笔记-方法(IMethod)的创建(wpf框架)为了适应框架的需要,对原生的MethodInfo进行了改造,如下图我们可以看到,主要的功能点是允许方法可以进行异步操作.其次IMethod也继承了IMetadataContainer接口,在方法上使用元数据也非常普遍.如下为默认实现的抽象类/ / A base class for implementations./ private abstract class MethodProxyBase : MetadataContainer, I

17、Method private readonly MethodInfo _info; protected readonly IThreadPool _threadPool; / / Initializes a new instance of the class. / / The info. / The thread pool. protected MethodProxyBase(MethodInfo info, IThreadPool threadPool) _info = info; _threadPool = threadPool; AddMetadataFrom(_info); / / G

18、ets the to which this instance applies. / / The info. public MethodInfo Info get return _info; / / Invokes the specified method on the provided instance with the given parameters. / / The instance. / The parameters. / / The result of the function or null if it is a procedure. / public abstract objec

19、t Invoke(object instance, params object parameters); / / Creates a background task for executing this method asynchronously. / / The instance. / The parameters. / / An instance of . / public abstract IBackgroundTask CreateBackgroundTask(object instance, params object parameters);继承此类的分为有返回值与无返回值的方法关

20、键点:1. 对方法进行了委托转换2. 方法执行安全操作,可进行抛错3. 可以进行异步private class Function : MethodProxyBase private readonly LateBoundFunc _theDelegate; / / Initializes a new instance of the class. / / The info. / The thread pool. public Function(MethodInfo info, IThreadPool threadPool) : base(info, threadPool) _theDelegate

21、 = DelegateFactory.Create(info); / / Invokes the specified method on the provided instance with the given parameters. / / The instance. / The parameters. / / The result of the function or null if it is a procedure. / public override object Invoke(object instance, params object parameters) return Saf

22、eInvoke(instance, parameters); / / Creates a background task for executing this method asynchronously. / / The instance. / The parameters. / / An instance of . / public override IBackgroundTask CreateBackgroundTask(object instance, params object parameters) return new BackgroundTask(_threadPool, ()

23、= SafeInvoke(instance, parameters); private object SafeInvoke(object instance, object parameters) try return _theDelegate(instance, parameters); catch(Exception) var requirements = Info.GetParameters(); if (requirements.Length != parameters.Length) throw new CaliburnException( string.Format( The method 0 expected 1 parameters but was provided 2., Info.Name, requirements.Length, parameters.Length) ); throw; DelegateFactory用于动态转换委托,其使用了表达式树(Expression)动态进行编译.Caliburn笔记-消息触发器(wpf框架)收藏参考此先看下面一段xaml /cal:RoutedMessageTrigge

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1