| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:AssemblyQualifiedTypeNameConverter.cs
- * 2.功能描述:类型配置转换器
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈晓野 2014/09/16 1.00 新建
- *******************************************************************************/
- using System;
- using System.ComponentModel;
- using System.Configuration;
- using System.Globalization;
- namespace Dongke.IBOSS.PRD.WCF.Services.ConfigSetting
- {
- /// <summary>
- /// 类型配置转换器
- /// </summary>
- public class AssemblyQualifiedTypeNameConverter : ConfigurationConverterBase
- {
- public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
- {
- string typeName = (string)value;
- if (string.IsNullOrEmpty(typeName))
- {
- return null;
- }
- Type result = Type.GetType(typeName, false);
- if (result == null)
- {
- throw new ArgumentException(string.Format("不能加载类型\"{0}\"", typeName));
- }
- return result;
- }
- public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
- {
- Type type = value as Type;
- if (null == type)
- {
- throw new ArgumentNullException("value");
- }
- return type.AssemblyQualifiedName;
- }
- }
- }
|