Beispiel #1
0
        public static DataTable ToDataTable(this TraceEvent traceEvent)
        {
            #region Argument exceptions

            if (traceEvent == null)
            {
                throw new ArgumentNullException("traceEvent");
            }

            #endregion

            var columns = traceEvent.Columns.Cast <TraceColumn>()
                          .Where((c) => c != ProfilerCollector.TraceColumnFilter)
                          .Select((c) => new { Name = c.ToName() });

            var properties = ProfilerResult.ItemsType
                             .GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public)
                             .Where((p) => !p.CanWrite);

            var query = properties.Join(columns,
                                        o => o.Name,
                                        i => i.Name,
                                        (o, i) =>
            {
                var columnType = o.PropertyType;

                if (o.PropertyType == typeof(TraceEventClass) || o.PropertyType == typeof(TraceEventSubclass) || o.PropertyType == typeof(Type))
                {
                    columnType = typeof(string);
                }

                return(new
                {
                    ColumnName = o.Name,
                    ColumnType = columnType
                });
            },
                                        StringComparer.OrdinalIgnoreCase
                                        );

            var table = new DataTable(traceEvent.EventID.ToName(), traceEvent.ToNamespace());
            foreach (var property in query)
            {
                table.Columns.Add(property.ColumnName, property.ColumnType);
            }

            return(table);
        }