示例#1
0
        private static void ProcessDelegates()
        {
            var delegates = _compilation.SyntaxTrees
                            .SelectMany(o => o.GetRoot().DescendantNodes().OfType <DelegateDeclarationSyntax>())
                            .Select(o => new
            {
                Syntax   = o,
                Symbol   = GetModel(o).GetDeclaredSymbol(o),
                TypeName = WriteType.TypeName(GetModel(o).GetDeclaredSymbol(o))
            }).GroupBy(o => o.Symbol.ContainingNamespace.FullNameWithDot() + o.TypeName)
                            .ToList();

            delegates.Parallel(type => //.ForEach(type => //.Parallel(type =>
            {
                Context.Instance = new Context
                {
                    TypeName         = type.First().TypeName,
                    DelegatePartials =
                        type.Select(
                            o =>
                            new Context.DelegateSyntaxAndSymbol
                    {
                        Symbol = o.Symbol,
                        Syntax = o.Syntax
                    })
                        .Where(o => !DoNotWrite.ContainsKey(o.Syntax))
                        .ToList()
                };

                if (Context.Instance.DelegatePartials.Count > 0)
                {
                    WriteDelegate.Go();
                }
            });
        }
示例#2
0
        private static void WriteOutNestedTypes(Context.SyntaxAndSymbol first, OutputWriter writer)
        {
            //WriteOut All My nested classes
            Context.Push();

            var delegates = first.Syntax.DescendantNodes().OfType <DelegateDeclarationSyntax>()
                            .Select(o => new
            {
                Syntax   = o,
                Symbol   = TypeProcessor.GetDeclaredSymbol(o),
                TypeName = WriteType.TypeName((INamedTypeSymbol)TypeProcessor.GetDeclaredSymbol(o))
            }).Where(k => k.Symbol.ContainingType == Context.Instance.Type) // Ignore all nested delegates
                            .GroupBy(o => o.Symbol.ContainingNamespace.FullNameWithDot() + o.TypeName)
                            .ToList();


            delegates.ForEach(type => //.ForEach(type => //.Parallel(type =>
            {
                Context.Instance = new Context
                {
                    TypeName         = type.First().TypeName,
                    DelegatePartials =
                        type.Select(
                            o =>
                            new Context.DelegateSyntaxAndSymbol
                    {
                        Symbol = (INamedTypeSymbol)o.Symbol,
                        Syntax = o.Syntax
                    })
                        .Where(o => !Program.DoNotWrite.ContainsKey(o.Syntax))
                        .ToList()
                };

                if (Context.Instance.DelegatePartials.Count > 0)
                {
                    WriteDelegate.Go(writer);
                }
            });
            Context.Pop();

            Context.Push();
            var subclasses = first.Syntax.DescendantNodes().OfType <BaseTypeDeclarationSyntax>()
                             .Select(o => new
            {
                Syntax   = o,
                Symbol   = TypeProcessor.GetDeclaredSymbol(o),
                TypeName = WriteType.TypeName((INamedTypeSymbol)TypeProcessor.GetDeclaredSymbol(o))
            }).Where(k => k.Symbol.ContainingType == Context.Instance.Type) // Ignore all nested classes
                             .GroupBy(o => o.Symbol.ContainingNamespace.FullNameWithDot() + o.TypeName)
                             .ToList();

            subclasses.ForEach(type => //.ForEach(type => //.Parallel(type =>
            {
                Context.Instance = new Context
                {
                    TypeName = type.First().TypeName,
                    Partials =
                        type.Select(
                            o =>
                            new Context.SyntaxAndSymbol
                    {
                        Symbol = (INamedTypeSymbol)o.Symbol,
                        Syntax = o.Syntax
                    })
                        .Where(o => !Program.DoNotWrite.ContainsKey(o.Syntax))
                        .ToList()
                };

                if (Context.Instance.Partials.Count > 0)
                {
                    try
                    {
                        WriteType.Go(writer);
                    }
                    catch (Exception ex)
                    {
                        //TODO: remove this when done with CorLib
                        throw ex;
                    }
                }
            });

            Context.Pop();
        }