public string GenerateCode() { List<string> parameterCodeEntries; IConstructor constructor = _registration.Constructor; if (null != constructor && null != constructor.Parameters && constructor.Parameters.Count > 0) { var parameterInjectionCodeGenerator = new ParameterInjectionCodeGenerator(constructor.Parameters, _metadata, _indent, MemberTypeWord, true); var parameterCodeResult = parameterInjectionCodeGenerator.GenerateCode(); if (false == string.IsNullOrWhiteSpace(parameterCodeResult.PreMemberCode)) { _stringBuilder.Append(parameterCodeResult.PreMemberCode); } parameterCodeEntries = parameterCodeResult.ParameterCodeEntries; } else { parameterCodeEntries = new List<string>(); } string concreteTypeFullName = _registration.ConcreteType.FullName; _stringBuilder.Append(_indent); if (_declareVariable) { _stringBuilder.Append(concreteTypeFullName); _stringBuilder.Append(" "); } _stringBuilder.Append(_assignToVariable); _stringBuilder.Append(" = "); if (_registration.ConcreteType.IsPrimitive) { GenerateValueTypeCode(concreteTypeFullName); } else { GenerateReferenceOrComplexValueTypeCode(concreteTypeFullName, parameterCodeEntries); } _stringBuilder.AppendLine(";"); return _stringBuilder.ToString(); }
public string GenerateCode() { if (null == _method || null == _method.Parameters || _method.Parameters.Count < 1) { return string.Empty; } var parameterInjectionCodeGenerator = new ParameterInjectionCodeGenerator(_method.Parameters, _metadata, _indent, MemberTypeWord, false); var parameterCodeResult = parameterInjectionCodeGenerator.GenerateCode(); if (false == string.IsNullOrWhiteSpace(parameterCodeResult.PreMemberCode)) { _stringBuilder.Append(parameterCodeResult.PreMemberCode); } _stringBuilder.Append(_indent); _stringBuilder.Append(_instanceVariable); _stringBuilder.Append("."); _stringBuilder.Append(_method.Name); _stringBuilder.Append("("); int index = 0; foreach (string item in parameterCodeResult.ParameterCodeEntries) { if (index > 0) { _stringBuilder.Append(", "); } _stringBuilder.Append(item); index++; } _stringBuilder.AppendLine(");"); return _stringBuilder.ToString(); }