private static void MarkCircular(Dependency d1, DependencyAnalysisResult results)
        {
            d1.Circular = true;
            if (!(d1.GraphParent is IEnumerable))
            {
                return;
            }
            var dependency = results[d1.GraphParent].DependsOn
                             .FirstOrDefault(d => d.Object == d1.Object);

            if (dependency != null)
            {
                dependency.Circular = true;
            }
        }
Exemplo n.º 2
0
 public CSharpObjectSerializerInstanceArguments(
     object @object,
     DependencyAnalysisResult dependencies,
     CompilationUnitSyntax compilationUnit
     )
 {
     Object                       = @object;
     Dependencies                 = dependencies;
     CompilationUnit              = compilationUnit;
     ObjectStatements             = new Dictionary <object, StatementSyntax>();
     EndObjectStatements          = new Dictionary <object, StatementSyntax>();
     LateCircularObjectStatements = new Dictionary <object, StatementSyntax>();
     ThisStatements               = new List <StatementSyntax>();
     ObjectsSerialized            = new Dictionary <object, CSharpObjectSerializeData>();
     CircularStatements           = new List <StatementSyntax>();
     LateCircularStatements       = new List <StatementSyntax>();
     InitialiserDependencies      = new Dictionary <object, List <object> >();
     Namespaces                   = new List <string>();
 }
        public DependencyAnalysisResult Analyse(object @object)
        {
            var results = new DependencyAnalysisResult();

            Analyse(@object, results, null);
            foreach (var result in results)
            {
                foreach (var selfReference in result.DependsOn.Where(r => r.Object == result.Object && r.TopLevel))
                {
                    MarkCircular(selfReference, results);
                }
            }
            foreach (var result in results)
            {
                foreach (var result2 in results)
                {
                    if (result2 == result)
                    {
                        continue;
                    }
                    // Do they reference each other
                    var d1s = result.DependsOn.Where(r => r.Object == result2.Object);
                    var d2s = result2.DependsOn.Where(r => r.Object == result.Object);
                    if (!d1s.Any() || !d2s.Any())
                    {
                        continue;
                    }
                    foreach (var d1 in d1s)
                    {
//						if (!(d1.Object == result2.Object && d1.GraphParent == result.Object))
                        MarkCircular(d1, results);
                    }
                    foreach (var d2 in d2s)
                    {
                        //					if (!(d2.Object == result.Object && d2.GraphParent == result2.Object))
                        MarkCircular(d2, results);
                    }
                }
            }
            return(results);
        }