private void StreamEntityFieldValue(Field field) { try { var getEntityValueMethod = GetEntityFieldValueMethod(field); var valueType = GetFieldValueType(field); var genericGet = getEntityValueMethod.MakeGenericMethod(valueType); var fieldSpecType = field.GetSpecTypeId(); var unit = UnitUtils.IsMeasurableSpec(fieldSpecType) ? UnitUtils.GetValidUnits(field.GetSpecTypeId()).First() : UnitTypeId.Custom; var parameters = getEntityValueMethod.GetParameters().Length == 1 ? new object[] { field } : new object[] { field, unit }; var value = genericGet.Invoke(_entity, parameters); AddFieldValue(field, value); } catch (Exception ex) { _data.Add(new Data.Exception(field.FieldName, ex)); } }
private static bool IsGetByFieldMethod(MethodInfo methodInfo, Field field) { var parameters = methodInfo.GetParameters(); var fieldSpecType = field.GetSpecTypeId(); if (UnitUtils.IsMeasurableSpec(fieldSpecType) || fieldSpecType == SpecTypeId.Custom) { var firstParameter = parameters[0]; var lastParameter = parameters[parameters.Length - 1]; return(parameters.Length == 2 && firstParameter.ParameterType == typeof(Field) && lastParameter.ParameterType == typeof(ForgeTypeId)); } return(parameters.Length == 1 && parameters.Single().ParameterType == typeof(Field)); }