diff --git a/VisualCard/Parsers/VcardConstants.cs b/VisualCard/Parsers/VcardConstants.cs index 70abed6..800b861 100644 --- a/VisualCard/Parsers/VcardConstants.cs +++ b/VisualCard/Parsers/VcardConstants.cs @@ -34,6 +34,7 @@ internal static class VcardConstants internal const char _fieldDelimiter = ';'; internal const char _valueDelimiter = ','; internal const char _argumentDelimiter = ':'; + internal const char _argumentValueDelimiter = '='; internal const string _nameSpecifier = "N"; internal const string _fullNameSpecifier = "FN"; internal const string _telephoneSpecifier = "TEL"; diff --git a/VisualCard/Parsers/VcardParserTools.cs b/VisualCard/Parsers/VcardParserTools.cs index dba02e6..995567d 100644 --- a/VisualCard/Parsers/VcardParserTools.cs +++ b/VisualCard/Parsers/VcardParserTools.cs @@ -53,11 +53,8 @@ internal static string GetTypesString(string[] args, string @default, bool isSpe // Attempt to get the value from the key Type = ArgType.Count() > 0 ? - ArgType[0].StartsWith(VcardConstants._typeArgumentSpecifier) ? - string.Join(VcardConstants._valueDelimiter.ToString(), ArgType.Select((arg) => arg.Substring(VcardConstants._typeArgumentSpecifier.Length))) : - ArgType[0] - : - @default; + string.Join(VcardConstants._valueDelimiter.ToString(), ArgType.Select((arg) => arg.StartsWith(VcardConstants._typeArgumentSpecifier) ? arg.Substring(VcardConstants._typeArgumentSpecifier.Length) : arg)) : + @default; // Return the type return Type; diff --git a/VisualCard/Parts/BaseCardPartInfo.cs b/VisualCard/Parts/BaseCardPartInfo.cs index bf1ef4f..9b30080 100644 --- a/VisualCard/Parts/BaseCardPartInfo.cs +++ b/VisualCard/Parts/BaseCardPartInfo.cs @@ -27,7 +27,7 @@ namespace VisualCard.Parts /// /// Base card part class /// - [DebuggerDisplay("Base card part | ALTID: {AltId}, TYPE: {ElementType}, VALUE: {ValueType}")] + [DebuggerDisplay("Base card part | ALTID: {AltId}, TYPE: {ElementTypes}, VALUE: {ValueType}")] public abstract class BaseCardPartInfo : IEquatable { /// diff --git a/VisualCard/Parts/Card.cs b/VisualCard/Parts/Card.cs index 2232e88..ba47a29 100644 --- a/VisualCard/Parts/Card.cs +++ b/VisualCard/Parts/Card.cs @@ -22,6 +22,7 @@ using System.Diagnostics; using System.IO; using System.Text; +using Textify.General; using VisualCard.Parsers; using VisualCard.Parts.Comparers; using VisualCard.Parts.Enums; @@ -144,7 +145,7 @@ public string SaveToString() // Now, locate the prefix and assemble the line string prefix = VcardParserTools.GetPrefixFromStringsEnum(stringEnum); - cardBuilder.AppendLine($"{prefix}:{stringValue}"); + cardBuilder.AppendLine($"{prefix}{VcardConstants._argumentDelimiter}{stringValue}"); } // Next, enumerate all the arrays @@ -156,9 +157,21 @@ public string SaveToString() if (array is null || array.Length == 0) continue; + // Get the prefix + string prefix = VcardParserTools.GetPrefixFromPartsArrayEnum(partsArrayEnum); + // Now, assemble the line foreach (var part in array) - cardBuilder.AppendLine($"{part.ToStringVcardInternal(version)}"); + { + var partBuilder = new StringBuilder(); + string partRepresentation = part.ToStringVcardInternal(version); + string partArguments = CardBuilderTools.BuildArguments(part, version); + string[] partArgumentsLines = partArguments.SplitNewLines(); + partBuilder.Append($"{prefix}"); + partBuilder.Append($"{partArguments}"); + partBuilder.Append($"{VcardParserTools.MakeStringBlock(partRepresentation, partArgumentsLines[partArgumentsLines.Length - 1].Length + prefix.Length)}"); + cardBuilder.AppendLine($"{partBuilder}"); + } } // Finally, enumerate all the parts @@ -170,8 +183,18 @@ public string SaveToString() if (part is null) continue; + // Get the prefix + string prefix = VcardParserTools.GetPrefixFromPartsEnum(partsEnum); + // Now, assemble the line - cardBuilder.AppendLine($"{part.ToStringVcardInternal(version)}"); + var partBuilder = new StringBuilder(); + string partRepresentation = part.ToStringVcardInternal(version); + string partArguments = CardBuilderTools.BuildArguments(part, version); + string[] partArgumentsLines = partArguments.SplitNewLines(); + partBuilder.Append($"{prefix}"); + partBuilder.Append($"{partArguments}"); + partBuilder.Append($"{VcardParserTools.MakeStringBlock(partRepresentation, partArgumentsLines[partArgumentsLines.Length - 1].Length + prefix.Length)}"); + cardBuilder.AppendLine($"{partBuilder}"); } // End the card and return it diff --git a/VisualCard/Parts/CardBuilderTools.cs b/VisualCard/Parts/CardBuilderTools.cs new file mode 100644 index 0000000..385c947 --- /dev/null +++ b/VisualCard/Parts/CardBuilderTools.cs @@ -0,0 +1,100 @@ +// +// VisualCard Copyright (C) 2021-2024 Aptivi +// +// This file is part of VisualCard +// +// VisualCard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// VisualCard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY, without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using VisualCard.Parsers; +using VisualCard.Parts.Implementations; + +namespace VisualCard.Parts +{ + internal static class CardBuilderTools + { + internal static string BuildArguments(BaseCardPartInfo partInfo, Version cardVersion) + { + // Check to see if we've been provided arguments + bool installAltId = partInfo.AltId >= 0 && partInfo.Arguments.Length > 0 && cardVersion.Major >= 4; + bool noSemicolon = partInfo.AltId == 0 && partInfo.Arguments.Length == 0 && partInfo.ElementTypes.Length == 0 && string.IsNullOrEmpty(partInfo.ValueType); + string xNonstandardName = partInfo is XNameInfo xName ? xName.XKeyName : ""; + if (noSemicolon) + return xNonstandardName + VcardConstants._argumentDelimiter.ToString(); + + // Now, initialize the argument builder + StringBuilder argumentsBuilder = new(xNonstandardName + VcardConstants._fieldDelimiter.ToString()); + bool installArguments = partInfo.Arguments.Length > 0; + bool installElementTypes = partInfo.ElementTypes.Length > 0; + bool installValueType = !string.IsNullOrEmpty(partInfo.ValueType); + + // First, install the AltId parameter if it exists + if (installAltId) + { + argumentsBuilder.Append(VcardConstants._altIdArgumentSpecifier + partInfo.AltId); + noSemicolon = !installArguments && !installElementTypes && !installValueType; + if (noSemicolon) + { + argumentsBuilder.Append(VcardConstants._argumentDelimiter.ToString()); + return argumentsBuilder.ToString(); + } + else + argumentsBuilder.Append(VcardConstants._fieldDelimiter.ToString()); + } + + // Then, install the element types parameter if it exists + if (installElementTypes) + { + argumentsBuilder.Append(VcardConstants._typeArgumentSpecifier + string.Join(",", partInfo.ElementTypes)); + noSemicolon = !installArguments && !installValueType; + if (noSemicolon) + { + argumentsBuilder.Append(VcardConstants._argumentDelimiter.ToString()); + return argumentsBuilder.ToString(); + } + else + argumentsBuilder.Append(VcardConstants._fieldDelimiter.ToString()); + } + + // Then, install the value type parameter if it exists + if (installValueType) + { + argumentsBuilder.Append(VcardConstants._valueArgumentSpecifier + string.Join(",", partInfo.ValueType)); + noSemicolon = !installArguments; + if (noSemicolon) + { + argumentsBuilder.Append(VcardConstants._argumentDelimiter.ToString()); + return argumentsBuilder.ToString(); + } + else + argumentsBuilder.Append(VcardConstants._fieldDelimiter.ToString()); + } + + // Finally, install the remaining arguments if they exist and contain keys and values + if (installArguments) + { + string[] finalArguments = partInfo.Arguments.Where((arg) => arg.Contains(VcardConstants._argumentValueDelimiter)).ToArray(); + argumentsBuilder.Append(string.Join(VcardConstants._fieldDelimiter.ToString(), finalArguments)); + } + + // We've reached the end. + argumentsBuilder.Append(VcardConstants._argumentDelimiter.ToString()); + return argumentsBuilder.ToString(); + } + } +} diff --git a/VisualCard/Parts/Implementations/AddressInfo.cs b/VisualCard/Parts/Implementations/AddressInfo.cs index d684c0f..7219b6e 100644 --- a/VisualCard/Parts/Implementations/AddressInfo.cs +++ b/VisualCard/Parts/Implementations/AddressInfo.cs @@ -64,38 +64,14 @@ public class AddressInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new AddressInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - return - $"{VcardConstants._addressSpecifier};" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" + - $"{PostOfficeBox}{VcardConstants._fieldDelimiter}" + - $"{ExtendedAddress}{VcardConstants._fieldDelimiter}" + - $"{StreetAddress}{VcardConstants._fieldDelimiter}" + - $"{Locality}{VcardConstants._fieldDelimiter}" + - $"{Region}{VcardConstants._fieldDelimiter}" + - $"{PostalCode}{VcardConstants._fieldDelimiter}" + - $"{Country}"; - } - else - { - return - $"{VcardConstants._addressSpecifier};" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" + - $"{PostOfficeBox}{VcardConstants._fieldDelimiter}" + - $"{ExtendedAddress}{VcardConstants._fieldDelimiter}" + - $"{StreetAddress}{VcardConstants._fieldDelimiter}" + - $"{Locality}{VcardConstants._fieldDelimiter}" + - $"{Region}{VcardConstants._fieldDelimiter}" + - $"{PostalCode}{VcardConstants._fieldDelimiter}" + - $"{Country}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + $"{PostOfficeBox}{VcardConstants._fieldDelimiter}" + + $"{ExtendedAddress}{VcardConstants._fieldDelimiter}" + + $"{StreetAddress}{VcardConstants._fieldDelimiter}" + + $"{Locality}{VcardConstants._fieldDelimiter}" + + $"{Region}{VcardConstants._fieldDelimiter}" + + $"{PostalCode}{VcardConstants._fieldDelimiter}" + + $"{Country}"; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/AgentInfo.cs b/VisualCard/Parts/Implementations/AgentInfo.cs index be63aff..9c60987 100644 --- a/VisualCard/Parts/Implementations/AgentInfo.cs +++ b/VisualCard/Parts/Implementations/AgentInfo.cs @@ -45,27 +45,12 @@ internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] fi internal override string ToStringVcardInternal(Version cardVersion) { var agents = new StringBuilder(); - bool altIdSupported = cardVersion.Major >= 4; foreach (var a in AgentCards) { - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - agents.Append( - $"{VcardConstants._agentSpecifier}" + - $"{(installAltId ? $"{VcardConstants._fieldDelimiter}{VcardConstants._altIdArgumentSpecifier}" + AltId : "")}" + - $"{VcardConstants._argumentDelimiter}" + - $"{string.Join("\\n", a.SaveToString().SplitNewLines())}" - ); - } - else - { - agents.Append( - $"{VcardConstants._agentSpecifier}{VcardConstants._argumentDelimiter}" + - $"{string.Join("\\n", a.SaveToString().SplitNewLines())}" - ); - } + agents.Append( + $"{string.Join("\\n", a.SaveToString().SplitNewLines())}" + ); } return agents.ToString(); } diff --git a/VisualCard/Parts/Implementations/AnniversaryInfo.cs b/VisualCard/Parts/Implementations/AnniversaryInfo.cs index 19fc35f..ceeb424 100644 --- a/VisualCard/Parts/Implementations/AnniversaryInfo.cs +++ b/VisualCard/Parts/Implementations/AnniversaryInfo.cs @@ -39,7 +39,7 @@ internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] fi new AnniversaryInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); internal override string ToStringVcardInternal(Version cardVersion) => - $"{VcardConstants._anniversarySpecifier}:{Anniversary:yyyyMMdd}"; + $"{Anniversary:yyyyMMdd}"; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/BirthDateInfo.cs b/VisualCard/Parts/Implementations/BirthDateInfo.cs index 1292c43..1409494 100644 --- a/VisualCard/Parts/Implementations/BirthDateInfo.cs +++ b/VisualCard/Parts/Implementations/BirthDateInfo.cs @@ -39,7 +39,7 @@ internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] fi new BirthDateInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); internal override string ToStringVcardInternal(Version cardVersion) => - $"{VcardConstants._birthSpecifier}:{BirthDate:yyyyMMdd}"; + $"{BirthDate:yyyyMMdd}"; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/CategoryInfo.cs b/VisualCard/Parts/Implementations/CategoryInfo.cs index 352f392..73e2111 100644 --- a/VisualCard/Parts/Implementations/CategoryInfo.cs +++ b/VisualCard/Parts/Implementations/CategoryInfo.cs @@ -39,12 +39,8 @@ public class CategoryInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new CategoryInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - return - $"{VcardConstants._categoriesSpecifier}:" + - $"{Category}"; - } + internal override string ToStringVcardInternal(Version cardVersion) => + $"{string.Join(VcardConstants._valueDelimiter.ToString(), Category)}"; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/EmailInfo.cs b/VisualCard/Parts/Implementations/EmailInfo.cs index 39e4d15..de6c089 100644 --- a/VisualCard/Parts/Implementations/EmailInfo.cs +++ b/VisualCard/Parts/Implementations/EmailInfo.cs @@ -40,26 +40,8 @@ public class EmailInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new EmailInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - return - $"{VcardConstants._emailSpecifier};" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" + - $"{ContactEmailAddress}"; - } - else - { - return - $"{VcardConstants._emailSpecifier};" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" + - $"{ContactEmailAddress}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + ContactEmailAddress; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/GenderInfo.cs b/VisualCard/Parts/Implementations/GenderInfo.cs index b4212da..b1ca3c9 100644 --- a/VisualCard/Parts/Implementations/GenderInfo.cs +++ b/VisualCard/Parts/Implementations/GenderInfo.cs @@ -46,7 +46,6 @@ internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] fi new GenderInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); internal override string ToStringVcardInternal(Version cardVersion) => - $"{VcardConstants._genderSpecifier}{VcardConstants._argumentDelimiter}" + (Gender != Gender.Unspecified ? Gender.ToString()[0] : "") + (!string.IsNullOrEmpty(GenderDescription) ? $"{VcardConstants._fieldDelimiter}{GenderDescription}" : ""); diff --git a/VisualCard/Parts/Implementations/GeoInfo.cs b/VisualCard/Parts/Implementations/GeoInfo.cs index a695fb4..022e308 100644 --- a/VisualCard/Parts/Implementations/GeoInfo.cs +++ b/VisualCard/Parts/Implementations/GeoInfo.cs @@ -39,25 +39,8 @@ public class GeoInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new GeoInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - return - $"{VcardConstants._geoSpecifier}{(installAltId ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(installAltId ? string.Join(VcardConstants._fieldDelimiter.ToString(), Arguments) + VcardConstants._argumentDelimiter : "")}" + - $"{Geo}"; - } - else - { - return - $"{VcardConstants._geoSpecifier}:" + - $"{Geo}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + Geo; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/ImppInfo.cs b/VisualCard/Parts/Implementations/ImppInfo.cs index 63cbacf..5e682ce 100644 --- a/VisualCard/Parts/Implementations/ImppInfo.cs +++ b/VisualCard/Parts/Implementations/ImppInfo.cs @@ -39,28 +39,8 @@ public class ImppInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new ImppInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - bool installType = ElementTypes.Length > 0 && ElementTypes[0].ToUpper() != "HOME"; - return - $"{VcardConstants._imppSpecifier}{(installType || installAltId ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + (installType ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter) : "")}" + - $"{(installType ? $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" : "")}" + - $"{ContactIMPP}"; - } - else - { - bool installType = ElementTypes.Length > 0 && ElementTypes[0].ToUpper() != "HOME"; - return - $"{VcardConstants._imppSpecifier}{(installType ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + - $"{(installType ? $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" : "")}" + - $"{ContactIMPP}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + ContactIMPP; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/LabelAddressInfo.cs b/VisualCard/Parts/Implementations/LabelAddressInfo.cs index 90c1435..1a4bc7e 100644 --- a/VisualCard/Parts/Implementations/LabelAddressInfo.cs +++ b/VisualCard/Parts/Implementations/LabelAddressInfo.cs @@ -39,26 +39,8 @@ public class LabelAddressInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new LabelAddressInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - return - $"{VcardConstants._labelSpecifier};" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" + - $"{DeliveryLabel}"; - } - else - { - return - $"{VcardConstants._labelSpecifier};" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" + - $"{DeliveryLabel}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + DeliveryLabel; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/LangInfo.cs b/VisualCard/Parts/Implementations/LangInfo.cs index d0b6b8f..514f694 100644 --- a/VisualCard/Parts/Implementations/LangInfo.cs +++ b/VisualCard/Parts/Implementations/LangInfo.cs @@ -42,28 +42,8 @@ public class LangInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new LangInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - return - $"{VcardConstants._langSpecifier};" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._prefArgumentSpecifier}{ContactLangPreference}{VcardConstants._argumentDelimiter}" + - $"{ContactLang}"; - } - else - { - return - $"{VcardConstants._langSpecifier};" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._prefArgumentSpecifier}{ContactLangPreference}{VcardConstants._argumentDelimiter}" + - $"{ContactLang}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + ContactLang; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/LogoInfo.cs b/VisualCard/Parts/Implementations/LogoInfo.cs index 01aa6d8..765e337 100644 --- a/VisualCard/Parts/Implementations/LogoInfo.cs +++ b/VisualCard/Parts/Implementations/LogoInfo.cs @@ -42,53 +42,8 @@ public class LogoInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new LogoInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - if (ValueType == "uri" || ValueType == "url") - { - return - $"{VcardConstants._logoSpecifier};" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(installAltId ? string.Join(VcardConstants._fieldDelimiter.ToString(), Arguments) + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._valueArgumentSpecifier}{ValueType}{VcardConstants._argumentDelimiter}" + - $"{LogoEncoded}"; - } - else - { - string logoArgsLine = - $"{VcardConstants._logoSpecifier};" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(installAltId ? string.Join(VcardConstants._fieldDelimiter.ToString(), Arguments) + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._valueArgumentSpecifier}{ValueType}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._encodingArgumentSpecifier}{Encoding}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(VcardConstants._valueDelimiter.ToString(), ElementTypes)}{VcardConstants._argumentDelimiter}"; - return logoArgsLine + VcardParserTools.MakeStringBlock(LogoEncoded, logoArgsLine.Length); - } - } - else - { - if (ValueType == "uri" || ValueType == "url") - { - return - $"{VcardConstants._logoSpecifier};" + - $"{VcardConstants._valueArgumentSpecifier}{ValueType}{VcardConstants._argumentDelimiter}" + - $"{LogoEncoded}"; - } - else - { - string logoArgsLine = - $"{VcardConstants._logoSpecifier};" + - $"{VcardConstants._valueArgumentSpecifier}{ValueType}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._encodingArgumentSpecifier}{Encoding}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(VcardConstants._valueDelimiter.ToString(), ElementTypes)}{VcardConstants._argumentDelimiter}"; - return logoArgsLine + VcardParserTools.MakeStringBlock(LogoEncoded, logoArgsLine.Length); - } - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + LogoEncoded; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/NameInfo.cs b/VisualCard/Parts/Implementations/NameInfo.cs index 5d14089..f2fe233 100644 --- a/VisualCard/Parts/Implementations/NameInfo.cs +++ b/VisualCard/Parts/Implementations/NameInfo.cs @@ -59,36 +59,15 @@ internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] fi internal override string ToStringVcardInternal(Version cardVersion) { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - string altNamesStr = string.Join(VcardConstants._valueDelimiter.ToString(), AltNames); - string prefixesStr = string.Join(VcardConstants._valueDelimiter.ToString(), Prefixes); - string suffixesStr = string.Join(VcardConstants._valueDelimiter.ToString(), Suffixes); - return - $"{VcardConstants._nameSpecifier}{(installAltId ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(installAltId ? string.Join(VcardConstants._fieldDelimiter.ToString(), Arguments) + VcardConstants._argumentDelimiter : "")}" + - $"{ContactLastName}{VcardConstants._fieldDelimiter}" + - $"{ContactFirstName}{VcardConstants._fieldDelimiter}" + - $"{altNamesStr}{VcardConstants._fieldDelimiter}" + - $"{prefixesStr}{VcardConstants._fieldDelimiter}" + - $"{suffixesStr}"; - } - else - { - string altNamesStr = string.Join(VcardConstants._valueDelimiter.ToString(), AltNames); - string prefixesStr = string.Join(VcardConstants._valueDelimiter.ToString(), Prefixes); - string suffixesStr = string.Join(VcardConstants._valueDelimiter.ToString(), Suffixes); - return - $"{VcardConstants._nameSpecifier}:" + - $"{ContactLastName}{VcardConstants._fieldDelimiter}" + - $"{ContactFirstName}{VcardConstants._fieldDelimiter}" + - $"{altNamesStr}{VcardConstants._fieldDelimiter}" + - $"{prefixesStr}{VcardConstants._fieldDelimiter}" + - $"{suffixesStr}"; - } + string altNamesStr = string.Join(VcardConstants._valueDelimiter.ToString(), AltNames); + string prefixesStr = string.Join(VcardConstants._valueDelimiter.ToString(), Prefixes); + string suffixesStr = string.Join(VcardConstants._valueDelimiter.ToString(), Suffixes); + return + $"{ContactLastName}{VcardConstants._fieldDelimiter}" + + $"{ContactFirstName}{VcardConstants._fieldDelimiter}" + + $"{altNamesStr}{VcardConstants._fieldDelimiter}" + + $"{prefixesStr}{VcardConstants._fieldDelimiter}" + + $"{suffixesStr}"; } internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) diff --git a/VisualCard/Parts/Implementations/NicknameInfo.cs b/VisualCard/Parts/Implementations/NicknameInfo.cs index 94d241a..8c9b07a 100644 --- a/VisualCard/Parts/Implementations/NicknameInfo.cs +++ b/VisualCard/Parts/Implementations/NicknameInfo.cs @@ -39,27 +39,8 @@ public class NicknameInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new NicknameInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - return - $"{VcardConstants._nicknameSpecifier};" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(installAltId ? string.Join(VcardConstants._fieldDelimiter.ToString(), Arguments) + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" + - $"{ContactNickname}"; - } - else - { - return - $"{VcardConstants._nicknameSpecifier};" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" + - $"{ContactNickname}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + ContactNickname; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/OrganizationInfo.cs b/VisualCard/Parts/Implementations/OrganizationInfo.cs index ffce405..05f2a60 100644 --- a/VisualCard/Parts/Implementations/OrganizationInfo.cs +++ b/VisualCard/Parts/Implementations/OrganizationInfo.cs @@ -47,32 +47,10 @@ public class OrganizationInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new OrganizationInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - bool installType = (installAltId || ElementTypes.Length > 0) && ElementTypes[0].ToUpper() != "WORK"; - return - $"{VcardConstants._orgSpecifier}{(installType || installAltId ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + (installType ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter) : "")}" + - $"{(installType ? $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" : "")}" + - $"{Name}{VcardConstants._fieldDelimiter}" + - $"{Unit}{VcardConstants._fieldDelimiter}" + - $"{Role}"; - } - else - { - bool installType = ElementTypes.Length > 0 && ElementTypes[0].ToUpper() != "WORK"; - return - $"{VcardConstants._orgSpecifier}{(installType ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + - $"{(installType ? $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" : "")}" + - $"{Name}{VcardConstants._fieldDelimiter}" + - $"{Unit}{VcardConstants._fieldDelimiter}" + - $"{Role}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + $"{Name}{VcardConstants._fieldDelimiter}" + + $"{Unit}{VcardConstants._fieldDelimiter}" + + $"{Role}"; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/PhotoInfo.cs b/VisualCard/Parts/Implementations/PhotoInfo.cs index f58531f..ca0b92f 100644 --- a/VisualCard/Parts/Implementations/PhotoInfo.cs +++ b/VisualCard/Parts/Implementations/PhotoInfo.cs @@ -42,53 +42,8 @@ public class PhotoInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new PhotoInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - if (ValueType == "uri" || ValueType == "url") - { - return - $"{VcardConstants._photoSpecifier};" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(installAltId ? string.Join(VcardConstants._fieldDelimiter.ToString(), Arguments) + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._valueArgumentSpecifier}{ValueType}{VcardConstants._argumentDelimiter}" + - $"{PhotoEncoded}"; - } - else - { - string photoArgsLine = - $"{VcardConstants._photoSpecifier};" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(installAltId ? string.Join(VcardConstants._fieldDelimiter.ToString(), Arguments) + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._valueArgumentSpecifier}{ValueType}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._encodingArgumentSpecifier}{Encoding}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(VcardConstants._valueDelimiter.ToString(), ElementTypes)}{VcardConstants._argumentDelimiter}"; - return photoArgsLine + VcardParserTools.MakeStringBlock(PhotoEncoded, photoArgsLine.Length); - } - } - else - { - if (ValueType == "uri" || ValueType == "url") - { - return - $"{VcardConstants._photoSpecifier};" + - $"{VcardConstants._valueArgumentSpecifier}{ValueType}{VcardConstants._argumentDelimiter}" + - $"{PhotoEncoded}"; - } - else - { - string photoArgsLine = - $"{VcardConstants._photoSpecifier};" + - $"{VcardConstants._valueArgumentSpecifier}{ValueType}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._encodingArgumentSpecifier}{Encoding}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(VcardConstants._valueDelimiter.ToString(), ElementTypes)}{VcardConstants._argumentDelimiter}"; - return photoArgsLine + VcardParserTools.MakeStringBlock(PhotoEncoded, photoArgsLine.Length); - } - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + PhotoEncoded; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/RevisionInfo.cs b/VisualCard/Parts/Implementations/RevisionInfo.cs index 90e87e3..cdcbadd 100644 --- a/VisualCard/Parts/Implementations/RevisionInfo.cs +++ b/VisualCard/Parts/Implementations/RevisionInfo.cs @@ -38,7 +38,7 @@ internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] fi new RevisionInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); internal override string ToStringVcardInternal(Version cardVersion) => - $"{VcardConstants._revSpecifier}:{Revision:yyyy-MM-dd HH:mm:ss}"; + $"{Revision:yyyy-MM-dd HH:mm:ss}"; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/RoleInfo.cs b/VisualCard/Parts/Implementations/RoleInfo.cs index 3f4abf4..fddeeda 100644 --- a/VisualCard/Parts/Implementations/RoleInfo.cs +++ b/VisualCard/Parts/Implementations/RoleInfo.cs @@ -39,25 +39,8 @@ public class RoleInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new RoleInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - return - $"{VcardConstants._roleSpecifier}{(installAltId ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(installAltId ? string.Join(VcardConstants._fieldDelimiter.ToString(), Arguments) + VcardConstants._argumentDelimiter : "")}" + - $"{ContactRole}"; - } - else - { - return - $"{VcardConstants._roleSpecifier};" + - $"{ContactRole}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + ContactRole; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/SoundInfo.cs b/VisualCard/Parts/Implementations/SoundInfo.cs index b4fab8d..60eba3d 100644 --- a/VisualCard/Parts/Implementations/SoundInfo.cs +++ b/VisualCard/Parts/Implementations/SoundInfo.cs @@ -42,53 +42,8 @@ public class SoundInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new SoundInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - if (ValueType == "uri" || ValueType == "url") - { - return - $"{VcardConstants._soundSpecifier};" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(installAltId ? string.Join(VcardConstants._fieldDelimiter.ToString(), Arguments) + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._valueArgumentSpecifier}{ValueType}{VcardConstants._argumentDelimiter}" + - $"{SoundEncoded}"; - } - else - { - string soundArgsLine = - $"{VcardConstants._soundSpecifier};" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(installAltId ? string.Join(VcardConstants._fieldDelimiter.ToString(), Arguments) + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._valueArgumentSpecifier}{ValueType}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._encodingArgumentSpecifier}{Encoding}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(VcardConstants._valueDelimiter.ToString(), ElementTypes)}{VcardConstants._argumentDelimiter}"; - return soundArgsLine + VcardParserTools.MakeStringBlock(SoundEncoded, soundArgsLine.Length); - } - } - else - { - if (ValueType == "uri" || ValueType == "url") - { - return - $"{VcardConstants._soundSpecifier};" + - $"{VcardConstants._valueArgumentSpecifier}{ValueType}{VcardConstants._argumentDelimiter}" + - $"{SoundEncoded}"; - } - else - { - string soundArgsLine = - $"{VcardConstants._soundSpecifier};" + - $"{VcardConstants._valueArgumentSpecifier}{ValueType}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._encodingArgumentSpecifier}{Encoding}{VcardConstants._fieldDelimiter}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(VcardConstants._valueDelimiter.ToString(), ElementTypes)}{VcardConstants._argumentDelimiter}"; - return soundArgsLine + VcardParserTools.MakeStringBlock(SoundEncoded, soundArgsLine.Length); - } - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + SoundEncoded; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/TelephoneInfo.cs b/VisualCard/Parts/Implementations/TelephoneInfo.cs index 8103e31..d9ddd98 100644 --- a/VisualCard/Parts/Implementations/TelephoneInfo.cs +++ b/VisualCard/Parts/Implementations/TelephoneInfo.cs @@ -39,26 +39,8 @@ public class TelephoneInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new TelephoneInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - return - $"{VcardConstants._telephoneSpecifier};" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" + - $"{ContactPhoneNumber}"; - } - else - { - return - $"{VcardConstants._telephoneSpecifier};" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" + - $"{ContactPhoneNumber}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + ContactPhoneNumber; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/TimeDateZoneInfo.cs b/VisualCard/Parts/Implementations/TimeDateZoneInfo.cs index 8b91940..cb9fb83 100644 --- a/VisualCard/Parts/Implementations/TimeDateZoneInfo.cs +++ b/VisualCard/Parts/Implementations/TimeDateZoneInfo.cs @@ -39,25 +39,8 @@ public class TimeDateZoneInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new TimeDateZoneInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - return - $"{VcardConstants._timeZoneSpecifier}{(installAltId ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(installAltId ? string.Join(VcardConstants._fieldDelimiter.ToString(), Arguments) + VcardConstants._argumentDelimiter : "")}" + - $"{TimeZone}"; - } - else - { - return - $"{VcardConstants._timeZoneSpecifier}:" + - $"{TimeZone}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + TimeZone; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/TitleInfo.cs b/VisualCard/Parts/Implementations/TitleInfo.cs index cb85cf4..dd2e5ce 100644 --- a/VisualCard/Parts/Implementations/TitleInfo.cs +++ b/VisualCard/Parts/Implementations/TitleInfo.cs @@ -39,25 +39,8 @@ public class TitleInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new TitleInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - return - $"{(installAltId ? $"{VcardConstants._titleSpecifier};" : $"{VcardConstants._titleSpecifier}:")}" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(installAltId ? string.Join(VcardConstants._fieldDelimiter.ToString(), Arguments) + VcardConstants._argumentDelimiter : "")}" + - $"{ContactTitle}"; - } - else - { - return - $"{VcardConstants._titleSpecifier}:" + - $"{ContactTitle}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + ContactTitle; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/XNameInfo.cs b/VisualCard/Parts/Implementations/XNameInfo.cs index fc9d82d..36be2a7 100644 --- a/VisualCard/Parts/Implementations/XNameInfo.cs +++ b/VisualCard/Parts/Implementations/XNameInfo.cs @@ -43,29 +43,8 @@ public class XNameInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new XNameInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - if (altIdSupported) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - bool installType = installAltId && ElementTypes.Length > 0; - return - $"{VcardConstants._xSpecifier}" + - $"{XKeyName}{(installType ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + - $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{(ElementTypes.Length > 0 ? VcardConstants._typeArgumentSpecifier + string.Join(VcardConstants._valueDelimiter.ToString(), ElementTypes) + VcardConstants._argumentDelimiter : "")}" + - $"{string.Join(VcardConstants._fieldDelimiter.ToString(), XValues)}"; - } - else - { - return - $"{VcardConstants._xSpecifier}" + - $"{XKeyName}{(ElementTypes.Length > 0 ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + - $"{(ElementTypes.Length > 0 ? VcardConstants._typeArgumentSpecifier + string.Join(VcardConstants._valueDelimiter.ToString(), ElementTypes) + VcardConstants._argumentDelimiter : "")}" + - $"{string.Join(VcardConstants._fieldDelimiter.ToString(), XValues)}"; - } - } + internal override string ToStringVcardInternal(Version cardVersion) => + string.Join(VcardConstants._fieldDelimiter.ToString(), XValues); internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { diff --git a/VisualCard/Parts/Implementations/XmlInfo.cs b/VisualCard/Parts/Implementations/XmlInfo.cs index 8413afb..953f050 100644 --- a/VisualCard/Parts/Implementations/XmlInfo.cs +++ b/VisualCard/Parts/Implementations/XmlInfo.cs @@ -44,14 +44,8 @@ public class XmlInfo : BaseCardPartInfo, IEquatable internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => new XmlInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); - internal override string ToStringVcardInternal(Version cardVersion) - { - bool installAltId = AltId >= 0 && Arguments.Length > 0; - return - $"{VcardConstants._xmlSpecifier}" + - $"{(installAltId ? VcardConstants._fieldDelimiter + VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._argumentDelimiter : VcardConstants._argumentDelimiter)}" + - $"{XmlString}"; - } + internal override string ToStringVcardInternal(Version cardVersion) => + XmlString; internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) {