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);
            }



        }
  • 相关阅读:
    Python:给你们安排一波VIP音乐,看我是如何不充会员也能下载的
    最详细Python打包exe教程,并修改图标,30秒搞定!
    Python:20行代码爬取高质量帅哥美女视频,让你一次看个够
    【Python爬虫】招聘网站实战合集第一弹:爬取前程无忧
    Python爬虫:爬点大家都喜欢的东西,比如美女!每天保持心情愉悦!
    Python吃喝玩乐:爬取全城按摩门店,看看有没有你想去的!
    明天就是1024了,Python前来报到!爬取全网M子图片!
    周末福利!用Python爬取美团美食信息,吃货们走起来!
    Python小工具:据说这是搜索文件最快的工具!没有之一!一起感受下......
    简单实现一个流程图(箭头流程图)
  • 原文地址:https://www.cnblogs.com/xiaotaoliang/p/389254.html
Copyright © 2011-2022 走看看