public void UseConstantForBaseCtor(Variable variable) { var index = BaseConstructorArguments.GetFirstIndex(v => v.VariableType == variable.VariableType); if (index < 0) { throw new InvalidOperationException("No base constructor arguments of type " + variable.VariableType.FullNameInCode()); } BaseConstructorArguments[index] = variable; AllInjectedFields.RemoveAt(index); }
private void writeConstructorMethod(ISourceWriter writer, IList<InjectedField> args) { var ctorArgs = args.Select(x => x.CtorArgDeclaration).Join(", "); var declaration = $"BLOCK:public {TypeName}({ctorArgs})"; if (BaseConstructorArguments.Any()) declaration = $"{declaration} : base({BaseConstructorArguments.Select(x => x.CtorArg).Join(", ")})"; writer.Write(declaration); foreach (var field in args) field.WriteAssignment(writer); writer.FinishBlock(); }
Variable IVariableSource.Create(Type type) { return(BaseConstructorArguments.FirstOrDefault(x => x.ArgType == type)); }
bool IVariableSource.Matches(Type type) { return(BaseConstructorArguments.Any(x => x.ArgType == type)); }