zoukankan      html  css  js  c++  java
  • 《ASP.NET组件设计》没提到的一个类

    就是这个, ItemBuilderConverter,
    终于搞明白这个 IComponent.Site是什么意思了。

    public class ItemBuilderConverter : TypeConverter
        
    {
            
    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
            
    {
                
    if (sourceType == typeof (string))
                    
    return true;
                
    return base.CanConvertFrom(context, sourceType);
            }


            
    public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
            
    {
                
    if (destinationType == typeof (string))
                    
    return true;
                
    return base.CanConvertTo(context, destinationType);
            }


            
    public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
            
    {
                
    if (value == null || value.ToString() == string.Empty) return string.Empty;
               
                
    object result = context.Container.Components[value.ToString()];
                
    if (result != null)
                
    {
                    
    return value.ToString();
                }

                
    return string.Empty;            
            }


            
    public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
            
    {
                
    if (destinationType == nullthrow new Exception("目标类型为null");
                
    if (value == nullreturn null;

                
    return base.ConvertTo(context, culture, value, destinationType);
            }

            
    public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            
    {
                
    return true;
            }



            
    public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            
    {         
                IList list 
    = new ArrayList();
                
                IEnumerator itor 
    = context.Container.Components.GetEnumerator();
                
    while(itor.MoveNext())
                
    {
                    
    object item = itor.Current;
                    
    if(item is IListsBuilder)
                    
    {
                        list.Add( ((IComponent)item).Site.Name );
                    }

                }
            
                
    if (list.Count > 0)
                
    {                
                    
    return new StandardValuesCollection(list);
                }
                    
                
    return base.GetStandardValues(context);
            }



        }
  • 相关阅读:
    娓娓道来c指针 (4)解析c的声明语句
    Snail—UI学习之UITextField
    E
    Qt录音机
    著名的英文搜索引擎
    java中Map,List与Set的差别
    Android图片处理:识别图像方向并显示
    Unity3D中组件事件函数的运行顺序
    Android屏幕density, dip等相关概念总结
    Codeforces Round #257 (Div. 2)
  • 原文地址:https://www.cnblogs.com/xiaotaoliang/p/389254.html
Copyright © 2011-2022 走看看