Skip to content

Commit

Permalink
add - doc - Added NestedGroup property
Browse files Browse the repository at this point in the history
---

We've added a new property that allows you to get a nested group representation.

---

Type: add
Breaking: False
Doc Required: True
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 9, 2024
1 parent 2e6f9a2 commit 5694f2b
Show file tree
Hide file tree
Showing 23 changed files with 132 additions and 114 deletions.
6 changes: 6 additions & 0 deletions VisualCard/Parsers/Arguments/PropertyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public class PropertyInfo : IEquatable<PropertyInfo?>
public string Group =>
group;

/// <summary>
/// Nested property groups
/// </summary>
public string[] NestedGroups =>
group.Split('.');

/// <summary>
/// Argument info instances. It includes AltId, type, and value
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions VisualCard/Parsers/VcardParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public Card Parse()
throw new InvalidDataException("Profile must be \"vCard\"");

// Set the string for real
var stringValueInfo = new CardValueInfo<string>(info, altId, elementTypes, valueType, info.Group, finalValue);
var stringValueInfo = new CardValueInfo<string>(info, altId, elementTypes, valueType, finalValue);
card.AddString(stringType, stringValueInfo);
}
break;
Expand All @@ -161,7 +161,7 @@ public Card Parse()

// Now, get the part info
finalValue = partsArrayType is PartsArrayEnum.NonstandardNames or PartsArrayEnum.IanaNames ? _value : info.Value;
var partInfo = partType.fromStringFunc(finalValue, info, altId, elementTypes, info.Group, valueType, CardVersion);
var partInfo = partType.fromStringFunc(finalValue, info, altId, elementTypes, valueType, CardVersion);

// Set the array for real
card.AddPartToArray(partsArrayType, partInfo);
Expand Down
4 changes: 2 additions & 2 deletions VisualCard/Parsers/VcardPartType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ internal class VcardPartType
internal readonly PartCardinality cardinality;
internal readonly Func<Version, bool> minimumVersionCondition = (_) => true;
internal readonly Type? enumType;
internal readonly Func<string, PropertyInfo, int, string[], string, string, Version, BaseCardPartInfo>? fromStringFunc;
internal readonly Func<string, PropertyInfo, int, string[], string, Version, BaseCardPartInfo>? fromStringFunc;
internal readonly string defaultType = "";
internal readonly string defaultValue = "";
internal readonly string defaultValueType = "";
internal readonly string[] allowedExtraTypes = [];
internal readonly string[] allowedValues = [];

internal VcardPartType(PartType type, object enumeration, PartCardinality cardinality, Func<Version, bool>? minimumVersionCondition, Type? enumType, Func<string, PropertyInfo, int, string[], string, string, Version, BaseCardPartInfo>? fromStringFunc, string defaultType, string defaultValue, string defaultValueType, string[] allowedExtraTypes, string[] allowedValues)
internal VcardPartType(PartType type, object enumeration, PartCardinality cardinality, Func<Version, bool>? minimumVersionCondition, Type? enumType, Func<string, PropertyInfo, int, string[], string, Version, BaseCardPartInfo>? fromStringFunc, string defaultType, string defaultValue, string defaultValueType, string[] allowedExtraTypes, string[] allowedValues)
{
this.type = type;
this.enumeration = enumeration;
Expand Down
14 changes: 10 additions & 4 deletions VisualCard/Parts/BaseCardPartInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ public abstract class BaseCardPartInfo : IEquatable<BaseCardPartInfo>
/// <summary>
/// Property group
/// </summary>
public virtual string Group { get; internal set; } = "";
public string Group =>
Property?.Group ?? "";

/// <summary>
/// Nested property groups
/// </summary>
public string[] NestedGroups =>
Group.Split('.');

/// <summary>
/// Is this part preferred?
Expand Down Expand Up @@ -136,20 +143,19 @@ public override int GetHashCode()
internal virtual bool EqualsInternal(BaseCardPartInfo source, BaseCardPartInfo target) =>
true;

internal abstract BaseCardPartInfo FromStringVcardInternal(string value, PropertyInfo property, int altId, string[] elementTypes, string group, string valueType, Version cardVersion);
internal abstract BaseCardPartInfo FromStringVcardInternal(string value, PropertyInfo property, int altId, string[] elementTypes, string valueType, Version cardVersion);

internal abstract string ToStringVcardInternal(Version cardVersion);

internal BaseCardPartInfo()
{ }

internal BaseCardPartInfo(PropertyInfo? property, int altId, string[] elementTypes, string valueType, string group)
internal BaseCardPartInfo(PropertyInfo? property, int altId, string[] elementTypes, string valueType)
{
Property = property;
AltId = altId;
ElementTypes = elementTypes;
ValueType = valueType;
Group = group;
}
}
}
2 changes: 1 addition & 1 deletion VisualCard/Parts/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public CardValueInfo<string>[] GetString(StringsEnum key)
string fallback = key == StringsEnum.Kind ? "individual" : "";
CardValueInfo<string>[] fallbacks =
!string.IsNullOrEmpty(fallback) ?
[new CardValueInfo<string>(null, -1, [], "", "", fallback)] :
[new CardValueInfo<string>(null, -1, [], "", fallback)] :
[];

