Skip to content

Instantly share code, notes, and snippets.

@alemik
alemik / NamedLists.cs
Last active March 5, 2025 09:39
Named Lists
public class NamedList : List<T>
{
public string Name { get; set; }
public NamedList(string name, IEnumerable<T> items) : base(items)
{
Name = name;
}
}
@alemik
alemik / UndoRedo.cs
Last active June 21, 2024 12:46
UndoRedo
// Messenger e' il Messenger del CommunityToolkit
// CommandManager
public partial class CommandManager : ObservableRecipient
{
private Stack<IStoryCommand> _undoStack = new Stack<IStoryCommand>();
private Stack<IStoryCommand> _redoStack = new Stack<IStoryCommand>();
public void ExecuteCommand(IStoryCommand command)
{
@alemik
alemik / ResetId.sql
Last active January 8, 2024 10:49
Reset Id
GO
DBCC CHECKIDENT ('NomeTabella', RESEED, N); -- N è il valore massimo dell'ultimo ID. Il prossimo record avrà ID = N+1
GO
@alemik
alemik / GenericCrudViewModel.cs
Created September 29, 2023 06:43
Generic CRUD VM
using AutoMapper;
using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
namespace YourNamespace
{
@alemik
alemik / UseServices.cs
Last active February 6, 2024 15:13
Use Services
using Microsoft.Extensions.DependencyInjection;
public static IServiceCollection UseBaseServices(this IServiceCollection services)
{
services.AddSingleton<BaseService>();
return services;
}
@alemik
alemik / GetUnique.cs
Last active September 14, 2023 09:19
Get Unique String
public static string GetUnique(IEnumerable<string> strings, string text, string separator)
{
string chk = text;
int suffix = 1;
while (strings.Contains(chk))
{
suffix++;
chk = $"{text}{separator}{suffix}";
}
@alemik
alemik / DataGridTextColumn.xaml
Created September 8, 2023 07:50
DataGridTextColumn Header MultiRow
<DataGridTextColumn
Width="50"
MinWidth="50"
Binding="{Binding PropertyName}">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style>
</DataGridTextColumn.HeaderStyle>
@alemik
alemik / WinUseDarkTheme.cs
Created February 13, 2023 10:48
Check if DarkTheme is setted in Windows
public static bool WinUseDarkTheme()
{
try
{
var theme = (int?)Registry.GetValue(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme", -1);
var response = theme == 0 ? true: false;
return response;
}
catch (Exception)
{
@alemik
alemik / OpenFile.cs
Last active February 1, 2023 08:03
Open file from process
private void OpenFile()
{
if(string.IsNullOrEmpty(FilePath)) return;
var extension = Path.GetExtension(FilePath);
bool isExcel = extension == ".xlsx" ^ extension == ".xls";
if (!isExcel) return;
try
{
using Process process= new Process();
@alemik
alemik / BaseTest.cs
Created November 30, 2022 10:41
Base Test
[TestClass]
public class TestClass1
{
[TestMethod]
public void TestClause()
{
//Arrange
string sql = @"SELECT src.id FROM Walls src";
// Act