Ejemplo n.º 1
0
        public string GetResolution(ResolutionDefinition resolution)
        {
            var excluded = new[]
            {
                InjectionMethod.Resolver,
                InjectionMethod.This,
                InjectionMethod.CapturedFactory
            };

            if (GetPriorInjectionExpression(resolution.TargetType, excluded) is {} selfCapacity)
            {
                return(selfCapacity);
            }

            var args = new List <string>();

            foreach (var dependency in resolution.Dependencies)
            {
                // 再生成で消えるようなパラメータには引数を与えない
                if (resolution.TypeName.Name == _factory.TypeName &&
                    _factory.Dependencies.All(x => x != dependency) &&
                    _factory.Captures.All(x => x.InterfaceNameInfo != dependency))
                {
                    continue;
                }
                args.Add(GetPriorInjectionExpression(dependency) ?? ErrorPlaceHolder);
            }

            return($"new {resolution.TypeName.Name}({args.Join(", ")})");
        }
Ejemplo n.º 2
0
        public ResolverDefinition GetDefinition()
        {
            var parameters = _syntax.Parameters
                             .Select(x => new VariableDefinition(x.TypeName, x.ParameterName))
                             .ToArray();

            var resolution = _syntax.Resolutions
                             .Select(x => new ResolutionDefinition(_syntax.ReturnTypeName, x.TypeName, x.Dependencies, x.IsDisposable))
                             .FirstOrDefault();

            if (resolution is null)
            {
                if (_syntax.ReturnTypeResolution is {} ret)
                {
                    resolution = new ResolutionDefinition(_syntax.ReturnTypeName, ret.TypeName, ret.Dependencies, ret.IsDisposable);
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }