diff --git a/VisualCard/Parts/BaseCardPartInfo.cs b/VisualCard/Parts/BaseCardPartInfo.cs index ac7143d..4128977 100644 --- a/VisualCard/Parts/BaseCardPartInfo.cs +++ b/VisualCard/Parts/BaseCardPartInfo.cs @@ -27,19 +27,29 @@ namespace VisualCard.Parts /// /// Base card part class /// - [DebuggerDisplay("Base card part = ALTID: {AltId}")] + [DebuggerDisplay("Base card part | ALTID: {AltId}, TYPE: {ElementType}, VALUE: {ValueType}")] public abstract class BaseCardPartInfo : IEquatable { /// - /// Arguments that follow the AltId + /// Final arguments /// - public virtual string[] AltArguments { get; internal set; } + public virtual string[] Arguments { get; internal set; } /// /// Alternative ID. Zero if unspecified. /// public virtual int AltId { get; internal set; } + /// + /// Card element type (home, work, ...) + /// + public virtual string[] ElementTypes { get; internal set; } + + /// + /// Value type (usually set by VALUE=) + /// + public virtual string ValueType { get; internal set; } + /// /// Checks to see if both the parts are equal /// @@ -62,8 +72,10 @@ public bool Equals(BaseCardPartInfo source, BaseCardPartInfo target) // Check all the properties return - source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId + source.Arguments.SequenceEqual(target.Arguments) && + source.AltId == target.AltId && + source.ElementTypes == target.ElementTypes && + source.ValueType == target.ValueType ; } @@ -74,9 +86,11 @@ public override bool Equals(object obj) => /// public override int GetHashCode() { - int hashCode = -2100286935; - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(AltArguments); + int hashCode = 936749766; + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Arguments); hashCode = hashCode * -1521134295 + AltId.GetHashCode(); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(ElementTypes); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(ValueType); return hashCode; } @@ -88,9 +102,7 @@ public override int GetHashCode() public static bool operator !=(BaseCardPartInfo left, BaseCardPartInfo right) => !(left == right); - internal abstract BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion); - - internal abstract BaseCardPartInfo FromStringVcardWithTypeInternal(string value, string[] finalArgs, int altId, Version cardVersion); + internal abstract BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion); internal abstract string ToStringVcardInternal(Version cardVersion); } diff --git a/VisualCard/Parts/Implementations/AddressInfo.cs b/VisualCard/Parts/Implementations/AddressInfo.cs index 07ce452..8083aa1 100644 --- a/VisualCard/Parts/Implementations/AddressInfo.cs +++ b/VisualCard/Parts/Implementations/AddressInfo.cs @@ -21,7 +21,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.Linq; using System.Text.RegularExpressions; using VisualCard.Parsers; @@ -33,10 +32,6 @@ namespace VisualCard.Parts.Implementations [DebuggerDisplay("Address = {PostOfficeBox}, {ExtendedAddress}, {StreetAddress}, {Locality}, {Region}, {PostalCode}, {Country}")] public class AddressInfo : BaseCardPartInfo, IEquatable { - /// - /// The contact's address types - /// - public string[] AddressTypes { get; } /// /// The contact's post office box /// @@ -66,22 +61,19 @@ public class AddressInfo : BaseCardPartInfo, IEquatable /// public string Country { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new AddressInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new AddressInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; return $"{VcardConstants._addressSpecifier};" + $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", AddressTypes)}{VcardConstants._argumentDelimiter}" + + $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" + $"{PostOfficeBox}{VcardConstants._fieldDelimiter}" + $"{ExtendedAddress}{VcardConstants._fieldDelimiter}" + $"{StreetAddress}{VcardConstants._fieldDelimiter}" + @@ -94,7 +86,7 @@ internal override string ToStringVcardInternal(Version cardVersion) { return $"{VcardConstants._addressSpecifier};" + - $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", AddressTypes)}{VcardConstants._argumentDelimiter}" + + $"{VcardConstants._typeArgumentSpecifier}{string.Join(",", ElementTypes)}{VcardConstants._argumentDelimiter}" + $"{PostOfficeBox}{VcardConstants._fieldDelimiter}" + $"{ExtendedAddress}{VcardConstants._fieldDelimiter}" + $"{StreetAddress}{VcardConstants._fieldDelimiter}" + @@ -105,56 +97,27 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { - // Get the value - string adrValue = value.Substring(VcardConstants._addressSpecifier.Length + 1); - string[] splitAdr = adrValue.Split(VcardConstants._argumentDelimiter); - - // Check the provided address - string[] splitAddressValues = splitAdr[0].Split(VcardConstants._fieldDelimiter); - if (splitAddressValues.Length < 7) - throw new InvalidDataException("Address information must specify exactly seven values (P.O. Box, extended address, street address, locality, region, postal code, and country)"); - - // Populate the fields - return InstallInfo([], splitAddressValues, altId, cardVersion); - } + bool altIdSupported = cardVersion.Major >= 4; - internal override BaseCardPartInfo FromStringVcardWithTypeInternal(string value, string[] finalArgs, int altId, Version cardVersion) - { // Get the value - string adrValue = value.Substring(VcardConstants._addressSpecifier.Length + 1); - string[] splitAdr = adrValue.Split(VcardConstants._argumentDelimiter); - if (splitAdr.Length < 2) - throw new InvalidDataException("Address field must specify exactly two values (Type (optionally prepended with TYPE=), and address information)"); + string[] splitAdr = value.Split(VcardConstants._argumentDelimiter); // Check the provided address - string[] splitAddressValues = splitAdr[1].Split(VcardConstants._fieldDelimiter); - if (splitAddressValues.Length < 7) + if (splitAdr.Length < 7) throw new InvalidDataException("Address information must specify exactly seven values (P.O. Box, extended address, street address, locality, region, postal code, and country)"); // Populate the fields - return InstallInfo(splitAdr, splitAddressValues, finalArgs, altId, cardVersion); - } - - private AddressInfo InstallInfo(string[] splitAdr, string[] splitAddressValues, int altId, Version cardVersion) => - InstallInfo(splitAdr, splitAddressValues, [], altId, cardVersion); - - private AddressInfo InstallInfo(string[] splitAdr, string[] splitAddressValues, string[] finalArgs, int altId, Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - bool specifierRequired = cardVersion.Major >= 3; - - // Populate the fields - string[] _addressTypes = splitAdr.Length == 0 ? ["HOME"] : VcardParserTools.GetTypes(splitAdr, "HOME", specifierRequired); - string _addressPOBox = Regex.Unescape(splitAddressValues[0]); - string _addressExtended = Regex.Unescape(splitAddressValues[1]); - string _addressStreet = Regex.Unescape(splitAddressValues[2]); - string _addressLocality = Regex.Unescape(splitAddressValues[3]); - string _addressRegion = Regex.Unescape(splitAddressValues[4]); - string _addressPostalCode = Regex.Unescape(splitAddressValues[5]); - string _addressCountry = Regex.Unescape(splitAddressValues[6]); - AddressInfo _address = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _addressTypes, _addressPOBox, _addressExtended, _addressStreet, _addressLocality, _addressRegion, _addressPostalCode, _addressCountry); + string[] _addressTypes = elementTypes.Length >= 0 ? elementTypes : ["HOME"]; + string _addressPOBox = Regex.Unescape(splitAdr[0]); + string _addressExtended = Regex.Unescape(splitAdr[1]); + string _addressStreet = Regex.Unescape(splitAdr[2]); + string _addressLocality = Regex.Unescape(splitAdr[3]); + string _addressRegion = Regex.Unescape(splitAdr[4]); + string _addressPostalCode = Regex.Unescape(splitAdr[5]); + string _addressCountry = Regex.Unescape(splitAdr[6]); + AddressInfo _address = new(altIdSupported ? altId : 0, finalArgs, _addressTypes, valueType, _addressPOBox, _addressExtended, _addressStreet, _addressLocality, _addressRegion, _addressPostalCode, _addressCountry); return _address; } @@ -184,9 +147,7 @@ public bool Equals(AddressInfo source, AddressInfo target) // Check all the properties return - source.AddressTypes.SequenceEqual(target.AddressTypes) && - source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.PostOfficeBox == target.PostOfficeBox && source.ExtendedAddress == target.ExtendedAddress && source.StreetAddress == target.StreetAddress && @@ -200,10 +161,8 @@ public bool Equals(AddressInfo source, AddressInfo target) /// public override int GetHashCode() { - int hashCode = -1858114484; - hashCode = hashCode * -1521134295 + AltId.GetHashCode(); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(AltArguments); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(AddressTypes); + int hashCode = -427937047; + hashCode = hashCode * -1521134295 + base.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(PostOfficeBox); hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(ExtendedAddress); hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(StreetAddress); @@ -224,11 +183,12 @@ public override int GetHashCode() internal AddressInfo() { } - internal AddressInfo(int altId, string[] altArguments, string[] addressTypes, string postOfficeBox, string extendedAddress, string streetAddress, string locality, string region, string postalCode, string country) + internal AddressInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string postOfficeBox, string extendedAddress, string streetAddress, string locality, string region, string postalCode, string country) { AltId = altId; - AltArguments = altArguments; - AddressTypes = addressTypes; + Arguments = arguments; + ElementTypes = elementTypes; + ValueType = valueType; PostOfficeBox = postOfficeBox; ExtendedAddress = extendedAddress; StreetAddress = streetAddress; diff --git a/VisualCard/Parts/Implementations/AgentInfo.cs b/VisualCard/Parts/Implementations/AgentInfo.cs index f0c02ef..22692f8 100644 --- a/VisualCard/Parts/Implementations/AgentInfo.cs +++ b/VisualCard/Parts/Implementations/AgentInfo.cs @@ -40,11 +40,8 @@ public class AgentInfo : BaseCardPartInfo, IEquatable /// public Card[] AgentCards { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new AgentInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new AgentInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => + new AgentInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); internal override string ToStringVcardInternal(Version cardVersion) { @@ -55,7 +52,7 @@ internal override string ToStringVcardInternal(Version cardVersion) { if (altIdSupported) { - bool installAltId = AltId >= 0 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; agents.Append( $"{VcardConstants._agentSpecifier}" + $"{(installAltId ? $"{VcardConstants._fieldDelimiter}{VcardConstants._altIdArgumentSpecifier}" + AltId : "")}" + @@ -74,49 +71,18 @@ internal override string ToStringVcardInternal(Version cardVersion) return agents.ToString(); } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) - { - // Get the value - string agentValue = value.Substring(VcardConstants._agentSpecifier.Length + 1); - string[] splitAgent = agentValue.Split(VcardConstants._argumentDelimiter); - - // Check the provided agent - string[] splitAgentValues = splitAgent[0].Split(VcardConstants._fieldDelimiter); - if (splitAgentValues.Length < 1) - throw new InvalidDataException("Agent information must specify exactly one value (agent vCard contents that have their lines delimited by \\n)"); - - // Populate the fields - return InstallInfo(agentValue, altId, cardVersion); - } - - internal override BaseCardPartInfo FromStringVcardWithTypeInternal(string value, string[] finalArgs, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { - // Get the value - string agentValue = value.Substring(VcardConstants._agentSpecifier.Length + 1); - string[] splitAgent = agentValue.Split(VcardConstants._argumentDelimiter); - if (splitAgent.Length < 2) - throw new InvalidDataException("Agent field must specify exactly two values (Type (optionally prepended with TYPE=), and agent information)"); + bool altIdSupported = cardVersion.Major >= 4; // Check the provided agent - string[] splitAgentValues = splitAgent[1].Split(VcardConstants._fieldDelimiter); - if (splitAgentValues.Length < 1) + if (string.IsNullOrEmpty(value)) throw new InvalidDataException("Agent information must specify exactly one value (agent vCard contents that have their lines delimited by \\n)"); - // Populate the fields - return InstallInfo(agentValue, finalArgs, altId, cardVersion); - } - - private AgentInfo InstallInfo(string value, int altId, Version cardVersion) => - InstallInfo(value, [], altId, cardVersion); - - private AgentInfo InstallInfo(string value, string[] finalArgs, int altId, Version cardVersion) - { - bool altIdSupported = cardVersion.Major >= 4; - // Populate the fields string _agentVcard = Regex.Unescape(value).Replace("\\n", "\n"); var _agentVcardParsers = CardTools.GetCardsFromString(_agentVcard); - AgentInfo _agent = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _agentVcardParsers); + AgentInfo _agent = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _agentVcardParsers); return _agent; } @@ -146,8 +112,7 @@ public bool Equals(AgentInfo source, AgentInfo target) // Check all the properties return - source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.AgentCards == target.AgentCards ; } @@ -155,9 +120,8 @@ public bool Equals(AgentInfo source, AgentInfo target) /// public override int GetHashCode() { - int hashCode = -1716393954; - hashCode = hashCode * -1521134295 + AltId.GetHashCode(); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(AltArguments); + int hashCode = -582546693; + hashCode = hashCode * -1521134295 + base.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(AgentCards); return hashCode; } @@ -172,10 +136,12 @@ public override int GetHashCode() internal AgentInfo() { } - internal AgentInfo(int altId, string[] altArguments, Card[] agentCard) + internal AgentInfo(int altId, string[] arguments, string[] elementTypes, string valueType, Card[] agentCard) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; + ElementTypes = elementTypes; + ValueType = valueType; AgentCards = agentCard; } } diff --git a/VisualCard/Parts/Implementations/AnniversaryInfo.cs b/VisualCard/Parts/Implementations/AnniversaryInfo.cs index 1791eed..7a96514 100644 --- a/VisualCard/Parts/Implementations/AnniversaryInfo.cs +++ b/VisualCard/Parts/Implementations/AnniversaryInfo.cs @@ -36,30 +36,15 @@ public class AnniversaryInfo : BaseCardPartInfo, IEquatable /// public DateTime? Anniversary { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new AnniversaryInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new AnniversaryInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => + new AnniversaryInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); internal override string ToStringVcardInternal(Version cardVersion) => $"{VcardConstants._anniversarySpecifier}:{Anniversary:yyyyMMdd}"; - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { - // Get the value - string anniversaryValue = value.Substring(VcardConstants._anniversarySpecifier.Length + 1); - // Populate the fields - return InstallInfo(anniversaryValue); - } - - internal override BaseCardPartInfo FromStringVcardWithTypeInternal(string value, string[] finalArgs, int altId, Version cardVersion) => - FromStringVcardInternal(value, altId, cardVersion); - - private AnniversaryInfo InstallInfo(string value) - { - // Populate field DateTime anniversary; if (int.TryParse(value, out _) && value.Length == 8) { @@ -74,7 +59,7 @@ private AnniversaryInfo InstallInfo(string value) anniversary = DateTime.Parse(value); // Add the fetched information - AnniversaryInfo _time = new(0, [], anniversary); + AnniversaryInfo _time = new(0, [], [], valueType, anniversary); return _time; } @@ -104,8 +89,7 @@ public bool Equals(AnniversaryInfo source, AnniversaryInfo target) // Check all the properties return - source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.Anniversary == target.Anniversary ; } @@ -113,10 +97,8 @@ public bool Equals(AnniversaryInfo source, AnniversaryInfo target) /// public override int GetHashCode() { - int hashCode = -2035919920; + int hashCode = 382927327; hashCode = hashCode * -1521134295 + base.GetHashCode(); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(AltArguments); - hashCode = hashCode * -1521134295 + AltId.GetHashCode(); hashCode = hashCode * -1521134295 + Anniversary.GetHashCode(); return hashCode; } @@ -131,10 +113,12 @@ public override int GetHashCode() internal AnniversaryInfo() { } - internal AnniversaryInfo(int altId, string[] altArguments, DateTime? anniversary) + internal AnniversaryInfo(int altId, string[] arguments, string[] elementTypes, string valueType, DateTime? anniversary) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; + ElementTypes = elementTypes; + ValueType = valueType; Anniversary = anniversary; } } diff --git a/VisualCard/Parts/Implementations/BirthDateInfo.cs b/VisualCard/Parts/Implementations/BirthDateInfo.cs index 5cde524..651cbc1 100644 --- a/VisualCard/Parts/Implementations/BirthDateInfo.cs +++ b/VisualCard/Parts/Implementations/BirthDateInfo.cs @@ -36,16 +36,13 @@ public class BirthDateInfo : BaseCardPartInfo, IEquatable /// public DateTime? BirthDate { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new BirthDateInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new BirthDateInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => + new BirthDateInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); internal override string ToStringVcardInternal(Version cardVersion) => $"{VcardConstants._birthSpecifier}:{BirthDate:yyyyMMdd}"; - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string bdayValue = value.Substring(VcardConstants._birthSpecifier.Length + 1); @@ -84,7 +81,7 @@ private BirthDateInfo InstallInfo(string value, string[] finalArgs, int altId, V // Add the fetched information bool altIdSupported = cardVersion.Major >= 4; - BirthDateInfo _time = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], bday); + BirthDateInfo _time = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, bday); return _time; } @@ -115,7 +112,7 @@ public bool Equals(BirthDateInfo source, BirthDateInfo target) // Check all the properties return source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.BirthDate == target.BirthDate ; } @@ -140,10 +137,10 @@ public override int GetHashCode() internal BirthDateInfo() { } - internal BirthDateInfo(int altId, string[] altArguments, DateTime? birth) + internal BirthDateInfo(int altId, string[] arguments, string[] elementTypes, string valueType, DateTime? birth) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; BirthDate = birth; } } diff --git a/VisualCard/Parts/Implementations/CategoryInfo.cs b/VisualCard/Parts/Implementations/CategoryInfo.cs index 1020cf5..d6d9a2e 100644 --- a/VisualCard/Parts/Implementations/CategoryInfo.cs +++ b/VisualCard/Parts/Implementations/CategoryInfo.cs @@ -37,11 +37,8 @@ public class CategoryInfo : BaseCardPartInfo, IEquatable /// public string[] Category { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new CategoryInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new CategoryInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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) { @@ -50,7 +47,7 @@ internal override string ToStringVcardInternal(Version cardVersion) $"{Category}"; } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string categoryValue = value.Substring(VcardConstants._categoriesSpecifier.Length + 1); @@ -99,7 +96,7 @@ public bool Equals(CategoryInfo source, CategoryInfo target) // Check all the properties return source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.Category == target.Category ; } @@ -125,10 +122,10 @@ public override int GetHashCode() internal CategoryInfo() { } - internal CategoryInfo(int altId, string[] altArguments, string[] category) + internal CategoryInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string[] category) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; Category = category; } } diff --git a/VisualCard/Parts/Implementations/EmailInfo.cs b/VisualCard/Parts/Implementations/EmailInfo.cs index c2cec0a..a92bda6 100644 --- a/VisualCard/Parts/Implementations/EmailInfo.cs +++ b/VisualCard/Parts/Implementations/EmailInfo.cs @@ -42,18 +42,15 @@ public class EmailInfo : BaseCardPartInfo, IEquatable /// public string ContactEmailAddress { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new EmailInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new EmailInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; return $"{VcardConstants._emailSpecifier};" + $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + @@ -69,7 +66,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string mailValue = value.Substring(VcardConstants._emailSpecifier.Length + 1); @@ -114,7 +111,7 @@ private EmailInfo InstallInfo(string[] splitMail, string[] finalArgs, int altId, // Populate the fields string[] _emailTypes = installType ? VcardParserTools.GetTypes(splitMail, "HOME", specifierRequired) : ["HOME"]; string _emailAddress = mail.Address; - EmailInfo _address = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _emailTypes, _emailAddress); + EmailInfo _address = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _emailTypes, _emailAddress); return _address; } @@ -144,8 +141,7 @@ public bool Equals(EmailInfo source, EmailInfo target) // Check all the properties return - source.ContactEmailTypes.SequenceEqual(target.ContactEmailTypes) && - source.AltId == target.AltId && + base.Equals(source, target) && source.ContactEmailAddress == target.ContactEmailAddress ; } @@ -171,10 +167,12 @@ public override int GetHashCode() internal EmailInfo() { } - internal EmailInfo(int altId, string[] altArguments, string[] contactEmailTypes, string contactEmailAddress) + internal EmailInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string[] contactEmailTypes, string contactEmailAddress) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; + ElementTypes = elementTypes; + ValueType = valueType; ContactEmailTypes = contactEmailTypes; ContactEmailAddress = contactEmailAddress; } diff --git a/VisualCard/Parts/Implementations/GenderInfo.cs b/VisualCard/Parts/Implementations/GenderInfo.cs index b1d7894..30363cb 100644 --- a/VisualCard/Parts/Implementations/GenderInfo.cs +++ b/VisualCard/Parts/Implementations/GenderInfo.cs @@ -42,18 +42,15 @@ public class GenderInfo : BaseCardPartInfo, IEquatable /// public string GenderDescription { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new GenderInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new GenderInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => + 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}" : ""); - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string genderValue = value.Substring(VcardConstants._genderSpecifier.Length + 1); @@ -125,7 +122,7 @@ public bool Equals(GenderInfo source, GenderInfo target) // Check all the properties return source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.Gender == target.Gender && source.GenderDescription == target.GenderDescription ; @@ -153,10 +150,10 @@ public override int GetHashCode() internal GenderInfo() { } - internal GenderInfo(int altId, string[] altArguments, Gender gender, string genderDescription) + internal GenderInfo(int altId, string[] arguments, string[] elementTypes, string valueType, Gender gender, string genderDescription) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; Gender = gender; GenderDescription = genderDescription; } diff --git a/VisualCard/Parts/Implementations/GeoInfo.cs b/VisualCard/Parts/Implementations/GeoInfo.cs index 3eeaf19..738b80d 100644 --- a/VisualCard/Parts/Implementations/GeoInfo.cs +++ b/VisualCard/Parts/Implementations/GeoInfo.cs @@ -42,18 +42,15 @@ public class GeoInfo : BaseCardPartInfo, IEquatable /// public string Geo { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new GeoInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new GeoInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; return $"{VcardConstants._geoSpecifier}{(installAltId ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + @@ -68,7 +65,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string geoValue = value.Substring(VcardConstants._geoSpecifier.Length + 1); @@ -102,7 +99,7 @@ private GeoInfo InstallInfo(string[] splitGeo, bool installType, string[] finalA string _geoStr = Regex.Unescape(typesSupported ? installType ? splitGeo[1] : splitGeo[0] : splitGeo[0]); // Populate the fields - GeoInfo _geo = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _geoTypes, _geoStr); + GeoInfo _geo = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _geoTypes, _geoStr); return _geo; } @@ -134,7 +131,7 @@ public bool Equals(GeoInfo source, GeoInfo target) return source.AltArguments.SequenceEqual(target.AltArguments) && source.GeoTypes.SequenceEqual(target.GeoTypes) && - source.AltId == target.AltId && + base.Equals(source, target) && source.Geo == target.Geo ; } @@ -160,10 +157,10 @@ public override int GetHashCode() internal GeoInfo() { } - internal GeoInfo(int altId, string[] altArguments, string[] geoTypes, string geo) + internal GeoInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string[] geoTypes, string geo) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; GeoTypes = geoTypes; Geo = geo; } diff --git a/VisualCard/Parts/Implementations/ImppInfo.cs b/VisualCard/Parts/Implementations/ImppInfo.cs index 0d0915a..44f235a 100644 --- a/VisualCard/Parts/Implementations/ImppInfo.cs +++ b/VisualCard/Parts/Implementations/ImppInfo.cs @@ -42,18 +42,15 @@ public class ImppInfo : BaseCardPartInfo, IEquatable /// public string[] ImppTypes { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new ImppInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new ImppInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; bool installType = ImppTypes.Length > 0 && ImppTypes[0].ToUpper() != "HOME"; return $"{VcardConstants._imppSpecifier}{(installType || installAltId ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + @@ -71,7 +68,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string imppValue = value.Substring(VcardConstants._imppSpecifier.Length + 1); @@ -109,7 +106,7 @@ private ImppInfo InstallInfo(string[] types, string imppValue, string[] finalArg Regex.Unescape(imppValue.Substring(imppValue.IndexOf(":") + 1)) : Regex.Unescape(imppValue); - ImppInfo _imppInstance = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _impp, types); + ImppInfo _imppInstance = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _impp, types); return _imppInstance; } @@ -141,7 +138,7 @@ public bool Equals(ImppInfo source, ImppInfo target) return source.AltArguments.SequenceEqual(target.AltArguments) && source.ImppTypes.SequenceEqual(target.ImppTypes) && - source.AltId == target.AltId && + base.Equals(source, target) && source.ContactIMPP == target.ContactIMPP ; } @@ -167,10 +164,10 @@ public override int GetHashCode() internal ImppInfo() { } - internal ImppInfo(int altId, string[] altArguments, string contactImpp, string[] imppTypes) + internal ImppInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string contactImpp, string[] imppTypes) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; ContactIMPP = contactImpp; ImppTypes = imppTypes; } diff --git a/VisualCard/Parts/Implementations/LabelAddressInfo.cs b/VisualCard/Parts/Implementations/LabelAddressInfo.cs index 95a52fa..f7d11fa 100644 --- a/VisualCard/Parts/Implementations/LabelAddressInfo.cs +++ b/VisualCard/Parts/Implementations/LabelAddressInfo.cs @@ -42,18 +42,15 @@ public class LabelAddressInfo : BaseCardPartInfo, IEquatable /// public string DeliveryLabel { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new LabelAddressInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new LabelAddressInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; return $"{VcardConstants._labelSpecifier};" + $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + @@ -69,7 +66,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string adrValue = value.Substring(VcardConstants._labelSpecifier.Length + 1); @@ -113,7 +110,7 @@ private LabelAddressInfo InstallInfo(string[] splitAdr, string[] splitAddressVal // Populate the fields string[] _addressTypes = defaultType ? ["HOME"] : VcardParserTools.GetTypes(splitAdr, "HOME", specifierRequired); string _addressLabel = Regex.Unescape(splitAddressValues[0]); - LabelAddressInfo _address = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _addressTypes, _addressLabel); + LabelAddressInfo _address = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _addressTypes, _addressLabel); return _address; } @@ -145,7 +142,7 @@ public bool Equals(LabelAddressInfo source, LabelAddressInfo target) return source.AddressTypes.SequenceEqual(target.AddressTypes) && source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.DeliveryLabel == target.DeliveryLabel ; } @@ -171,10 +168,10 @@ public override int GetHashCode() internal LabelAddressInfo() { } - internal LabelAddressInfo(int altId, string[] altArguments, string[] addressTypes, string label) + internal LabelAddressInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string[] addressTypes, string label) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; AddressTypes = addressTypes; DeliveryLabel = label; } diff --git a/VisualCard/Parts/Implementations/LangInfo.cs b/VisualCard/Parts/Implementations/LangInfo.cs index cc0cf29..84364df 100644 --- a/VisualCard/Parts/Implementations/LangInfo.cs +++ b/VisualCard/Parts/Implementations/LangInfo.cs @@ -45,18 +45,15 @@ public class LangInfo : BaseCardPartInfo, IEquatable /// public string ContactLang { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new LangInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new LangInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; return $"{VcardConstants._langSpecifier};" + $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + @@ -74,7 +71,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string langValue = value.Substring(VcardConstants._langSpecifier.Length + 1); @@ -137,7 +134,7 @@ public bool Equals(LangInfo source, LangInfo target) // Check all the properties return source.ContactLangTypes.SequenceEqual(target.ContactLangTypes) && - source.AltId == target.AltId && + base.Equals(source, target) && source.ContactLang == target.ContactLang ; } @@ -163,10 +160,10 @@ public override int GetHashCode() internal LangInfo() { } - internal LangInfo(int altId, string[] altArguments, string[] contactLangTypes, string contactLangCode) + internal LangInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string[] contactLangTypes, string contactLangCode) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; ContactLangTypes = contactLangTypes; ContactLang = contactLangCode; } diff --git a/VisualCard/Parts/Implementations/LogoInfo.cs b/VisualCard/Parts/Implementations/LogoInfo.cs index f68f5bb..0ff2e2a 100644 --- a/VisualCard/Parts/Implementations/LogoInfo.cs +++ b/VisualCard/Parts/Implementations/LogoInfo.cs @@ -49,18 +49,15 @@ public class LogoInfo : BaseCardPartInfo, IEquatable /// public string LogoEncoded { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new LogoInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new LogoInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; if (ValueType == "uri" || ValueType == "url") { return @@ -103,7 +100,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) => + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => throw new InvalidDataException("Logo field must not have empty type."); internal override BaseCardPartInfo FromStringVcardWithTypeInternal(string value, string[] finalArgs, int altId, Version cardVersion) @@ -132,7 +129,7 @@ private LogoInfo InstallInfo(string[] splitLogo, string[] finalArgs, int altId, string logoType = VcardParserTools.GetTypesString(splitLogo, "JPEG", false); // Populate the fields - LogoInfo _logo = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], valueType, logoEncoding, logoType, splitLogo[1]); + LogoInfo _logo = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, valueType, logoEncoding, logoType, splitLogo[1]); return _logo; } @@ -163,7 +160,7 @@ public bool Equals(LogoInfo source, LogoInfo target) // Check all the properties return source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.ValueType == target.ValueType && source.Encoding == target.Encoding && source.LogoType == target.LogoType && @@ -194,10 +191,10 @@ public override int GetHashCode() internal LogoInfo() { } - internal LogoInfo(int altId, string[] altArguments, string valueType, string encoding, string logoType, string logoEncoded) + internal LogoInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string valueType, string encoding, string logoType, string logoEncoded) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; ValueType = valueType; Encoding = encoding; LogoType = logoType; diff --git a/VisualCard/Parts/Implementations/NameInfo.cs b/VisualCard/Parts/Implementations/NameInfo.cs index 90b6032..c8fbb2c 100644 --- a/VisualCard/Parts/Implementations/NameInfo.cs +++ b/VisualCard/Parts/Implementations/NameInfo.cs @@ -54,18 +54,15 @@ public class NameInfo : BaseCardPartInfo, IEquatable /// public string[] Suffixes { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new NameInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new NameInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => + new NameInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); internal override string ToStringVcardInternal(Version cardVersion) { bool altIdSupported = cardVersion.Major >= 4; if (altIdSupported) { - bool installAltId = AltId >= 0 && AltArguments.Length > 0; + 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); @@ -94,7 +91,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Check the line string nameValue = value.Substring(VcardConstants._nameSpecifier.Length + 1); @@ -132,7 +129,7 @@ private NameInfo InstallInfo(string[] splitName, string[] finalArgs, int altId, string[] _altNames = splitName.Length >= 3 ? Regex.Unescape(splitName[2]).Split(new char[] { VcardConstants._valueDelimiter }, StringSplitOptions.RemoveEmptyEntries) : []; string[] _prefixes = splitName.Length >= 4 ? Regex.Unescape(splitName[3]).Split(new char[] { VcardConstants._valueDelimiter }, StringSplitOptions.RemoveEmptyEntries) : []; string[] _suffixes = splitName.Length >= 5 ? Regex.Unescape(splitName[4]).Split(new char[] { VcardConstants._valueDelimiter }, StringSplitOptions.RemoveEmptyEntries) : []; - NameInfo _name = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _firstName, _lastName, _altNames, _prefixes, _suffixes); + NameInfo _name = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _firstName, _lastName, _altNames, _prefixes, _suffixes); return _name; } @@ -166,7 +163,7 @@ public bool Equals(NameInfo source, NameInfo target) source.AltNames.SequenceEqual(target.AltNames) && source.Prefixes.SequenceEqual(target.Prefixes) && source.Suffixes.SequenceEqual(target.Suffixes) && - source.AltId == target.AltId && + base.Equals(source, target) && source.ContactFirstName == target.ContactFirstName && source.ContactLastName == target.ContactLastName ; @@ -196,10 +193,10 @@ public override int GetHashCode() internal NameInfo() { } - internal NameInfo(int altId, string[] altArguments, string contactFirstName, string contactLastName, string[] altNames, string[] prefixes, string[] suffixes) + internal NameInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string contactFirstName, string contactLastName, string[] altNames, string[] prefixes, string[] suffixes) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; ContactFirstName = contactFirstName; ContactLastName = contactLastName; AltNames = altNames; diff --git a/VisualCard/Parts/Implementations/NicknameInfo.cs b/VisualCard/Parts/Implementations/NicknameInfo.cs index 09c748c..82ce341 100644 --- a/VisualCard/Parts/Implementations/NicknameInfo.cs +++ b/VisualCard/Parts/Implementations/NicknameInfo.cs @@ -42,18 +42,15 @@ public class NicknameInfo : BaseCardPartInfo, IEquatable /// public string[] NicknameTypes { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new NicknameInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new NicknameInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; return $"{VcardConstants._nicknameSpecifier};" + $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + @@ -70,7 +67,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string nickValue = value.Substring(VcardConstants._nicknameSpecifier.Length + 1); @@ -103,7 +100,7 @@ private NicknameInfo InstallInfo(string[] splitNick, string[] finalArgs, int alt // Populate the fields string[] _nicknameTypes = installType ? VcardParserTools.GetTypes(splitNick, "WORK", specifierRequired) : ["HOME"]; string _nick = Regex.Unescape(installType ? splitNick[1] : splitNick[0]); - NicknameInfo _nickInstance = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _nick, _nicknameTypes); + NicknameInfo _nickInstance = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _nick, _nicknameTypes); return _nickInstance; } @@ -135,7 +132,7 @@ public bool Equals(NicknameInfo source, NicknameInfo target) return source.AltArguments.SequenceEqual(target.AltArguments) && source.NicknameTypes.SequenceEqual(target.NicknameTypes) && - source.AltId == target.AltId && + base.Equals(source, target) && source.ContactNickname == target.ContactNickname ; } @@ -161,10 +158,10 @@ public override int GetHashCode() internal NicknameInfo() { } - internal NicknameInfo(int altId, string[] altArguments, string contactNickname, string[] nicknameTypes) + internal NicknameInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string contactNickname, string[] nicknameTypes) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; ContactNickname = contactNickname; NicknameTypes = nicknameTypes; } diff --git a/VisualCard/Parts/Implementations/OrganizationInfo.cs b/VisualCard/Parts/Implementations/OrganizationInfo.cs index 6daccfe..5972816 100644 --- a/VisualCard/Parts/Implementations/OrganizationInfo.cs +++ b/VisualCard/Parts/Implementations/OrganizationInfo.cs @@ -50,18 +50,15 @@ public class OrganizationInfo : BaseCardPartInfo, IEquatable /// public string Role { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new OrganizationInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new OrganizationInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; bool installType = (installAltId || OrgTypes.Length > 0) && OrgTypes[0].ToUpper() != "WORK"; return $"{VcardConstants._orgSpecifier}{(installType || installAltId ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + @@ -83,7 +80,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string orgValue = value.Substring(VcardConstants._orgSpecifier.Length + 1); @@ -124,7 +121,7 @@ private OrganizationInfo InstallInfo(string[] splitOrg, string[] _orgTypes, stri string _orgName = Regex.Unescape(splitOrg[0]); string _orgUnit = Regex.Unescape(splitOrg.Length >= 2 ? splitOrg[1] : ""); string _orgUnitRole = Regex.Unescape(splitOrg.Length >= 3 ? splitOrg[2] : ""); - OrganizationInfo _org = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _orgName, _orgUnit, _orgUnitRole, _orgTypes); + OrganizationInfo _org = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _orgName, _orgUnit, _orgUnitRole, _orgTypes); return _org; } @@ -156,7 +153,7 @@ public bool Equals(OrganizationInfo source, OrganizationInfo target) return source.OrgTypes.SequenceEqual(target.OrgTypes) && source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.Name == target.Name && source.Unit == target.Unit && source.Role == target.Role @@ -186,10 +183,10 @@ public override int GetHashCode() internal OrganizationInfo() { } - internal OrganizationInfo(int altId, string[] altArguments, string name, string unit, string role, string[] orgTypes) + internal OrganizationInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string name, string unit, string role, string[] orgTypes) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; Name = name; Unit = unit; Role = role; diff --git a/VisualCard/Parts/Implementations/PhotoInfo.cs b/VisualCard/Parts/Implementations/PhotoInfo.cs index b90e41c..0b373fc 100644 --- a/VisualCard/Parts/Implementations/PhotoInfo.cs +++ b/VisualCard/Parts/Implementations/PhotoInfo.cs @@ -49,18 +49,15 @@ public class PhotoInfo : BaseCardPartInfo, IEquatable /// public string PhotoEncoded { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new PhotoInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new PhotoInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; if (ValueType == "uri" || ValueType == "url") { return @@ -103,7 +100,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) => + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => throw new InvalidDataException("Photo field must not have empty type."); internal override BaseCardPartInfo FromStringVcardWithTypeInternal(string value, string[] finalArgs, int altId, Version cardVersion) @@ -132,7 +129,7 @@ private PhotoInfo InstallInfo(string[] splitPhoto, string[] finalArgs, int altId string photoType = VcardParserTools.GetTypesString(splitPhoto, "JPEG", false); // Populate the fields - PhotoInfo _photo = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], valueType, photoEncoding, photoType, splitPhoto[1]); + PhotoInfo _photo = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, valueType, photoEncoding, photoType, splitPhoto[1]); return _photo; } @@ -163,7 +160,7 @@ public bool Equals(PhotoInfo source, PhotoInfo target) // Check all the properties return source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.ValueType == target.ValueType && source.Encoding == target.Encoding && source.PhotoType == target.PhotoType && @@ -194,10 +191,10 @@ public override int GetHashCode() internal PhotoInfo() { } - internal PhotoInfo(int altId, string[] altArguments, string valueType, string encoding, string photoType, string photoEncoded) + internal PhotoInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string valueType, string encoding, string photoType, string photoEncoded) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; ValueType = valueType; Encoding = encoding; PhotoType = photoType; diff --git a/VisualCard/Parts/Implementations/RevisionInfo.cs b/VisualCard/Parts/Implementations/RevisionInfo.cs index 9365cda..b796d3c 100644 --- a/VisualCard/Parts/Implementations/RevisionInfo.cs +++ b/VisualCard/Parts/Implementations/RevisionInfo.cs @@ -36,16 +36,13 @@ public class RevisionInfo : BaseCardPartInfo, IEquatable /// public DateTime? Revision { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new RevisionInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new RevisionInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => + new RevisionInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, valueType, cardVersion); internal override string ToStringVcardInternal(Version cardVersion) => $"{VcardConstants._revSpecifier}:{Revision:yyyy-MM-dd HH:mm:ss}"; - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string revValue = value.Substring(VcardConstants._revSpecifier.Length + 1); @@ -67,7 +64,7 @@ private RevisionInfo InstallInfo(string value, string[] finalArgs, int altId, Ve // Add the fetched information bool altIdSupported = cardVersion.Major >= 4; - RevisionInfo _time = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], rev); + RevisionInfo _time = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, rev); return _time; } @@ -98,7 +95,7 @@ public bool Equals(RevisionInfo source, RevisionInfo target) // Check all the properties return source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.Revision == target.Revision ; } @@ -123,10 +120,10 @@ public override int GetHashCode() internal RevisionInfo() { } - internal RevisionInfo(int altId, string[] altArguments, DateTime? birth) + internal RevisionInfo(int altId, string[] arguments, string[] elementTypes, string valueType, DateTime? birth) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; Revision = birth; } } diff --git a/VisualCard/Parts/Implementations/RoleInfo.cs b/VisualCard/Parts/Implementations/RoleInfo.cs index ba805ee..b4d9545 100644 --- a/VisualCard/Parts/Implementations/RoleInfo.cs +++ b/VisualCard/Parts/Implementations/RoleInfo.cs @@ -36,18 +36,15 @@ public class RoleInfo : BaseCardPartInfo, IEquatable /// public string ContactRole { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new RoleInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new RoleInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; return $"{VcardConstants._roleSpecifier}{(installAltId ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + @@ -62,7 +59,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string roleValue = value.Substring(VcardConstants._roleSpecifier.Length + 1); @@ -88,7 +85,7 @@ private RoleInfo InstallInfo(string roleValue, string[] finalArgs, int altId, Ve bool altIdSupported = cardVersion.Major >= 4; // Populate the fields - RoleInfo _telephone = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], roleValue); + RoleInfo _telephone = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, roleValue); return _telephone; } @@ -119,7 +116,7 @@ public bool Equals(RoleInfo source, RoleInfo target) // Check all the properties return source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.ContactRole == target.ContactRole ; } @@ -144,10 +141,10 @@ public override int GetHashCode() internal RoleInfo() { } - internal RoleInfo(int altId, string[] altArguments, string contactRole) + internal RoleInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string contactRole) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; ContactRole = contactRole; } } diff --git a/VisualCard/Parts/Implementations/SoundInfo.cs b/VisualCard/Parts/Implementations/SoundInfo.cs index 117d1e5..0d88862 100644 --- a/VisualCard/Parts/Implementations/SoundInfo.cs +++ b/VisualCard/Parts/Implementations/SoundInfo.cs @@ -49,18 +49,15 @@ public class SoundInfo : BaseCardPartInfo, IEquatable /// public string SoundEncoded { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new SoundInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new SoundInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; if (ValueType == "uri" || ValueType == "url") { return @@ -103,7 +100,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) => + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) => throw new InvalidDataException("Sound field must not have empty type."); internal override BaseCardPartInfo FromStringVcardWithTypeInternal(string value, string[] finalArgs, int altId, Version cardVersion) @@ -132,7 +129,7 @@ private SoundInfo InstallInfo(string[] splitSound, string[] finalArgs, int altId string soundType = VcardParserTools.GetTypesString(splitSound, "WAVE", false); // Populate the fields - SoundInfo _sound = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], valueType, soundEncoding, soundType, splitSound[1]); + SoundInfo _sound = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, valueType, soundEncoding, soundType, splitSound[1]); return _sound; } @@ -163,7 +160,7 @@ public bool Equals(SoundInfo source, SoundInfo target) // Check all the properties return source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.ValueType == target.ValueType && source.Encoding == target.Encoding && source.SoundType == target.SoundType && @@ -194,10 +191,10 @@ public override int GetHashCode() internal SoundInfo() { } - internal SoundInfo(int altId, string[] altArguments, string valueType, string encoding, string soundType, string soundEncoded) + internal SoundInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string valueType, string encoding, string soundType, string soundEncoded) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; ValueType = valueType; Encoding = encoding; SoundType = soundType; diff --git a/VisualCard/Parts/Implementations/TelephoneInfo.cs b/VisualCard/Parts/Implementations/TelephoneInfo.cs index 4ba7f7a..75fe532 100644 --- a/VisualCard/Parts/Implementations/TelephoneInfo.cs +++ b/VisualCard/Parts/Implementations/TelephoneInfo.cs @@ -42,18 +42,15 @@ public class TelephoneInfo : BaseCardPartInfo, IEquatable /// public string ContactPhoneNumber { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new TelephoneInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new TelephoneInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; return $"{VcardConstants._telephoneSpecifier};" + $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + @@ -69,7 +66,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string telValue = value.Substring(VcardConstants._telephoneSpecifier.Length + 1); @@ -102,7 +99,7 @@ private TelephoneInfo InstallInfo(string[] splitTel, string[] finalArgs, int alt // Populate the fields string[] _telephoneTypes = installType ? VcardParserTools.GetTypes(splitTel, "CELL", specifierRequired) : ["CELL"]; string _telephoneNumber = Regex.Unescape(installType ? splitTel[1] : splitTel[0]); - TelephoneInfo _telephone = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _telephoneTypes, _telephoneNumber); + TelephoneInfo _telephone = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _telephoneTypes, _telephoneNumber); return _telephone; } @@ -134,7 +131,7 @@ public bool Equals(TelephoneInfo source, TelephoneInfo target) return source.ContactPhoneTypes.SequenceEqual(target.ContactPhoneTypes) && source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.ContactPhoneNumber == target.ContactPhoneNumber ; } @@ -160,10 +157,10 @@ public override int GetHashCode() internal TelephoneInfo() { } - internal TelephoneInfo(int altId, string[] altArguments, string[] contactPhoneTypes, string contactPhoneNumber) + internal TelephoneInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string[] contactPhoneTypes, string contactPhoneNumber) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; ContactPhoneTypes = contactPhoneTypes; ContactPhoneNumber = contactPhoneNumber; } diff --git a/VisualCard/Parts/Implementations/TimeDateZoneInfo.cs b/VisualCard/Parts/Implementations/TimeDateZoneInfo.cs index 0187ce8..245b759 100644 --- a/VisualCard/Parts/Implementations/TimeDateZoneInfo.cs +++ b/VisualCard/Parts/Implementations/TimeDateZoneInfo.cs @@ -42,18 +42,15 @@ public class TimeDateZoneInfo : BaseCardPartInfo, IEquatable /// public string TimeZone { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new TimeDateZoneInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new TimeDateZoneInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; return $"{VcardConstants._timeZoneSpecifier}{(installAltId ? VcardConstants._fieldDelimiter : VcardConstants._argumentDelimiter)}" + $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + @@ -68,7 +65,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string tzValue = value.Substring(VcardConstants._timeZoneSpecifier.Length + 1); @@ -102,7 +99,7 @@ private TimeDateZoneInfo InstallInfo(string[] splitTz, bool installType, string[ string _geoStr = Regex.Unescape(typesSupported ? installType ? splitTz[1] : splitTz[0] : splitTz[0]); // Add the fetched information - TimeDateZoneInfo _timeZone = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _geoTypes, _geoStr); + TimeDateZoneInfo _timeZone = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _geoTypes, _geoStr); return _timeZone; } @@ -134,7 +131,7 @@ public bool Equals(TimeDateZoneInfo source, TimeDateZoneInfo target) return source.AltArguments.SequenceEqual(target.AltArguments) && source.TimeZoneTypes.SequenceEqual(target.TimeZoneTypes) && - source.AltId == target.AltId && + base.Equals(source, target) && source.TimeZone == target.TimeZone ; } @@ -160,10 +157,10 @@ public override int GetHashCode() internal TimeDateZoneInfo() { } - internal TimeDateZoneInfo(int altId, string[] altArguments, string[] timeZoneTypes, string timeZone) + internal TimeDateZoneInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string[] timeZoneTypes, string timeZone) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; TimeZoneTypes = timeZoneTypes; TimeZone = timeZone; } diff --git a/VisualCard/Parts/Implementations/TitleInfo.cs b/VisualCard/Parts/Implementations/TitleInfo.cs index e246540..6f8828a 100644 --- a/VisualCard/Parts/Implementations/TitleInfo.cs +++ b/VisualCard/Parts/Implementations/TitleInfo.cs @@ -37,18 +37,15 @@ public class TitleInfo : BaseCardPartInfo, IEquatable /// public string ContactTitle { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new TitleInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new TitleInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; return $"{(installAltId ? $"{VcardConstants._titleSpecifier};" : $"{VcardConstants._titleSpecifier}:")}" + $"{(installAltId ? VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._fieldDelimiter : "")}" + @@ -63,7 +60,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string titleValue = value.Substring(VcardConstants._titleSpecifier.Length + 1); @@ -89,7 +86,7 @@ private TitleInfo InstallInfo(string[] splitTitleParts, string[] finalArgs, int { bool altIdSupported = cardVersion.Major >= 4; string _title = Regex.Unescape(splitTitleParts.Length > 1 ? splitTitleParts[1] : splitTitleParts[0]); - TitleInfo _titleInfo = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _title); + TitleInfo _titleInfo = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _title); return _titleInfo; } @@ -120,7 +117,7 @@ public bool Equals(TitleInfo source, TitleInfo target) // Check all the properties return source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.ContactTitle == target.ContactTitle ; } @@ -145,10 +142,10 @@ public override int GetHashCode() internal TitleInfo() { } - internal TitleInfo(int altId, string[] altArguments, string contactTitle) + internal TitleInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string contactTitle) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; ContactTitle = contactTitle; } } diff --git a/VisualCard/Parts/Implementations/XNameInfo.cs b/VisualCard/Parts/Implementations/XNameInfo.cs index 49da2f5..c0b755b 100644 --- a/VisualCard/Parts/Implementations/XNameInfo.cs +++ b/VisualCard/Parts/Implementations/XNameInfo.cs @@ -44,18 +44,15 @@ public class XNameInfo : BaseCardPartInfo, IEquatable /// public string[] XValues { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new XNameInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new XNameInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; bool installType = installAltId && XKeyTypes.Length > 0; return $"{VcardConstants._xSpecifier}" + @@ -74,7 +71,7 @@ internal override string ToStringVcardInternal(Version cardVersion) } } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string xValue = value.Substring(VcardConstants._xSpecifier.Length); @@ -112,7 +109,7 @@ private XNameInfo InstallInfo(string[] splitX, string[] finalArgs, int altId, Ve .Split(VcardConstants._fieldDelimiter) : []; string[] _xValues = splitX[1].Split(VcardConstants._fieldDelimiter); - XNameInfo _x = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], _xName, _xValues, _xTypes); + XNameInfo _x = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _xName, _xValues, _xTypes); return _x; } @@ -145,7 +142,7 @@ public bool Equals(XNameInfo source, XNameInfo target) source.AltArguments.SequenceEqual(target.AltArguments) && source.XKeyTypes.SequenceEqual(target.XKeyTypes) && source.XValues.SequenceEqual(target.XValues) && - source.AltId == target.AltId && + base.Equals(source, target) && source.XKeyName == target.XKeyName ; } @@ -172,10 +169,10 @@ public override int GetHashCode() internal XNameInfo() { } - internal XNameInfo(int altId, string[] altArguments, string xKeyName, string[] xValues, string[] xKeyTypes) + internal XNameInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string xKeyName, string[] xValues, string[] xKeyTypes) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; XKeyName = xKeyName; XValues = xValues; XKeyTypes = xKeyTypes; diff --git a/VisualCard/Parts/Implementations/XmlInfo.cs b/VisualCard/Parts/Implementations/XmlInfo.cs index f5be469..0fb7634 100644 --- a/VisualCard/Parts/Implementations/XmlInfo.cs +++ b/VisualCard/Parts/Implementations/XmlInfo.cs @@ -42,22 +42,19 @@ public class XmlInfo : BaseCardPartInfo, IEquatable /// public string XmlString { get; } - internal static BaseCardPartInfo FromStringVcardStatic(string value, int altId, Version cardVersion) => - new XmlInfo().FromStringVcardInternal(value, altId, cardVersion); - - internal static BaseCardPartInfo FromStringVcardWithTypeStatic(string value, string[] finalArgs, int altId, Version cardVersion) => - new XmlInfo().FromStringVcardWithTypeInternal(value, finalArgs, altId, cardVersion); + 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 && AltArguments.Length > 0; + bool installAltId = AltId >= 0 && Arguments.Length > 0; return $"{VcardConstants._xmlSpecifier}" + $"{(installAltId ? VcardConstants._fieldDelimiter + VcardConstants._altIdArgumentSpecifier + AltId + VcardConstants._argumentDelimiter : VcardConstants._argumentDelimiter)}" + $"{XmlString}"; } - internal override BaseCardPartInfo FromStringVcardInternal(string value, int altId, Version cardVersion) + internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion) { // Get the value string xmlValue = value.Substring(VcardConstants._xmlSpecifier.Length + 1); @@ -93,7 +90,7 @@ private XmlInfo InstallInfo(string value, string[] finalArgs, int altId, Version // Add the fetched information bool altIdSupported = cardVersion.Major >= 4; - XmlInfo _xml = new(altIdSupported ? altId : 0, altIdSupported ? finalArgs : [], doc, value); + XmlInfo _xml = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, doc, value); return _xml; } @@ -124,7 +121,7 @@ public bool Equals(XmlInfo source, XmlInfo target) // Check all the properties return source.AltArguments.SequenceEqual(target.AltArguments) && - source.AltId == target.AltId && + base.Equals(source, target) && source.Xml == target.Xml ; } @@ -150,10 +147,10 @@ public override int GetHashCode() internal XmlInfo() { } - internal XmlInfo(int altId, string[] altArguments, XmlDocument xml, string xmlString) + internal XmlInfo(int altId, string[] arguments, string[] elementTypes, string valueType, XmlDocument xml, string xmlString) { AltId = altId; - AltArguments = altArguments; + Arguments = arguments; Xml = xml; XmlString = xmlString; }