private void SetResultData <TResult>(object dbResult, SingleResultContext <TResult> singleResult) { if (dbResult == null || dbResult == DBNull.Value) { singleResult.SetData(default(TResult)); } else { var convertType = singleResult.ResultType; convertType = Nullable.GetUnderlyingType(convertType) ?? convertType; if (convertType.IsInstanceOfType(dbResult)) { singleResult.SetData(dbResult); return; } if (convertType.IsEnum) { singleResult.SetData(Enum.ToObject(convertType, dbResult)); } else { if (CommonType.Guid == convertType && CommonType.String == dbResult.GetType()) { singleResult.SetData(Guid.Parse(dbResult.ToString())); return; } singleResult.SetData(Convert.ChangeType(dbResult, convertType)); } } }
private void SetResultData <TResult>(object dbResult, SingleResultContext <TResult> singleResult) { if (dbResult == null || dbResult == DBNull.Value) { singleResult.SetData(default(TResult)); } else { var convertType = singleResult.ResultType; convertType = Nullable.GetUnderlyingType(convertType) ?? convertType; if (convertType.IsEnum) { singleResult.SetData(Enum.ToObject(convertType, dbResult)); } else { singleResult.SetData(Convert.ChangeType(dbResult, convertType)); } } }