public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value == null) { return(null); } ChoNotNullableArrayList arrayList = new ChoNotNullableArrayList(); object notNullItem = null; if (value.GetType().IsArray) { foreach (object item in (Array)value) { if (item == null) { continue; } notNullItem = item; ChoValidationResults validationResults = ChoValidation.Validate(item); if (validationResults != null && validationResults.Count > 0) { continue; } arrayList.Add(item); } return(notNullItem == null ? null : arrayList.ToArray(notNullItem.GetType())); } else { return(value); } }
// If the type of the value to convert is string, parses the string // and returns the integer to set the value of the property to. // This example first extends the integer array that supplies the // standard values collection if the user-entered value is not // already in the array. public override object ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { value = ChoType.GetMemberValue(Target, DependentMemberName); object convertedObject = null; using (ChoBufferProfileEx outerProfile = new ChoBufferProfileEx(LogFileName, "Converting file to objects....")) { try { if (value.GetType() == typeof(string)) { convertedObject = GetObject(value as string, outerProfile); } else if (value.GetType() == typeof(string[])) { ChoNotNullableArrayList convertedObjects = new ChoNotNullableArrayList(); foreach (string fileName in (string[])value) { convertedObjects.Add(GetObject(fileName, outerProfile)); } convertedObject = convertedObjects.ToArray(ObjElementType); } } catch (ChoFatalApplicationException) { throw; } catch (Exception ex) { outerProfile.Append(ex); } } return(convertedObject); }
public void Dispose() { _msg = null; _tokens = null; }