Skip to content

Commit

Permalink
Added nullable.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshClose committed May 19, 2024
1 parent d2ccb61 commit d0b6e3b
Show file tree
Hide file tree
Showing 192 changed files with 13,388 additions and 13,984 deletions.
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ csharp_space_around_binary_operators = before_and_after
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_namespace_declarations = file_scoped:warning
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
Expand Down Expand Up @@ -44,6 +44,7 @@ csharp_prefer_static_local_function = true:suggestion
csharp_style_allow_embedded_statements_on_same_line_experimental = true:suggestion
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:suggestion
csharp_style_prefer_primary_constructors = true:suggestion

[*.yml]
indent_style = space
Expand Down
104 changes: 49 additions & 55 deletions src/CsvHelper/ArrayHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,71 @@
// This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
// See LICENSE.txt for details or visit http://www.opensource.org/licenses/ms-pl.html for MS-PL and http://opensource.org/licenses/Apache-2.0 for Apache 2.0.
// https://github.com/JoshClose/CsvHelper
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace CsvHelper
namespace CsvHelper;

/// <summary>
/// Methods to help with arrays.
/// </summary>
public static class ArrayHelper
{
/// <summary>
/// Methods to help with arrays.
/// Trims the characters off the start and end of the buffer
/// by updating the start and length arguments.
/// </summary>
public static class ArrayHelper
{
/// <summary>
/// Trims the characters off the start and end of the buffer
/// by updating the start and length arguments.
/// </summary>
/// <param name="buffer">The buffer.</param>
/// <param name="start">The start.</param>
/// <param name="length">The length.</param>
/// <param name="trimChars">The characters to trim.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Trim(char[] buffer, ref int start, ref int length, char[] trimChars)
/// <param name="buffer">The buffer.</param>
/// <param name="start">The start.</param>
/// <param name="length">The length.</param>
/// <param name="trimChars">The characters to trim.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Trim(char[] buffer, ref int start, ref int length, char[] trimChars)
{
// Trim start.
for (var i = start; i < start + length; i++)
{
// Trim start.
for (var i = start; i < start + length; i++)
var c = buffer[i];
if (!Contains(trimChars, c))
{
var c = buffer[i];
if (!Contains(trimChars, c))
{
break;
}

start++;
length--;
break;
}

// Trim end.
for (var i = start + length - 1; i > start; i--)
{
var c = buffer[i];
if (!Contains(trimChars, c))
{
break;
}
start++;
length--;
}

length--;
// Trim end.
for (var i = start + length - 1; i > start; i--)
{
var c = buffer[i];
if (!Contains(trimChars, c))
{
break;
}

length--;
}
}

/// <summary>
/// Determines whether this given array contains the given character.
/// </summary>
/// <param name="array">The array to search.</param>
/// <param name="c">The character to look for.</param>
/// <returns>
/// <c>true</c> if the array contains the characters, otherwise <c>false</c>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Contains(char[] array, in char c)
/// <summary>
/// Determines whether this given array contains the given character.
/// </summary>
/// <param name="array">The array to search.</param>
/// <param name="c">The character to look for.</param>
/// <returns>
/// <c>true</c> if the array contains the characters, otherwise <c>false</c>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Contains(char[] array, in char c)
{
for (var i = 0; i < array.Length; i++)
{
for (var i = 0; i < array.Length; i++)
if (array[i] == c)
{
if (array[i] == c)
{
return true;
}
return true;
}

return false;
}

return false;
}
}
103 changes: 50 additions & 53 deletions src/CsvHelper/BadDataException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,63 @@
// This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
// See LICENSE.txt for details or visit http://www.opensource.org/licenses/ms-pl.html for MS-PL and http://opensource.org/licenses/Apache-2.0 for Apache 2.0.
// https://github.com/JoshClose/CsvHelper
using System;
namespace CsvHelper;

namespace CsvHelper
/// <summary>
/// Represents errors that occur due to bad data.
/// </summary>
[Serializable]
public class BadDataException : CsvHelperException
{
/// <summary>
/// Represents errors that occur due to bad data.
/// The full field unedited.
/// </summary>
[Serializable]
public class BadDataException : CsvHelperException
{
/// <summary>
/// The full field unedited.
/// </summary>
public readonly string Field;
public readonly string Field;

/// <summary>
/// The full row unedited.
/// </summary>
public readonly string RawRecord;
/// <summary>
/// The full row unedited.
/// </summary>
public readonly string RawRecord;

/// <summary>
/// Initializes a new instance of the <see cref="BadDataException"/> class.
/// </summary>
/// <param name="field">The full field unedited.</param>
/// <param name="rawRecord">The full row unedited.</param>
/// <param name="context">The reading context.</param>
public BadDataException(string field, string rawRecord, CsvContext context) : base(context)
{
Field = field;
RawRecord = rawRecord;
}
/// <summary>
/// Initializes a new instance of the <see cref="BadDataException"/> class.
/// </summary>
/// <param name="field">The full field unedited.</param>
/// <param name="rawRecord">The full row unedited.</param>
/// <param name="context">The reading context.</param>
public BadDataException(string field, string rawRecord, CsvContext context) : base(context)
{
Field = field;
RawRecord = rawRecord;
}

/// <summary>
/// Initializes a new instance of the <see cref="BadDataException"/> class
/// with a specified error message.
/// </summary>
/// <param name="field">The full field unedited.</param>
/// <param name="rawRecord">The full row unedited.</param>
/// <param name="context">The reading context.</param>
/// <param name="message">The message that describes the error.</param>
public BadDataException(string field, string rawRecord, CsvContext context, string message) : base(context, message)
{
Field = field;
RawRecord = rawRecord;
}
/// <summary>
/// Initializes a new instance of the <see cref="BadDataException"/> class
/// with a specified error message.
/// </summary>
/// <param name="field">The full field unedited.</param>
/// <param name="rawRecord">The full row unedited.</param>
/// <param name="context">The reading context.</param>
/// <param name="message">The message that describes the error.</param>
public BadDataException(string field, string rawRecord, CsvContext context, string message) : base(context, message)
{
Field = field;
RawRecord = rawRecord;
}

/// <summary>
/// Initializes a new instance of the <see cref="BadDataException"/> class
/// with a specified error message and a reference to the inner exception that
/// is the cause of this exception.
/// </summary>
/// <param name="field">The full field unedited.</param>
/// <param name="rawRecord">The full row unedited.</param>
/// <param name="context">The reading context.</param>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
public BadDataException(string field, string rawRecord, CsvContext context, string message, Exception innerException) : base(context, message, innerException)
{
Field = field;
RawRecord = rawRecord;
}
/// <summary>
/// Initializes a new instance of the <see cref="BadDataException"/> class
/// with a specified error message and a reference to the inner exception that
/// is the cause of this exception.
/// </summary>
/// <param name="field">The full field unedited.</param>
/// <param name="rawRecord">The full row unedited.</param>
/// <param name="context">The reading context.</param>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
public BadDataException(string field, string rawRecord, CsvContext context, string message, Exception innerException) : base(context, message, innerException)
{
Field = field;
RawRecord = rawRecord;
}
}
22 changes: 9 additions & 13 deletions src/CsvHelper/Compatibility/AsyncExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
using System.IO;
using System.Threading.Tasks;
namespace CsvHelper;

namespace CsvHelper
internal static class AsyncExtensions
{
internal static class AsyncExtensions
{
#if !(NETSTANDARD2_1_OR_GREATER || NET)
public static ValueTask DisposeAsync(this TextWriter textWriter)
public static ValueTask DisposeAsync(this TextWriter textWriter)
{
if (textWriter != null)
{
if (textWriter != null)
{
textWriter.Dispose();
}

return default;
textWriter.Dispose();
}
#endif

return default;
}
#endif
}
41 changes: 19 additions & 22 deletions src/CsvHelper/Configuration/Attributes/AllowCommentsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,31 @@
// This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
// See LICENSE.txt for details or visit http://www.opensource.org/licenses/ms-pl.html for MS-PL and http://opensource.org/licenses/Apache-2.0 for Apache 2.0.
// https://github.com/JoshClose/CsvHelper
using System;
namespace CsvHelper.Configuration.Attributes;

namespace CsvHelper.Configuration.Attributes
/// <summary>
/// A value indicating whether comments are allowed.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class AllowCommentsAttribute : Attribute, IClassMapper
{
/// <summary>
/// Gets a value indicating whether comments are allowed.
/// </summary>
public bool AllowComments { get; private set; }

/// <summary>
/// A value indicating whether comments are allowed.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class AllowCommentsAttribute : Attribute, IClassMapper
/// <param name="allowComments">The value indicating whether comments are allowed.</param>
public AllowCommentsAttribute(bool allowComments = true)
{
/// <summary>
/// Gets a value indicating whether comments are allowed.
/// </summary>
public bool AllowComments { get; private set; }

/// <summary>
/// A value indicating whether comments are allowed.
/// </summary>
/// <param name="allowComments">The value indicating whether comments are allowed.</param>
public AllowCommentsAttribute(bool allowComments = true)
{
AllowComments = allowComments;
}
AllowComments = allowComments;
}

/// <inheritdoc />
public void ApplyTo(CsvConfiguration configuration)
{
configuration.AllowComments = AllowComments;
}
/// <inheritdoc />
public void ApplyTo(CsvConfiguration configuration)
{
configuration.AllowComments = AllowComments;
}
}
Loading

0 comments on commit d0b6e3b

Please sign in to comment.