Bamboo.Prevalence.VersionMigration.MigrationContext.ChangeType C# (CSharp) Метод

ChangeType() публичный Метод

public ChangeType ( object value, Type conversionType ) : object
value object
conversionType System.Type
Результат object
		public object ChangeType(object value, Type conversionType)
		{
			if (null != value)
			{
				if (conversionType.IsEnum)
				{
					if (value is string)
					{
						return Enum.Parse(conversionType, (string)value);
					}
				}
				TypeConverter converter = TypeDescriptor.GetConverter(conversionType);
				if (null != converter && converter.CanConvertFrom(value.GetType()))
				{
					return converter.ConvertFrom(null, _plan.Culture, value);
				}
				return Convert.ChangeType(value, conversionType, _plan.Culture);
			}
			return null;
		}

Usage Example

		public void InitializeField(MigrationContext context)
		{			
			FieldInfo field = context.CurrentField;
			SerializationInfo info = context.CurrentSerializationInfo;

			object value = info.GetValue(_fieldName, field.FieldType);
			field.SetValue(context.CurrentObject, context.ChangeType(value, field.FieldType));
			context.Trace("Field {0} set to \"{1}\" loaded from field {2}.", field.Name, value, _fieldName);
		}
All Usage Examples Of Bamboo.Prevalence.VersionMigration.MigrationContext::ChangeType