Skip to content

Commit

Permalink
Updated the .editorconfig file and updated all .cs files to use file-…
Browse files Browse the repository at this point in the history
…scoped namespace declarations
  • Loading branch information
abjerner committed Sep 28, 2024
1 parent 307cf42 commit 77f30dd
Show file tree
Hide file tree
Showing 43 changed files with 2,261 additions and 2,335 deletions.
8 changes: 8 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Version 1.0.7

# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

Expand Down Expand Up @@ -209,3 +211,9 @@ dotnet_naming_style.require_underscore_prefix_and_camel_case.capitalization = ca
dotnet_naming_rule.private_fields_must_begin_with_underscore_and_be_in_camel_case.symbols = private_fields
dotnet_naming_rule.private_fields_must_begin_with_underscore_and_be_in_camel_case.style = require_underscore_prefix_and_camel_case
dotnet_naming_rule.private_fields_must_begin_with_underscore_and_be_in_camel_case.severity = warning

# Prefer file-scoped namespace declarations
csharp_style_namespace_declarations = file_scoped:warning

# Don't prefer or suggest primary constructors
csharp_style_prefer_primary_constructors = false
16 changes: 7 additions & 9 deletions src/Skybrud.Umbraco.GridData/Composers/GridComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Extensions;

namespace Skybrud.Umbraco.GridData.Composers {
namespace Skybrud.Umbraco.GridData.Composers;

internal class GridComposer : IComposer {
internal class GridComposer : IComposer {

public void Compose(IUmbracoBuilder builder) {
public void Compose(IUmbracoBuilder builder) {

builder.Services.AddSingleton<GridContext>();
builder.Services.AddUnique<IGridFactory, DefaultGridFactory>();
builder.Services.AddSingleton<GridContext>();
builder.Services.AddUnique<IGridFactory, DefaultGridFactory>();

builder.GridConverters().Append<UmbracoGridConverter>();
builder.GridConverters().Append<UmbracoGridConverter>();

builder.ManifestFilters().Append<GridManifestFilter>();

}
builder.ManifestFilters().Append<GridManifestFilter>();

}

Expand Down
24 changes: 11 additions & 13 deletions src/Skybrud.Umbraco.GridData/Composers/GridComposerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@

// ReSharper disable InconsistentNaming

namespace Skybrud.Umbraco.GridData.Composers {
namespace Skybrud.Umbraco.GridData.Composers;

/// <summary>
/// Static class with extension methods for composing the grid.
/// </summary>
public static class GridComposerExtensions {

/// <summary>
/// Static class with extension methods for composing the grid.
/// Returns the current instance of <see cref="GridConverterCollectionBuilder"/>.
/// </summary>
public static class GridComposerExtensions {

/// <summary>
/// Returns the current instance of <see cref="GridConverterCollectionBuilder"/>.
/// </summary>
/// <param name="builder">The current <see cref="IUmbracoBuilder"/>.</param>
/// <returns>An instance of <see cref="GridConverterCollectionBuilder"/>.</returns>
public static GridConverterCollectionBuilder GridConverters(this IUmbracoBuilder builder) {
return builder.WithCollectionBuilder<GridConverterCollectionBuilder>();
}

/// <param name="builder">The current <see cref="IUmbracoBuilder"/>.</param>
/// <returns>An instance of <see cref="GridConverterCollectionBuilder"/>.</returns>
public static GridConverterCollectionBuilder GridConverters(this IUmbracoBuilder builder) {
return builder.WithCollectionBuilder<GridConverterCollectionBuilder>();
}

}
192 changes: 95 additions & 97 deletions src/Skybrud.Umbraco.GridData/Converters/GridConverterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,114 +8,112 @@
using Skybrud.Umbraco.GridData.Models.Values;
using Umbraco.Cms.Core.Models.PublishedContent;

namespace Skybrud.Umbraco.GridData.Converters {
namespace Skybrud.Umbraco.GridData.Converters;

/// <summary>
/// Abstract base implementation of <see cref="IGridConverter"/>.
/// </summary>
public abstract class GridConverterBase : IGridConverter {

/// <summary>
/// Abstract base implementation of <see cref="IGridConverter"/>.
/// Attemtps to get the type of the configuration object of the specified <paramref name="editor"/>.
/// </summary>
public abstract class GridConverterBase : IGridConverter {

/// <summary>
/// Attemtps to get the type of the configuration object of the specified <paramref name="editor"/>.
/// </summary>
/// <param name="editor">The editor.</param>
/// <param name="type">When this method returns, holds an instance of <see cref="Type"/> representing the type if successful; otherwise, <see langword="null"/>.</param>
/// <returns><see langword="true"/> if successful; otherwise, <see langword="false"/>.</returns>
public virtual bool TryGetConfigType(GridEditor editor, [NotNullWhen(true)] out Type? type) {
type = null;
return false;
}

/// <summary>
/// Attempts to get the type of the value of the specified <paramref name="control"/>.
/// </summary>
/// <param name="control">The control.</param>
/// <param name="type">When this method returns, holds an instance of <see cref="Type"/> representing the type if successful; otherwise, <see langword="null"/>.</param>
/// <returns><see langword="true"/> if successful; otherwise, <see langword="false"/>.</returns>
public virtual bool TryGetValueType(GridControl control, [NotNullWhen(true)] out Type? type) {
type = null;
return false;
}
/// <param name="editor">The editor.</param>
/// <param name="type">When this method returns, holds an instance of <see cref="Type"/> representing the type if successful; otherwise, <see langword="null"/>.</param>
/// <returns><see langword="true"/> if successful; otherwise, <see langword="false"/>.</returns>
public virtual bool TryGetConfigType(GridEditor editor, [NotNullWhen(true)] out Type? type) {
type = null;
return false;
}

/// <summary>
/// Converts the specified <paramref name="token"/> into an instance of <see cref="IGridControlValue"/>.
/// </summary>
/// <param name="control">A reference to the parent <see cref="GridControl"/>.</param>
/// <param name="token">The instance of <see cref="JToken"/> representing the control value.</param>
/// <param name="value">The converted control value.</param>
public virtual bool TryConvertControlValue(GridControl control, JToken token, [NotNullWhen(true)] out IGridControlValue? value) {
value = null;
return false;
}
/// <summary>
/// Attempts to get the type of the value of the specified <paramref name="control"/>.
/// </summary>
/// <param name="control">The control.</param>
/// <param name="type">When this method returns, holds an instance of <see cref="Type"/> representing the type if successful; otherwise, <see langword="null"/>.</param>
/// <returns><see langword="true"/> if successful; otherwise, <see langword="false"/>.</returns>
public virtual bool TryGetValueType(GridControl control, [NotNullWhen(true)] out Type? type) {
type = null;
return false;
}

/// <summary>
/// Converts the specified <paramref name="token"/> into an instance of <see cref="IGridEditorConfig"/>.
/// </summary>
/// <param name="editor">A reference to the parent <see cref="GridEditor"/>.</param>
/// <param name="token">The instance of <see cref="JToken"/> representing the editor config.</param>
/// <param name="config">The converted editor config.</param>
public virtual bool TryConvertEditorConfig(GridEditor editor, JToken token, [NotNullWhen(true)] out IGridEditorConfig? config) {
config = null;
return false;
}
/// <summary>
/// Converts the specified <paramref name="token"/> into an instance of <see cref="IGridControlValue"/>.
/// </summary>
/// <param name="control">A reference to the parent <see cref="GridControl"/>.</param>
/// <param name="token">The instance of <see cref="JToken"/> representing the control value.</param>
/// <param name="value">The converted control value.</param>
public virtual bool TryConvertControlValue(GridControl control, JToken token, [NotNullWhen(true)] out IGridControlValue? value) {
value = null;
return false;
}

/// <summary>
/// Writes a string representation of <paramref name="element"/> to <paramref name="writer"/>.
/// </summary>
/// <param name="context">The current grid context.</param>
/// <param name="element">The element.</param>
/// <param name="writer">The writer.</param>
/// <returns><see langword="true"/> if successful; otherwise, <see langword="false"/>.</returns>
public virtual bool TryWriteSearchableText(GridContext context, IPublishedElement element, TextWriter writer) {
return false;
}
/// <summary>
/// Converts the specified <paramref name="token"/> into an instance of <see cref="IGridEditorConfig"/>.
/// </summary>
/// <param name="editor">A reference to the parent <see cref="GridEditor"/>.</param>
/// <param name="token">The instance of <see cref="JToken"/> representing the editor config.</param>
/// <param name="config">The converted editor config.</param>
public virtual bool TryConvertEditorConfig(GridEditor editor, JToken token, [NotNullWhen(true)] out IGridEditorConfig? config) {
config = null;
return false;
}

/// <summary>
/// Attempts to check whether the specified <paramref name="value"/> represents a valid grid control value.
/// </summary>
/// <param name="value">The value to check.</param>
/// <param name="result">When this method returns, holds a boolean value indicating whether <paramref name="value"/> is valid if successful; otherwise, <see langword="false"/>.</param>
/// <returns><see langword="true"/> if successful; otherwise, <see langword="false"/>.</returns>
public virtual bool TryGetValid(IGridControlValue value, out bool result) {
result = false;
return false;
}
/// <summary>
/// Writes a string representation of <paramref name="element"/> to <paramref name="writer"/>.
/// </summary>
/// <param name="context">The current grid context.</param>
/// <param name="element">The element.</param>
/// <param name="writer">The writer.</param>
/// <returns><see langword="true"/> if successful; otherwise, <see langword="false"/>.</returns>
public virtual bool TryWriteSearchableText(GridContext context, IPublishedElement element, TextWriter writer) {
return false;
}

/// <summary>
/// Attempts to check whether the specified <paramref name="element"/> represents a valid element.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="result">When this method returns, holds a boolean value indicating whether <paramref name="element"/> is valid if successful; otherwise, <see langword="false"/>.</param>
/// <returns><see langword="true"/> if successful; otherwise, <see langword="false"/>.</returns>
public virtual bool TryGetValid(IPublishedElement element, out bool result) {
result = false;
return false;
}
/// <summary>
/// Attempts to check whether the specified <paramref name="value"/> represents a valid grid control value.
/// </summary>
/// <param name="value">The value to check.</param>
/// <param name="result">When this method returns, holds a boolean value indicating whether <paramref name="value"/> is valid if successful; otherwise, <see langword="false"/>.</param>
/// <returns><see langword="true"/> if successful; otherwise, <see langword="false"/>.</returns>
public virtual bool TryGetValid(IGridControlValue value, out bool result) {
result = false;
return false;
}

/// <summary>
/// Returns whether <paramref name="value"/> is contained in <paramref name="source"/> (case insensitive).
/// </summary>
/// <param name="source">The source string.</param>
/// <param name="value">The value to search for.</param>
/// <returns><c>true</c> if <paramref name="source"/> contains <paramref name="value"/>; otherwise <c>false</c>.</returns>
protected bool ContainsIgnoreCase(string source, string value) {
if (string.IsNullOrWhiteSpace(source)) return false;
if (string.IsNullOrWhiteSpace(value)) return false;
return CultureInfo.InvariantCulture.CompareInfo.IndexOf(source, value, CompareOptions.IgnoreCase) >= 0;
}
/// <summary>
/// Attempts to check whether the specified <paramref name="element"/> represents a valid element.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="result">When this method returns, holds a boolean value indicating whether <paramref name="element"/> is valid if successful; otherwise, <see langword="false"/>.</param>
/// <returns><see langword="true"/> if successful; otherwise, <see langword="false"/>.</returns>
public virtual bool TryGetValid(IPublishedElement element, out bool result) {
result = false;
return false;
}

/// <summary>
/// Returns whether <paramref name="value"/> is equal <paramref name="source"/> (case insensitive).
/// </summary>
/// <param name="source">The source string.</param>
/// <param name="value">The value to search for.</param>
/// <returns><c>true</c> if <paramref name="value"/> equal to <paramref name="source"/>; otherwise <c>false</c>.</returns>
protected bool EqualsIgnoreCase(string source, string value) {
if (string.IsNullOrWhiteSpace(source)) return false;
if (string.IsNullOrWhiteSpace(value)) return false;
return source.Equals(value, StringComparison.InvariantCultureIgnoreCase);
}
/// <summary>
/// Returns whether <paramref name="value"/> is contained in <paramref name="source"/> (case insensitive).
/// </summary>
/// <param name="source">The source string.</param>
/// <param name="value">The value to search for.</param>
/// <returns><c>true</c> if <paramref name="source"/> contains <paramref name="value"/>; otherwise <c>false</c>.</returns>
protected bool ContainsIgnoreCase(string source, string value) {
if (string.IsNullOrWhiteSpace(source)) return false;
if (string.IsNullOrWhiteSpace(value)) return false;
return CultureInfo.InvariantCulture.CompareInfo.IndexOf(source, value, CompareOptions.IgnoreCase) >= 0;
}

/// <summary>
/// Returns whether <paramref name="value"/> is equal <paramref name="source"/> (case insensitive).
/// </summary>
/// <param name="source">The source string.</param>
/// <param name="value">The value to search for.</param>
/// <returns><c>true</c> if <paramref name="value"/> equal to <paramref name="source"/>; otherwise <c>false</c>.</returns>
protected bool EqualsIgnoreCase(string source, string value) {
if (string.IsNullOrWhiteSpace(source)) return false;
if (string.IsNullOrWhiteSpace(value)) return false;
return source.Equals(value, StringComparison.InvariantCultureIgnoreCase);
}

}
20 changes: 9 additions & 11 deletions src/Skybrud.Umbraco.GridData/Converters/GridConverterCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
using System.Collections.Generic;
using Umbraco.Cms.Core.Composing;

namespace Skybrud.Umbraco.GridData.Converters {
namespace Skybrud.Umbraco.GridData.Converters;

/// <summary>
/// Collection of <see cref="IGridConverter"/>.
/// </summary>
public class GridConverterCollection : BuilderCollectionBase<IGridConverter> {

/// <summary>
/// Collection of <see cref="IGridConverter"/>.
/// Initializes a new converter collection based on the specified <paramref name="items"/>.
/// </summary>
public class GridConverterCollection : BuilderCollectionBase<IGridConverter> {

/// <summary>
/// Initializes a new converter collection based on the specified <paramref name="items"/>.
/// </summary>
/// <param name="items">The items to make up the collection.</param>
public GridConverterCollection(Func<IEnumerable<IGridConverter>> items) : base(items) { }

}
/// <param name="items">The items to make up the collection.</param>
public GridConverterCollection(Func<IEnumerable<IGridConverter>> items) : base(items) { }

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using Umbraco.Cms.Core.Composing;

namespace Skybrud.Umbraco.GridData.Converters {
namespace Skybrud.Umbraco.GridData.Converters;

/// <inheritdoc />
public class GridConverterCollectionBuilder : OrderedCollectionBuilderBase<GridConverterCollectionBuilder, GridConverterCollection, IGridConverter> {

/// <inheritdoc />
protected override GridConverterCollectionBuilder This => this;
/// <inheritdoc />
public class GridConverterCollectionBuilder : OrderedCollectionBuilderBase<GridConverterCollectionBuilder, GridConverterCollection, IGridConverter> {

}
/// <inheritdoc />
protected override GridConverterCollectionBuilder This => this;

}
Loading

0 comments on commit 77f30dd

Please sign in to comment.