// Check to see if the string has a value or not
Expand Down
12 changes: 9 additions & 3 deletions VisualCard/Parts/CardValueInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ public class CardValueInfo<TValue> : IEquatable<CardValueInfo<TValue>>
/// <summary>
/// Property group
/// </summary>
public virtual string Group { get; internal set; } = "";
public string Group =>
Property?.Group ?? "";

/// <summary>
/// Nested property groups
/// </summary>
public string[] NestedGroups =>
Group.Split('.');

/// <summary>
/// Value
Expand Down Expand Up @@ -142,13 +149,12 @@ public override int GetHashCode()
internal virtual bool EqualsInternal(CardValueInfo<TValue> source, CardValueInfo<TValue> target) =>
true;

internal CardValueInfo(PropertyInfo? property, int altId, string[] elementTypes, string valueType, string group, TValue? value)
internal CardValueInfo(PropertyInfo? property, int altId, string[] elementTypes, string valueType, TValue? value)
{
Property = property;
AltId = altId;
ElementTypes = elementTypes;
ValueType = valueType;
Group = group;
Value = value ??
throw new ArgumentNullException(nameof(value));
}
Expand Down
12 changes: 6 additions & 6 deletions VisualCard/Parts/Implementations/AddressInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public class AddressInfo : BaseCardPartInfo, IEquatable<AddressInfo>
/// </summary>
public string? Country { get; }

internal static BaseCardPartInfo FromStringVcardStatic(string value, PropertyInfo property, int altId, string[] elementTypes, string group, string valueType, Version cardVersion) =>
new AddressInfo().FromStringVcardInternal(value, property, altId, elementTypes, group, valueType, cardVersion);
internal static BaseCardPartInfo FromStringVcardStatic(string value, PropertyInfo property, int altId, string[] elementTypes, string valueType, Version cardVersion) =>
new AddressInfo().FromStringVcardInternal(value, property, altId, elementTypes, valueType, cardVersion);

internal override string ToStringVcardInternal(Version cardVersion) =>
$"{PostOfficeBox}{VcardConstants._fieldDelimiter}" +
Expand All @@ -74,7 +74,7 @@ internal override string ToStringVcardInternal(Version cardVersion) =>
$"{PostalCode}{VcardConstants._fieldDelimiter}" +
$"{Country}";

internal override BaseCardPartInfo FromStringVcardInternal(string value, PropertyInfo property, int altId, string[] elementTypes, string group, string valueType, Version cardVersion)
internal override BaseCardPartInfo FromStringVcardInternal(string value, PropertyInfo property, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
// Get the value
string[] splitAdr = value.Split(VcardConstants._fieldDelimiter);
Expand All @@ -92,7 +92,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, Propert
string _addressRegion = Regex.Unescape(splitAdr[4]);
string _addressPostalCode = Regex.Unescape(splitAdr[5]);
string _addressCountry = Regex.Unescape(splitAdr[6]);
AddressInfo _address = new(altId, property, _addressTypes, valueType, group, _addressPOBox, _addressExtended, _addressStreet, _addressLocality, _addressRegion, _addressPostalCode, _addressCountry);
AddressInfo _address = new(altId, property, _addressTypes, valueType, _addressPOBox, _addressExtended, _addressStreet, _addressLocality, _addressRegion, _addressPostalCode, _addressCountry);
return _address;
}

Expand Down Expand Up @@ -162,8 +162,8 @@ internal AddressInfo() :
base()
{ }

