public bool Compatible(Type type)
        {
            if (type == null)
            {
                /*
                 * 这里type是有可能为null的,是正常情况,如:
                 *  _gridView.GridViewController.DataBind(e.Node.Items, e.Node.ItemType, e.Node.DataBoundItem);
                 *  其中的 e.Node.ItemType 为null,因为没有配子类型
                 *  这时进到这里来的时候,type就为null
                 *  按讲,外部调用者应确认type是否为null,但为保证健壮性,这里视type为null时,返回false
                 *  不抛异常,但断言,因为应该在外部调用之前判断type是否为null
                 */
                Debug.Assert(false, "type为null");
                return(false);
            }
            bool compatible = false;

            if (DataBoundType.IsClass)
            {
                compatible = type.Equals(DataBoundType) ||
                             (_actOnSubClass && type.IsSubclassOf(DataBoundType));
            }
            else if (DataBoundType.IsInterface)
            {
                compatible = type == DataBoundType || type.GetInterface(DataBoundType.ToString()) != null;
            }
            return(compatible);
        }
        public void AddCodon(TypeBinderDataGridViewTypeCodon codon)
        {
            if (codon == null)
            {
                Debug.Assert(false, "codon 为 null");
                throw new ArgumentNullException();
            }
            if (_codons.Contains(codon))
            {
                Debug.Assert(false, "_typeBinderDataGridViewTypeCodons 重复添加:" + codon.ToString());
                return;
            }
            Type dataBoundType = codon.DataBoundType;

            Debug.Assert(GetCodon(dataBoundType) == null,
                         "_typeBinderDataGridViewTypeCodons 重复添加类型:" + codon.ToString());
            bool compatible = false;

            if (DataBoundType.IsClass)
            {
                compatible = dataBoundType.Equals(DataBoundType) || dataBoundType.IsSubclassOf(DataBoundType);
            }
            else if (DataBoundType.IsInterface)
            {
                compatible = dataBoundType == DataBoundType ||
                             dataBoundType.GetInterface(DataBoundType.ToString()) != null;
            }
            if (compatible == false)
            {
                Debug.Assert(false, "指定的 codon 所绑定的对象类型不是该 ComboCodon 绑定类型的子类型:" + codon.ToString());
            }
            _codons.Add(codon);
        }
 public override string ToString()
 {
     if (DataBoundType != null)
     {
         return(DataBoundType.ToString());
     }
     else
     {
         return(base.ToString());
     }
 }
示例#4
0
        public bool UpwardCompatible(Type type)
        {
            if (type == null)
            {
                Debug.Assert(false, "type为null");
                throw new ArgumentNullException();
            }
            bool compatible = type.Equals(DataBoundType) || DataBoundType.IsSubclassOf(type);

            return(compatible);
        }
        public bool UpwardCompatible(Type type)
        {
            if (type == null)
            {
                Debug.Assert(false, "type为null");
                throw new ArgumentNullException();
            }
            bool compatible = false;

            if (DataBoundType.IsClass)
            {
                compatible = type.Equals(DataBoundType) || DataBoundType.IsSubclassOf(type);
            }
            else if (DataBoundType.IsInterface)
            {
                compatible = DataBoundType == type || DataBoundType.GetInterface(type.ToString()) != null;
            }
            return(compatible);
        }
        public bool Compatible(Type type)
        {
            if (type == null)
            {
                Debug.Assert(false, "type为null");
                return(false);
            }
            bool compatible = false;

            if (DataBoundType.IsClass)
            {
                compatible = type.Equals(DataBoundType) ||
                             (_actOnSubClass && type.IsSubclassOf(DataBoundType));
            }
            else if (DataBoundType.IsInterface)
            {
                compatible = type == DataBoundType || type.GetInterface(DataBoundType.ToString()) != null;
            }
            return(compatible);
        }