Exemplo n.º 1
0
        /// <summary>
        /// Takes the given type and recurses that type's properties
        /// down to the <see cref="FlattenTypeArgs.Depth"/> until a terminating property
        /// is a value type (both <see cref="System.ValueType"/>
        /// and <see cref="System.String"/>)
        /// </summary>
        /// <param name="fta"></param>
        /// <returns>
        /// A list of strings where the item after the last <see cref="FlattenTypeArgs.Separator"/> is the
        /// terminating, value type, property and each item between the other <see cref="FlattenTypeArgs.Separator"/>
        /// is either the property name or the type name.  The entries may be thought of
        /// like dot-notation (e.g. MyObject.MyProperty.ItsProperty.ThenItsProperty).
        /// The item before the first space (0x20) is the particular value type.
        /// </returns>
        public static FlattenedType FlattenType(FlattenTypeArgs fta)
        {
            var assembly      = fta.Assembly;
            var typeFulleName = fta.TypeFullName;
            var maxDepth      = fta.Depth;

            var startCount = 0;

            if (maxDepth <= 0)
            {
                maxDepth = 16;
            }
            var results = FlattenType(assembly, typeFulleName, ref startCount, maxDepth, fta.LimitOnThisType,
                                      fta.DisplayEnums, null, null);

            return(new FlattenedType
            {
                Lines = results,
                UseTypeNames = fta.UseTypeNames,
                RootType = assembly.GetType(typeFulleName),
                Separator = fta.Separator
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Dumps an entire assembly into a list of <see cref="FlattenedLine"/>
        /// </summary>
        /// <param name="fla"></param>
        /// <param name="writeProgress">Optional handler to write progress for the calling assembly.</param>
        /// <returns></returns>
        public static FlattenAssembly GetFlattenedAssembly(FlattenLineArgs fla, Action <ProgressMessage> writeProgress = null)
        {
            if (fla == null)
            {
                throw new ArgumentNullException(nameof(fla));
            }
            if (fla.Assembly == null)
            {
                throw new ArgumentException("The Assembly reference must be passed in " +
                                            "with the FlattenLineArgs");
            }

            writeProgress?.Invoke(new ProgressMessage
            {
                Activity        = "Getting all types from assembly",
                ProcName        = Process.GetCurrentProcess().ProcessName,
                ProgressCounter = 1,
                Status          = "OK"
            });

            var allTypeNames = fla.Assembly.NfGetTypes().Select(x => x.FullName).ToList();
            var allLines     = new List <FlattenedLine>();
            var counter      = 0;
            var total        = allTypeNames.Count;

            foreach (var t in allTypeNames)
            {
                writeProgress?.Invoke(new ProgressMessage
                {
                    Activity        = t,
                    ProcName        = Process.GetCurrentProcess().ProcessName,
                    ProgressCounter = Etc.CalcProgressCounter(counter, total),
                    Status          = "Working Type Names"
                });

                var flattenArgs = new FlattenTypeArgs
                {
                    Assembly        = fla.Assembly,
                    TypeFullName    = t,
                    Depth           = fla.Depth,
                    Separator       = fla.Separator,
                    UseTypeNames    = fla.UseTypeNames,
                    LimitOnThisType = fla.LimitOnThisType
                };
                var flattenedType = FlattenType(flattenArgs);
                foreach (var line in flattenedType.Lines.Where(x => !string.IsNullOrWhiteSpace(x.ValueType)))
                {
                    //if there is a limit on some type and this line is that type in any form then continue
                    if (!string.IsNullOrWhiteSpace(fla.LimitOnThisType) &&
                        !string.Equals(fla.LimitOnThisType, line.ValueType, StringComparison.OrdinalIgnoreCase) &&
                        !string.Equals(fla.LimitOnThisType,
                                       NfReflect.GetLastTypeNameFromArrayAndGeneric(line.ValueType),
                                       StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    if (allLines.Any(x => x.Equals(line)))
                    {
                        continue;
                    }

                    allLines.Add(line);
                }
                counter += 1;
            }
            return(new FlattenAssembly {
                AllLines = allLines, AssemblyName = fla.Assembly.GetName().FullName
            });
        }