public static bool ExtractParameters <T>(this DynamicParameters param, T element) { var returnValue = false; if (element != null) { param.SetDefaultReturnValue(); var elementType = element.GetType(); var props = elementType.GetProperties(); foreach (var prop in props) { IgnoreExtractionAttribute attribute = null; foreach (var attr in prop.GetCustomAttributes(true)) { attribute = attr as IgnoreExtractionAttribute; if (attribute != null) { break; } } if (attribute == null) { var value = prop.GetValue(element, new object[] { }); if ((prop.Name == "Id" || prop.Name == $"{elementType.Name}Id") && object.Equals(value, prop.PropertyType.IsValueType ? Activator.CreateInstance(prop.PropertyType) : null)) { param.Add($"@{prop.Name}", dbType: DbType.Int32, size: 4, direction: ParameterDirection.Output); continue; } if (value != null) { param.Add($"@{prop.Name}", value); } } } returnValue = true; } return(returnValue); }