예제 #1
0
        private static void MapObjectToParameters(
            string procedure,
            object parametersObject,
            MySqlParameterCollection parameters)
        {
            ////TODO Add caching using connectionstringkey and procedure

            var properties =
                parametersObject
                .GetType()
                .GetProperties()
                .Where(p => !p.GetCustomAttributes(true).Any(a => a.GetType() == typeof(ExcludeFromMappingAttribute)))
                .Select(p => new MySqlParameter(p.Name, p.GetValue(parametersObject)));

            var fields =
                parametersObject
                .GetType()
                .GetFields()
                .Where(p => !p.GetCustomAttributes(true).Any(a => a.GetType() == typeof(ExcludeFromMappingAttribute)))
                .Select(f => new MySqlParameter(f.Name, f.GetValue(parametersObject)));

            var mappedParameters = properties.Union(fields).ToArray();

            parameters.AddRange(mappedParameters);
        }