Exemplo n.º 1
0
        private void CreateBehaviorFactories(GeneratorExecutionContext context,
                                             BindingContextCollection bindingContexts,
                                             Dictionary <INamedTypeSymbol, List <BehaviorData> > behaviorMap,
                                             IEnumerable <ClassDeclarationSyntax> @classes)
        {
            // Let's start by generating code for incomplete entities
            foreach (var entity in @classes)
            {
                var model  = context.Compilation.GetSemanticModel(entity.SyntaxTree);
                var symbol = model.GetDeclaredSymbol(entity, context.CancellationToken) as INamedTypeSymbol;

                // Get the set of behaviors for this entity
                var bindingContext = bindingContexts.GetBindingContext(symbol);
                var factory        = new BehaviorFactoryResolver(symbol, behaviorMap[symbol], bindingContext);
                var code           = factory.Create();
                context.AddSource(symbol.ToString() + ".Behaviors.cs", code);
            }
        }