zoukankan      html  css  js  c++  java
  • 用xpo实现dc技术的关键点-XPO是如何处理接口类型与真实类型的对应关系的

    https://www.devexpress.com/Support/Center/Question/Details/Q487000/xpodatamodel-and-model-interfaces

    代码来自于上面的网址,这个代码功能是xpo解析类型信息时,可以有个中转.

    这也成了xaf中dc机制的一个关键点,即,接口信息需要有一个真实的对应类型信息才行.

    也说是说,接口类型只是一个公开给程序员的信息,ta必须对应一个真实的classinfo,这个classinfo用于xpo解析真实的表字段表达式等其他元数据时使用.

     public class InterfaceAsForcedAliasHelper {
                public InterfaceAsForcedAliasHelper() { }
                public InterfaceAsForcedAliasHelper(ReflectionDictionary dictionary)
                    : this() {
                    Help(dictionary);
                }
                public void Help(ReflectionDictionary dictionary) {
                    dictionary.CanGetClassInfoByTypeHandler += new EventHandler<CanGetClassInfoByTypeEventArgs>(canGet);
                    dictionary.ResolveClassInfoByTypeHandler += new EventHandler<ResolveClassInfoByTypeEventArgs>(resolve);
                }
                Dictionary<Type, Type> map = new Dictionary<Type, Type>();
                public void Map(Type interfaceType, Type actualClassInfoType) {
                    map.Add(interfaceType, actualClassInfoType);
                }
                void canGet(object sender, CanGetClassInfoByTypeEventArgs e) {
                    if(e.CanGetClassInfo.HasValue)
                        return;
                    if(map.ContainsKey(e.ClassType))
                        e.CanGetClassInfo = true;
                }
                void resolve(object sender, ResolveClassInfoByTypeEventArgs e) {
                    if(e.ClassInfo != null)
                        return;
                    Type mapType;
                    if(map.TryGetValue(e.ClassType, out mapType)) {
                        if(mapType != null && mapType != e.ClassType) {
                            e.ClassInfo = e.Dictionary.QueryClassInfo(mapType);
                        }
                    }
                }
            }
                ReflectionDictionary myDictionary = new ReflectionDictionary();
                InterfaceAsForcedAliasHelper helper = new InterfaceAsForcedAliasHelper(myDictionary);
                helper.Map(typeof(IInterfaceAsForcedAliasTestPerson), typeof(InterfaceAsForcedAliasTestPerson));
                IDataLayer dl = new SimpleDataLayer(myDictionary, new InMemoryDataStore());
  • 相关阅读:
    合并表已经转化对象的操作
    终于也有自己的博客园一角了,权当新人报到帖了
    常见软件滤波器总结
    按键设计总结
    关于goto语句
    Delphi XE2 Default Keyboard Shortcuts
    Delphi XE2 IDE Classic Keyboard Shortcuts
    Delphi实现静态变量
    datasnap传输流/文件问题
    查询条件的封装(小结)
  • 原文地址:https://www.cnblogs.com/foreachlife/p/7569981.html
Copyright © 2011-2022 走看看