mirror of
https://github.com/dotnet/skills.git
synced 2026-09-20 09:49:54 +08:00
28 lines
759 B
C#
28 lines
759 B
C#
namespace Common;
|
|
|
|
public class Entity
|
|
{
|
|
public int Id { get; set; }
|
|
public string Name { get; set; } = string.Empty;
|
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
|
}
|
|
|
|
public class Result<T>
|
|
{
|
|
public bool Success { get; set; }
|
|
public T? Data { get; set; }
|
|
public string? Error { get; set; }
|
|
|
|
public static Result<T> Ok(T data) => new() { Success = true, Data = data };
|
|
public static Result<T> Fail(string error) => new() { Success = false, Error = error };
|
|
}
|
|
|
|
public static class StringExtensions
|
|
{
|
|
public static string Truncate(this string value, int maxLength)
|
|
{
|
|
if (string.IsNullOrEmpty(value)) return value;
|
|
return value.Length <= maxLength ? value : value[..maxLength] + "...";
|
|
}
|
|
}
|