庖丁解牛Asp.net3.5控件和组件开发技术系列—页面状态机制(四)
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-05-20
t;</returns> public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new Exception("目标类型不能为空!"); } if (value is SolidCoordinate) { if (destinationType == typeof(string)) { SolidCoordinate solidCoordinate = (SolidCoordinate)value; if (culture == null) { culture = CultureInfo.CurrentCulture; } string separator = culture.TextInfo.ListSeparator + " "; TypeConverter converter=TypeDescriptor.GetConverter(typeof(int)); string[] strArray = new string[3]; int num = 0; strArray[num++] = converter.ConvertToString(context, culture, s olidCoordinate.X); strArray[num++] = converter.ConvertToString(context, culture, solidCoordinate.Y); strArray[num++] = converter.ConvertToString(context, culture, solidCoordinate.Z); return string.Join(separator, strArray); } if (destinationType == typeof(InstanceDescriptor)) { SolidCoordinate solidCoordinate2 = (SolidCoordinate)value; ConstructorInfo constructor =typeof(SolidCoordinate). GetConstructor(new Type[]{typeof(int),typeof(int),typeof(int)}); if (constructor != null) { return new InstanceDescriptor(constructor, new object[] { solidCoordinate2.X, solidCoordinate2.Y, solidCoordinate2.Z }); } } } return base.ConvertTo(context, culture, value, destinationType); } /// <summary> /// 根据上下文和指定的属性字典创建实例 /// </summary> /// <param name="context"></param> /// <param name="propertyValues"></param> /// <returns></returns> public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) { if (propertyValues == null) { throw new Exception("属性值不能为空!"); } object obj2 = propertyValues["X"]; object obj3 = propertyValues["Y"]; object obj4 = propertyValues["Z"]; if (((obj2 == null) || (obj3 == null) || (obj4 == null)) || (!(obj2 is int) || !(obj3 is int) || !(obj4 is int))) { throw new Exception("格式不正确!"); } return new SolidCoordinate((int)obj2, (int)obj3, (int)obj4); |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于庖丁解牛Asp.net3.5控件和组件开发技术系列—页面状态机制(四)的所有评论