Skip to content

Commit 3f84faa

Browse files
authored
Merge pull request #18 from altasoft/feature/StringManipulationFunctions
Feature/string manipulation functions
2 parents 3a72a6f + d376bf7 commit 3f84faa

5 files changed

+96
-0
lines changed

src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,30 @@ public static void GenerateStringMethods(SourceCodeBuilder builder)
895895
.AppendLine("public string Substring(int startIndex) => _value.Substring(startIndex);")
896896
.NewLine();
897897

898+
builder
899+
.AppendLine("/// <summary>")
900+
.AppendLine("/// Checks if the specified value is contained within the current instance.")
901+
.AppendLine("/// </summary>")
902+
.AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]")
903+
.AppendLine("public bool Contains(string value) => _value.Contains(value);")
904+
.NewLine();
905+
906+
builder
907+
.AppendLine("/// <summary>")
908+
.AppendLine("/// Determines whether a specified string is a prefix of the current instance.")
909+
.AppendLine("/// </summary>")
910+
.AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]")
911+
.AppendLine("public bool StartsWith(string value) => _value.StartsWith(value);")
912+
.NewLine();
913+
914+
builder
915+
.AppendLine("/// <summary>")
916+
.AppendLine("/// Determines whether a specified string is a suffix of the current instance.")
917+
.AppendLine("/// </summary>")
918+
.AppendLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]")
919+
.AppendLine("public bool EndsWith(string value) => _value.EndsWith(value);")
920+
.NewLine();
921+
898922
builder
899923
.AppendLine("/// <summary>")
900924
.AppendLine("/// Returns the entire string as an array of characters.")

tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringOfStringValue_GeneratesAllInterfacesAndConverters#StringOfStringValue.g.verified.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ public string this[Range range]
155155
[MethodImpl(MethodImplOptions.AggressiveInlining)]
156156
public string Substring(int startIndex) => _value.Substring(startIndex);
157157

158+
/// <summary>
159+
/// Checks if the specified value is contained within the current instance.
160+
/// </summary>
161+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
162+
public bool Contains(string value) => _value.Contains(value);
163+
164+
/// <summary>
165+
/// Determines whether a specified string is a prefix of the current instance.
166+
/// </summary>
167+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
168+
public bool StartsWith(string value) => _value.StartsWith(value);
169+
170+
/// <summary>
171+
/// Determines whether a specified string is a suffix of the current instance.
172+
/// </summary>
173+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
174+
public bool EndsWith(string value) => _value.EndsWith(value);
175+
158176
/// <summary>
159177
/// Returns the entire string as an array of characters.
160178
/// </summary>

tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringOfStringValue_GeneratesAllInterfacesAndConverters#StringValue.g.verified.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ public string this[Range range]
155155
[MethodImpl(MethodImplOptions.AggressiveInlining)]
156156
public string Substring(int startIndex) => _value.Substring(startIndex);
157157

158+
/// <summary>
159+
/// Checks if the specified value is contained within the current instance.
160+
/// </summary>
161+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
162+
public bool Contains(string value) => _value.Contains(value);
163+
164+
/// <summary>
165+
/// Determines whether a specified string is a prefix of the current instance.
166+
/// </summary>
167+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
168+
public bool StartsWith(string value) => _value.StartsWith(value);
169+
170+
/// <summary>
171+
/// Determines whether a specified string is a suffix of the current instance.
172+
/// </summary>
173+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
174+
public bool EndsWith(string value) => _value.EndsWith(value);
175+
158176
/// <summary>
159177
/// Returns the entire string as an array of characters.
160178
/// </summary>

tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_GeneratesAllInterfacesAndConverters#StringValue.g.verified.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ public string this[Range range]
155155
[MethodImpl(MethodImplOptions.AggressiveInlining)]
156156
public string Substring(int startIndex) => _value.Substring(startIndex);
157157

158+
/// <summary>
159+
/// Checks if the specified value is contained within the current instance.
160+
/// </summary>
161+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
162+
public bool Contains(string value) => _value.Contains(value);
163+
164+
/// <summary>
165+
/// Determines whether a specified string is a prefix of the current instance.
166+
/// </summary>
167+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
168+
public bool StartsWith(string value) => _value.StartsWith(value);
169+
170+
/// <summary>
171+
/// Determines whether a specified string is a suffix of the current instance.
172+
/// </summary>
173+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
174+
public bool EndsWith(string value) => _value.EndsWith(value);
175+
158176
/// <summary>
159177
/// Returns the entire string as an array of characters.
160178
/// </summary>

tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_GeneratesAllInterfacesAndConvertersForInternalClass#InternalStringValue.g.verified.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ public string this[Range range]
155155
[MethodImpl(MethodImplOptions.AggressiveInlining)]
156156
public string Substring(int startIndex) => _value.Substring(startIndex);
157157

158+
/// <summary>
159+
/// Checks if the specified value is contained within the current instance.
160+
/// </summary>
161+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
162+
public bool Contains(string value) => _value.Contains(value);
163+
164+
/// <summary>
165+
/// Determines whether a specified string is a prefix of the current instance.
166+
/// </summary>
167+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
168+
public bool StartsWith(string value) => _value.StartsWith(value);
169+
170+
/// <summary>
171+
/// Determines whether a specified string is a suffix of the current instance.
172+
/// </summary>
173+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
174+
public bool EndsWith(string value) => _value.EndsWith(value);
175+
158176
/// <summary>
159177
/// Returns the entire string as an array of characters.
160178
/// </summary>

0 commit comments

Comments
 (0)