/// <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); //get line Intend string var intendLineString = options.GetPreLineIndentString(info.Depth); //membername (nullable for inline objects not allowed) var memberName = IsNullable && info.ForType != TsElementTypes.InlineObject ? string.Format(TsDomConstants.NULLABLE_FORMAT, Name) : Name; //prepare source var source = string.Empty; //we dont need the type for constant if (info.ForType == TsElementTypes.Constant || info.ForType == TsElementTypes.InlineObject || info.ForType == TsElementTypes.Enumerations) { //if its an inline object and membername as string => add string signs if (info.ForType == TsElementTypes.InlineObject && info.MemberNameAsString) { memberName = string.Format(TsDomConstants.STRING_VALUE_FORMAT, memberName); } source += memberName; } else { source += string.Format(TsDomConstants.TS_ELEMENT_TYPE_FORMAT, memberName, GetTypeSource()); } //typeattributes are only interresting in classes if (info.ForType == TsElementTypes.Class) { //get type attributes var typeAttributes = TsTypeAttributeMappings.TypeMappings.Where(el => TypeAttributes.HasFlag(el.Key)).OrderBy(el => el.Key).ToList(); //combine attriubtes var typeAttributeSource = string.Join(TsDomConstants.ATTRIBUTE_SEPEARATOR, typeAttributes.Select(el => el.Value)); //add type attribute source = string.Format(TsDomConstants.TS_ATTRIBUTE_COMBINE_FORMAT, typeAttributeSource, source); } //add line intendent string source = intendLineString + source; //add init statement if its set if (InitStatement != null) { AddInitStatement(ref source, info.ForType, options, info); } //add end seperator (for enum its different var endSeperator = info.ForType == TsElementTypes.Enumerations || info.ForType == TsElementTypes.Constant || info.ForType == TsElementTypes.InlineObject ? TsDomConstants.LIST_ELEMENT_SEPERATOR : TsDomConstants.EXPRESSION_END; //add end seperator source += endSeperator; //write writer.WriteLine(source); }
/// <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)); } }