/// <summary> /// Write Source /// </summary> /// <param name="writer"></param> internal override void WriteSource(System.IO.StreamWriter writer, TsGeneratorOptions options, TsWriteInformation info) { //if there are comments write them if (Comments.Any()) { Comments.ToList().ForEach(el => el.WriteSource(writer, options, info)); } //if there is a name if (HasName) { //add statement begin var namespaceSource = AddStatementBegin(string.Format(TsDomConstants.TS_NAMESPACE_FORMAT, Name), options, info.Depth); //write statement line writer.WriteLine(namespaceSource); //add imports Imports.ToList().ForEach(el => el.WriteSource(writer, options, info.Clone(info.Depth + 1))); //write content WriteContent(writer, options, info.Clone(info.Depth + 1)); //write close statement writer.WriteLine(GetStatementEnd(options, info.Depth)); } //if there is no name just add content else { //add imports Imports.ToList().ForEach(el => el.WriteSource(writer, options, info)); WriteContent(writer, options, info.Clone()); } }
/// <summary> /// Write Source /// </summary> /// <param name="writer"></param> internal override void WriteSource(System.IO.StreamWriter writer, TsGeneratorOptions options, TsWriteInformation info) { //write base stuff base.WriteSource(writer, options.Clone(options.IndentString, false), info); //sec check if (info.ForType != TsElementTypes.Class) { throw new Exception("TsCodeMemberProperty can only be defined for class"); } if (!Types.Any()) { throw new Exception("TsCodeMemberProperty type not defined"); } //prepare source var source = options.GetPreLineIndentString(info.Depth); //add attributres if (Attributes != TsMemberAttributes.None) { source += TsMemberAttributeMappings.TypeMappings[Attributes] + TsDomConstants.ATTRIBUTE_SEPEARATOR; } //if there is no setter and getter this is a bit useless if (!HasSet && !HasGet) { throw new Exception("TsCodeMemberProperty there is no setter and getter for MemberProperty" + Name); } //if we have a getter write getter if (HasGet) { var getSource = source + string.Format(TsDomConstants.GETTER_FORMAT, Name, GetTypeSource()) + TsDomConstants.STATEMENT_BRACKET_BEGIN; //write begin line writer.WriteLine(getSource); //write statemetns GetStatements.ToList().ForEach(el => el.WriteSource(writer, options, info.Clone(info.Depth + 1))); //write end source writer.WriteLine(GetStatementEnd(options, info.Depth)); } //as setter if (HasSet) { var setSource = source + string.Format(TsDomConstants.SETTER_FORMAT, Name, SetParameterName, GetTypeSource()) + TsDomConstants.STATEMENT_BRACKET_BEGIN; //write begin line writer.WriteLine(setSource); //write statemetns SetStatements.ToList().ForEach(el => el.WriteSource(writer, options, info.Clone(info.Depth + 1))); //write end source writer.WriteLine(GetStatementEnd(options, info.Depth)); } }
/// <summary> /// GetSource /// </summary> /// <returns></returns> internal override string GetSource(TsGeneratorOptions options, TsWriteInformation info) { var source = TsDomConstants.STATEMENT_BRACKET_BEGIN; //if there are properties if (Properties.Any()) { var newInfo = info.Clone(info.Depth + 1); newInfo.ForType = TsElementTypes.InlineObject; newInfo.MemberNameAsString = MemberNameAsString; //add new Line source += Environment.NewLine; Properties.ToList().ForEach(el => source += el.GetStringFromWriteSource(options, newInfo)); source += options.GetPreLineIndentString(info.Depth); } source += TsDomConstants.STATEMENT_BRACKET_END; //return return(source); }
/// <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); } }
/// <summary> /// Write Source /// </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) { //sec check if (Condition == null) { throw new ArgumentNullException("Condition in TsConditionStatement not set"); } //get condition source string conditionSource = Condition.GetSource(options, info); //create statement string statementSource = options.GetPreLineIndentString(info.Depth) + string.Format(TsDomConstants.TS_IF_STATEMENT_FORMAT, conditionSource); //add start bracket for true condition statementSource += TsDomConstants.STATEMENT_BRACKET_BEGIN; //write writer.WriteLine(statementSource); //if there are true statements (add them) if (TrueStatements.Any()) { //write statements TrueStatements.ToList().ForEach(el => el.WriteSource(writer, options, info.Clone(info.Depth + 1))); } //write end bracket writer.WriteLine(GetStatementEnd(options, info.Depth)); }