Пример #1
0
        private IEnumerable <CSharpClassMember> CreateSingletons(ContainerRegistrationMethod registration)
        {
            var members = new List <CSharpClassMember>();

            var binding   = registration.Binding;
            var fieldName = binding.GetSingletonFieldName();
            var field     = new CSharpField(binding, fieldName, false);

            members.Add(field);

            var condition  = new CSharpBinaryStatement(new CSharpSymbol(fieldName), CSharpSymbol.NULL, "==");
            var statements = new CSharpStatement[] {
                new CSharpBinaryStatement(new CSharpSymbol(fieldName), new CSharpInvoke(registration.FactoryMethod, new CSharpStatement[0]), "=", true),
            };
            var ifStatement = new CSharpIf(condition, statements);
            var resolveBody = new CSharpStatement[] {
                ifStatement,
                new CSharpReturn(new CSharpSymbol(fieldName))
            };
            var resolveName   = binding.GetResolveNameBind();
            var resolveMethod = new CSharpClassMethod(binding, resolveName,
                                                      new MethodParameter[0], false, resolveBody);

            members.Add(resolveMethod);

            return(members);
        }
Пример #2
0
        private CSharpClassMethod CreateTransients(ContainerRegistrationMethod registration)
        {
            var resultStatement = new CSharpInitVariable(null, "result", new CSharpInvoke(registration.FactoryMethod, new CSharpStatement[0]));
            var resolveBody     = new CSharpStatement[] {
                resultStatement,
                new CSharpReturn(new CSharpSymbol("result"))
            };
            var resolveName   = registration.Binding.GetResolveNameBind();
            var resolveMethod = new CSharpClassMethod(registration.Binding, resolveName,
                                                      new MethodParameter[0], false, resolveBody);

            return(resolveMethod);
        }