public override bool SetField(object context, FieldInfo field, string valueString, string[] format, IScalarUnmarshallingContext scalarUnmarshallingContext) { if (valueString == null || string.IsNullOrWhiteSpace(valueString)) { return(true); } bool result = false; object valueObject = valueScalarType.GetInstance(valueString, format, scalarUnmarshallingContext); if (valueObject != null) { Object metadataScalarContext = field.GetValue(context); if (metadataScalarContext == null) { Type t = field.FieldType; metadataScalarContext = Activator.CreateInstance(t, new object[] { valueObject }); field.SetValue(context, metadataScalarContext); } else { ValueField.SetValue(metadataScalarContext, valueObject); } result = true; } return(result); }
public void AddLeafNodeToCollection(object root, string value, TranslationContext translationContext) { if (String.IsNullOrEmpty(value)) { return; } if (ScalarType != null) { Object typeConvertedValue = ScalarType.GetInstance(value, dataFormat, translationContext); if (typeConvertedValue != null) { IList collection = (IList)AutomaticLazyGetCollectionOrMap(root); collection.Add(typeConvertedValue); } } }