/// <summary> /// AddCustomAttributes /// </summary> /// <param name="writer"></param> private void AddCustomAttributes(StreamWriter writer, TsGeneratorOptions options, int depth) { //check if there are custom attributes if (Decorators.Any()) { //add indent var customAttributeString = options.GetPreLineIndentString(depth); //get source var attributeList = Decorators.Select(el => el.GetSource()); customAttributeString += string.Join(TsDomConstants.ATTRIBUTE_SEPEARATOR, attributeList); //write custom attribute string writer.WriteLine(customAttributeString); } }
/// <summary> /// Write Source /// attribute methodname() : returntype /// </summary> /// <param name="writer"></param> /// <param name="options"></param> /// <param name="info"></param> internal override void WriteSource(System.IO.StreamWriter writer, TsGeneratorOptions options, TsWriteInformation info) { //write base stuff base.WriteSource(writer, options, info); //check if (Decorators.Any()) { throw new NotImplementedException("CodeMemberMethod, CustomAttributes not implemented yet!"); } //set attribute var methodTypeSource = GetSource(); if (Attributes != TsMemberAttributes.None) { methodTypeSource = TsMemberAttributeMappings.TypeMappings[Attributes] + TsDomConstants.ATTRIBUTE_SEPEARATOR + methodTypeSource; } //add method source var methodSource = options.GetPreLineIndentString(info.Depth) + string.Format(TsDomConstants.TS_MEMBERMETHOD_FORMAT, methodTypeSource, GetParameterSource(options, info)); //return type (empty string if not available) if (ReturnType != null) { methodSource = string.Format(TsDomConstants.TS_ELEMENT_TYPE_FORMAT, methodSource, ReturnType.TsTypeName); } // we only write method info for interfaces if (info.ForType != TsElementTypes.Interface) { //add statement begin methodSource += TsDomConstants.ATTRIBUTE_SEPEARATOR + TsDomConstants.STATEMENT_BRACKET_BEGIN; //write begin line writer.WriteLine(methodSource); //write statemetns Statements.ToList().ForEach(el => el.WriteSource(writer, options, info.Clone(info.Depth + 1))); //write end source writer.WriteLine(GetStatementEnd(options, info.Depth)); } else { methodSource += TsDomConstants.EXPRESSION_END; writer.WriteLine(methodSource); } }
public override TypescriptBuilder Build(TypescriptBuilder builder, IElement parent) { if (Decorators.Any()) { builder.NewLine(); } builder.Join(Decorators, b => b.NewLine()); if (Decorators.Any()) { builder.NewLine(); } if (parent == null) { builder.Append("var ").Append(Name); if (HasType) { builder.Append(": ").Append(Type); } if (HasValue) { builder.Append(" = ").Append(Value); } builder.Append(";"); } if (HasGetter && parent is Class) { builder.Append(Get, this); } if (HasGetter && HasSetter) { builder.NewLine(); } if (HasSetter && parent is Class) { builder.Append(Set, this); } if (!HasSetter && !HasGetter && parent != null || parent is Interface) { var modifiers = Modifiers.Distinct().OrderBy(m => !(m is IAccessor)).Select(m => m.ToString()); builder.Join(modifiers, " "); if (Modifiers.Any()) { builder.Append(' '); } builder.Append(Name); if (HasType) { builder.Append(": ").Append(Type); } if (HasValue) { builder.Append(" = ").Append(Value); } builder.Append(";"); } return(builder); }