Exemplo n.º 1
0
 public bool TryGetContextLazy(INamedTypeSymbol contextSymbol, out ContextSymbolWrapper context)
 {
     if (!contexts.TryGetValue(contextSymbol, out context))
     {
         return(TryCacheContext(contextSymbol, out context));
     }
     return(true);
 }
Exemplo n.º 2
0
        public bool Init(GenerationEnvironment env)
        {
            // 1. Lookup the type of the context. It is the most nested generic type of the index type.
            var contextType = (INamedTypeSymbol)symbol.Type.GetLeafTypeArguments().First();

            // 2. See if that context has already been cached in the environment.
            // 3. Initialize the context if it is not found.
            if (!env.TryGetContextLazy(contextType, out var context))
            {
                return(false);
            }

            Context = context;

            return(true);
        }
Exemplo n.º 3
0
        public bool TryInitActivationContext(GenerationEnvironment env, out ContextSymbolWrapper context)
        {
            // Initialize the context class symbol wrapper
            var ctx_symbol = symbol.GetMembers().FirstOrDefault(s => s.Name == "Context");

            if (ctx_symbol == null)
            {
                env.ReportError($"The {symbol.Name} behavior did not define a nested Context class.\nNote: Any behavior must define a Context class. If you do not have any chains in the behavior, make it a simple component. Behaviors by design differ from components in that they exploit chains.");
                context = default;
                return(false);
            }
            if (!(ctx_symbol is INamedTypeSymbol named_ctx_symbol))
            {
                env.ReportError($"The Context defined inside {symbol.Name} must be a class");
                context = default;
                return(false);
            }
            return(env.TryCacheContext(named_ctx_symbol, out context));
        }
Exemplo n.º 4
0
 public bool TryCacheContext(INamedTypeSymbol contextSymbol, out ContextSymbolWrapper context)
 {
     context = new ContextSymbolWrapper(contextSymbol);
     return(context.TryInit(this));
 }
Exemplo n.º 5
0
 public BehaviorActivationChainWrapper(string name, INamedTypeSymbol parentSymbol, ContextSymbolWrapper context)
 {
     Name    = name;
     Parent  = parentSymbol;
     Context = context;
 }