/// <summary> /// <paramref name="sourceObj" /> is expected to be a plain object - not collection. /// </summary> /// <param name="targetSetFldInfo">The field information.</param> /// <param name="sourceObj">The color object.</param> /// <param name="val">The value.</param> /// <returns><c>true</c> if field read correctly;<c>false</c> otherwise.</returns> protected virtual bool ReadFieldValue( [NotNull] FieldInfo targetSetFldInfo, [CanBeNull] ClrObject sourceObj, [CanBeNull] out object val) { Assert.ArgumentNotNull(targetSetFldInfo, "targetSetFldInfo"); val = null; string fldName = targetSetFldInfo.Name; try { if (targetSetFldInfo.FieldType == typeof(string)) { val = sourceObj.GetStringSafe(fldName); return(true); } // F.e. Int, float ... if (targetSetFldInfo.FieldType.IsPrimitive) { // TODO: NMI test. Migration to newer CLR var fld = sourceObj.Type.GetFieldByName(fldName); val = fld.GetValue(sourceObj.Address); // val = sourceObj.Type.GetFieldValue(sourceObj.Address, new[] { fldName }); // = sourceObj.Type.GetTypeToMapOn(sourceObj.GetValueFld(fldName).Address); return(true); } if (targetSetFldInfo.FieldType.IsEnum) { // TODO: NMI test. Migration to newer CLR var fld = sourceObj.Type.GetFieldByName(fldName); val = fld.GetValue(sourceObj.Address); return(true); // return sourceObj.Type.TryGetFieldValue(sourceObj.Address, new[] { fldName }, out val); } // Try read primitive types like Guid, ID, DateTime . // And return read value as an instance of primitive type. if (this.PrimitiveKnownTypesFieldRdr.TryCalcFieldValue(targetSetFldInfo, sourceObj, out val)) { return(true); } // Read pointer for the object reference ClrObject value = sourceObj.GetRefFld(fldName); // Read value through recursion. val = this.BuildModel(value); return(true); } catch (Exception ex) { // TODO: Consider returning true and an exception. return(false); } }