/// <summary>
        /// Find all unique dependencies for a given CustomType, including field, method, nested, inherited,
        /// and generic types.  Then assign this set of dependencies to the given CustomType.
        /// </summary>
        private void GatherDependencies(CustomType customType)
        {
            // First find all unique assembly Types that this CustomType depends on
            HashSet <Type> dependencySet = new HashSet <Type>();

            dependencySet.UnionWith(GetFieldDependencies(customType.assemblyType));
            dependencySet.UnionWith(GetMethodDependencies(customType.assemblyType));
            dependencySet.UnionWith(GetNestedDependencies(customType.assemblyType));
            dependencySet.UnionWith(GetInheritedDependencies(customType.assemblyType));

            // Iterate through these Type dependencies, and find the corresponding valid CustomType from the lookup table
            HashSet <CustomType> customDependencySet = new HashSet <CustomType>();

            foreach (Type t in dependencySet)
            {
                //Ignore dependency with self
                if (t != customType.assemblyType)
                {
                    string simplifiedName = CustomType.SimplifyTypeFullName(t);

                    //Dont add dependencies that aren't CustomTypes (e.g. those in System or Unity namespaces, as previously filtered)
                    if (customTypeLookup.ContainsKey(simplifiedName))
                    {
                        customDependencySet.Add(customTypeLookup[simplifiedName]);
                    }
                }
            }

            // Assign this unique set of dependencies to the CustomType for easy access later
            customType.dependencies = customDependencySet;
        }
Exemple #2
0
        /// <summary>
        /// Determine if the matched type has any parents.  If so, create the text that should be prepended
        /// onto the given type to match the format used in the customTypeLookup from DependencyAnalyzer.
        /// E.g. if B is not nested, return an empty string.  If B is nested in A, return "A+".
        /// If C is nested in B which is nested in A, return "A+B+".
        /// </summary>
        private string FindParentTypesInText(CustomType previousType, int startLineNum, int endLineNum)
        {
            System.Text.StringBuilder typeString = new System.Text.StringBuilder();

            // Handle nested types (e.g. private classes nested in other classes, potentially many nested levels)
            bool foundParent = false;

            do
            {
                // No outer type detected, i.e. match is not nested
                if (previousType == null)
                {
                    foundParent = true;
                }
                //Check if match is nested in previous matched type
                else if (startLineNum >= previousType.startLineNum && endLineNum <= previousType.endLineNum)
                {
                    Type parent = previousType.assemblyType;
                    while (parent.IsNested)
                    {
                        typeString.Insert(0, parent.Name + "+");
                        parent = parent.DeclaringType;
                    }
                    typeString.Insert(0, parent.Name + "+");
                    foundParent = true;
                }
                //Not nested in previous matched type. Check if nested in that type's parent (if it exists)
                else
                {
                    if (previousType.assemblyType.DeclaringType != null)
                    {
                        previousType = DependencyAnalyzer.GetCustomTypeFromString(CustomType.SimplifyTypeFullName(previousType.assemblyType.DeclaringType));
                    }
                    else
                    {
                        previousType = null;
                    }
                }
            } while (!foundParent);

            return(typeString.ToString());
        }