internal AddressInfo(int altId, PropertyInfo? property, string[] elementTypes, string valueType, string group, string postOfficeBox, string extendedAddress, string streetAddress, string locality, string region, string postalCode, string country) :
base(property, altId, elementTypes, valueType, group)
internal AddressInfo(int altId, PropertyInfo? property, string[] elementTypes, string valueType, string postOfficeBox, string extendedAddress, string streetAddress, string locality, string region, string postalCode, string country) :
base(property, altId, elementTypes, valueType)
{
PostOfficeBox = postOfficeBox;
ExtendedAddress = extendedAddress;
Expand Down
12 changes: 6 additions & 6 deletions VisualCard/Parts/Implementations/AgentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class AgentInfo : BaseCardPartInfo, IEquatable<AgentInfo>
/// </summary>
public Card[]? AgentCards { get; }

internal static BaseCardPartInfo FromStringVcardStatic(string value, PropertyInfo property, int altId, string[] elementTypes, string group, string valueType, Version cardVersion) =>
new AgentInfo().FromStringVcardInternal(value, property, altId, elementTypes, group, valueType, cardVersion);
internal static BaseCardPartInfo FromStringVcardStatic(string value, PropertyInfo property, int altId, string[] elementTypes, string valueType, Version cardVersion) =>
new AgentInfo().FromStringVcardInternal(value, property, altId, elementTypes, valueType, cardVersion);

internal override string ToStringVcardInternal(Version cardVersion)
{
Expand All @@ -57,7 +57,7 @@ internal override string ToStringVcardInternal(Version cardVersion)
return agents.ToString();
}

internal override BaseCardPartInfo FromStringVcardInternal(string value, PropertyInfo property, int altId, string[] elementTypes, string group, string valueType, Version cardVersion)
internal override BaseCardPartInfo FromStringVcardInternal(string value, PropertyInfo property, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
// Check the provided agent
if (string.IsNullOrEmpty(value))
Expand All @@ -66,7 +66,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, Propert
// Populate the fields
string _agentVcard = Regex.Unescape(value).Replace("\\n", "\n").Replace("\\N", "\n");
var _agentVcardParsers = CardTools.GetCardsFromString(_agentVcard);
AgentInfo _agent = new(altId, property, elementTypes, valueType, group, _agentVcardParsers);
AgentInfo _agent = new(altId, property, elementTypes, valueType, _agentVcardParsers);
return _agent;
}

Expand Down Expand Up @@ -124,8 +124,8 @@ internal AgentInfo() :
base()
{ }

internal AgentInfo(int altId, PropertyInfo? property, string[] elementTypes, string valueType, string group, Card[] agentCard) :
base(property, altId, elementTypes, valueType, group)
internal AgentInfo(int altId, PropertyInfo? property, string[] elementTypes, string valueType, Card[] agentCard) :
base(property, altId, elementTypes, valueType)
{
AgentCards = agentCard;
}
Expand Down
12 changes: 6 additions & 6 deletions VisualCard/Parts/Implementations/AnniversaryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public class AnniversaryInfo : BaseCardPartInfo, IEquatable<AnniversaryInfo>
/// </summary>
public DateTimeOffset Anniversary { get; }

internal static BaseCardPartInfo FromStringVcardStatic(string value, PropertyInfo property, int altId, string[] elementTypes, string group, string valueType, Version cardVersion) =>
new AnniversaryInfo().FromStringVcardInternal(value, property, altId, elementTypes, group, valueType, cardVersion);
internal static BaseCardPartInfo FromStringVcardStatic(string value, PropertyInfo property, int altId, string[] elementTypes, string valueType, Version cardVersion) =>
new AnniversaryInfo().FromStringVcardInternal(value, property, altId, elementTypes, valueType, cardVersion);

internal override string ToStringVcardInternal(Version cardVersion) =>
$"{VcardCommonTools.SavePosixDate(Anniversary, true)}";

internal override BaseCardPartInfo FromStringVcardInternal(string value, PropertyInfo property, int altId, string[] elementTypes, string group, string valueType, Version cardVersion)
internal override BaseCardPartInfo FromStringVcardInternal(string value, PropertyInfo property, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate the fields
DateTimeOffset anniversary = VcardCommonTools.ParsePosixDateTime(value);

// Add the fetched information
AnniversaryInfo _time = new(-1, property, [], valueType, group, anniversary);
AnniversaryInfo _time = new(-1, property, [], valueType, anniversary);
return _time;
}

Expand Down Expand Up @@ -103,8 +103,8 @@ internal override bool EqualsInternal(BaseCardPartInfo source, BaseCardPartInfo

internal AnniversaryInfo() { }

internal AnniversaryInfo(int altId, PropertyInfo? property, string[] elementTypes, string valueType, string group, DateTimeOffset anniversary) :
base(property, altId, elementTypes, valueType, group)
internal AnniversaryInfo(int altId, PropertyInfo? property, string[] elementTypes, string valueType, DateTimeOffset anniversary) :
base(property, altId, elementTypes, valueType)
{
Anniversary = anniversary;
}
Expand Down
12 changes: 6 additions & 6 deletions VisualCard/Parts/Implementations/BirthDateInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public class BirthDateInfo : BaseCardPartInfo, IEquatable<BirthDateInfo>
/// </summary>
public DateTimeOffset BirthDate { get; }

internal static BaseCardPartInfo FromStringVcardStatic(string value, PropertyInfo property, int altId, string[] elementTypes, string group, string valueType, Version cardVersion) =>
new BirthDateInfo().FromStringVcardInternal(value, property, altId, elementTypes, group, valueType, cardVersion);
internal static BaseCardPartInfo FromStringVcardStatic(string value, PropertyInfo property, int altId, string[] elementTypes, string valueType, Version cardVersion) =>
new BirthDateInfo().FromStringVcardInternal(value, property, altId, elementTypes, valueType, cardVersion);

internal override string ToStringVcardInternal(Version cardVersion) =>
$"{VcardCommonTools.SavePosixDate(BirthDate, true)}";

internal override BaseCardPartInfo FromStringVcardInternal(string value, PropertyInfo property, int altId, string[] elementTypes, string group, string valueType, Version cardVersion)
internal override BaseCardPartInfo FromStringVcardInternal(string value, PropertyInfo property, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate field
DateTimeOffset bday = VcardCommonTools.ParsePosixDateTime(value);

// Add the fetched information
BirthDateInfo _time = new(altId, property, elementTypes, valueType, group, bday);
BirthDateInfo _time = new(altId, property, elementTypes, valueType, bday);
return _time;
}

Expand Down Expand Up @@ -103,8 +103,8 @@ internal override bool EqualsInternal(BaseCardPartInfo source, BaseCardPartInfo

internal BirthDateInfo() { }

internal BirthDateInfo(int altId, PropertyInfo? property, string[] elementTypes, string valueType, string group, DateTimeOffset birth) :
base(property, altId, elementTypes, valueType, group)
internal BirthDateInfo(int altId, PropertyInfo? property, string[] elementTypes, string valueType, DateTimeOffset birth) :
base(property, altId, elementTypes, valueType)
{
BirthDate = birth;
}
Expand Down
12 changes: 6 additions & 6 deletions VisualCard/Parts/Implementations/CategoryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ public class CategoryInfo : BaseCardPartInfo, IEquatable<CategoryInfo>
/// </summary>
public string[]? Category { get; }

internal static BaseCardPartInfo FromStringVcardStatic(string value, PropertyInfo property, int altId, string[] elementTypes, string group, string valueType, Version cardVersion) =>
new CategoryInfo().FromStringVcardInternal(value, property, altId, elementTypes, group, valueType, cardVersion);
internal static BaseCardPartInfo FromStringVcardStatic(string value, PropertyInfo property, int altId, string[] elementTypes, string valueType, Version cardVersion) =>
new CategoryInfo().FromStringVcardInternal(value, property, altId, elementTypes, valueType, cardVersion);

internal override string ToStringVcardInternal(Version cardVersion) =>
$"{string.Join(VcardConstants._valueDelimiter.ToString(), Category)}";

internal override BaseCardPartInfo FromStringVcardInternal(string value, PropertyInfo property, int altId, string[] elementTypes, string group, string valueType, Version cardVersion)
internal override BaseCardPartInfo FromStringVcardInternal(string value, PropertyInfo property, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate the fields
var categories = Regex.Unescape(value).Split(',');

// Add the fetched information
CategoryInfo _time = new(-1, property, elementTypes, valueType, group, categories);
CategoryInfo _time = new(-1, property, elementTypes, valueType, categories);
return _time;
}

Expand Down Expand Up @@ -105,8 +105,8 @@ internal override bool EqualsInternal(BaseCardPartInfo source, BaseCardPartInfo

internal CategoryInfo() { }

internal CategoryInfo(int altId, PropertyInfo? property, string[] elementTypes, string valueType, string group, string[] category) :
base(property, altId, elementTypes, valueType, group)
internal CategoryInfo(int altId, PropertyInfo? property, string[] elementTypes, string valueType, string[] category) :
base(property, altId, elementTypes, valueType)
{
Category = category;
}
Expand Down
Loading

0 comments on commit 5694f2b

Please sign in to comment.