This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using yournamespace.Data; | |
using Microsoft.EntityFrameworkCore.Infrastructure; | |
using Microsoft.EntityFrameworkCore.Storage; | |
namespace yournamespace.Classes; | |
internal class EntityHelpers | |
{ | |
public static bool DatabaseExists() | |
{ | |
using var context = new Context(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Item> items = | |
[ | |
new() { Id = 1,Name = "100"}, | |
new() { Id = 2,Name = "100"}, | |
new() { Id = 3,Name = "100" } | |
]; | |
string json = JsonSerializer.Serialize(items, Options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static partial class Extensions | |
{ | |
/// <summary> | |
/// Paginates the elements of an <see cref="IQueryable{TSource}"/> based on the specified page number and page size. | |
/// </summary> | |
/// <typeparam name="TSource">The type of the elements of the source.</typeparam> | |
/// <param name="source">The source <see cref="IQueryable{TSource}"/> to paginate.</param> | |
/// <param name="page">The page number to retrieve. Must be greater than or equal to 1.</param> | |
/// <param name="pageSize">The number of elements per page. Must be greater than or equal to 1.</param> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DiacriticsConverter : JsonConverter<string> | |
{ | |
public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |
=> reader.GetString() ?? string.Empty; | |
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) | |
{ | |
writer.WriteStringValue(value.ReplaceDiacritics2()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#nullable enable | |
using System.Diagnostics.CodeAnalysis; | |
using System.Text.Json; | |
namespace Tinkering.Classes; | |
/// <summary> | |
/// Provides methods for serializing and deserializing objects to and from JSON format. | |
/// Base code from David McCarter | |
/// https://github.com/RealDotNetDave/dotNetTips.Spargine/blob/main/source/6/dotNetTips.Spargine.6.Core/Serialization/JsonSerialization.cs | |
/// </summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string json = | |
/*lang=json*/ | |
""" | |
[ | |
{ | |
"Id": 1, | |
"FirstName": "jose", | |
"LastName": "fernandez", | |
"BirthDate": "1985-01-01" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Customer1 | |
{ | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Category | |
{ | |
public int CategoryId { get; set; } | |
public string Name { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text.RegularExpressions; | |
namespace Your_namespace; | |
internal static partial class Extensions | |
{ | |
public static List<string> StringsBetweenQuotes(this string sender) | |
{ | |
var matches = QuotesRegex().Matches(sender); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal record RowRecord(DataGridViewRow Row, string RowItem); | |
public static class DataGridViewExtensions | |
{ | |
public static void ExportRows(this DataGridView sender, string fileName, string defaultNullValue = "(empty)") | |
{ | |
File.WriteAllLines(fileName, sender.Rows.Cast<DataGridViewRow>() | |
.Where(row => !row.IsNewRow) | |
.Select(row => new RowRecord( |
NewerOlder