コード例 #1
0
        // For cached queries, local values are passed in closure object. The problem is that a single closure is created for a method,
        // and a query might use only some of closure values. So for each field in closure we check that it is actually used in the query we report.
        private static string FormatClosureValues(string fromExpression, string paramName, object obj)
        {
            if (obj == null)
            {
                return(paramName + "=null");
            }
            var type = obj.GetType();

            if (!type.IsAnonymousType())
            {
                return(paramName + "=" + LoggingExtensions.ToLogString(obj));
            }
            //Anonymous type
            var fields    = type.GetFields();
            var strValues = new StringList();

            for (int i = 0; i < fields.Length; i++)
            {
                var fld         = fields[i];
                var fullRefName = paramName + "." + fld.Name;
                if (fromExpression.Contains(fullRefName))
                {
                    strValues.Add(fullRefName + "=" + LoggingExtensions.ToLogString(fld.GetValue(obj)));
                }
            }
            return(string.Join(", ", strValues));
        }