Exemple #1
0
        public void can_replace_base_ctor_argument_with_variable()
        {
            var type = new GeneratedType("SomeClass");

            type.InheritsFrom <ClassWithCtorArgs>();

            type.AllInjectedFields.Count.ShouldBe(3);
            type.BaseConstructorArguments.Length.ShouldBe(3);

            type.UseConstantForBaseCtor(Constant.ForEnum(Color.blue));

            type.AllInjectedFields.Count.ShouldBe(2);
            type.AllInjectedFields.Any(x => x.ArgType == typeof(Color))
            .ShouldBeFalse();

            type.BaseConstructorArguments[2].ShouldBeOfType <Variable>()
            .Usage.ShouldBe("LamarCompiler.Testing.Codegen.Color.blue");
        }
        public GeneratedType AddType(string typeName, Type baseType)
        {
            // TODO -- assert that it's been generated already?

            var generatedType = new GeneratedType(Generation, typeName);

            if (baseType.IsInterface)
            {
                generatedType.Implements(baseType);
            }
            else
            {
                generatedType.InheritsFrom(baseType);
            }

            GeneratedTypes.Add(generatedType);

            return(generatedType);
        }