65 lines
1.6 KiB
C#
65 lines
1.6 KiB
C#
// Copyright (c) 2023 schick Informatik
|
|
// Description: some helpers
|
|
//
|
|
|
|
using BreCalClient.misc.Model;
|
|
using System;
|
|
using System.ComponentModel;
|
|
|
|
namespace BreCalClient
|
|
{
|
|
public static class Extensions
|
|
{
|
|
|
|
#region Enum
|
|
|
|
/// <summary>
|
|
/// Custom participant flags
|
|
/// </summary>
|
|
[Flags]
|
|
public enum ParticipantFlag
|
|
{
|
|
[Description("allow BSMD initial info")]
|
|
ALLOW_BSMD = 1,
|
|
}
|
|
|
|
public enum SortOrder
|
|
{
|
|
SHIP_NAME,
|
|
ETA_ETD,
|
|
MODIFIED
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region public helper
|
|
|
|
public static bool IsTypeFlagSet(this Participant participant, ParticipantType flag)
|
|
{
|
|
return (participant.Type & (uint)flag) != 0;
|
|
}
|
|
|
|
public static bool IsFlagSet(this Participant participant, ParticipantFlag flag)
|
|
{
|
|
return (participant.Flags & (uint)flag) != 0;
|
|
}
|
|
|
|
public static string Truncate(this string value, int maxLength)
|
|
{
|
|
if (string.IsNullOrEmpty(value)) return value;
|
|
return value.Length <= maxLength ? value : value.Substring(0, maxLength);
|
|
}
|
|
|
|
public static string TruncateDots(this string value, int maxLength)
|
|
{
|
|
if(string.IsNullOrEmpty(value)) return value;
|
|
if (value.Length <= maxLength) return value;
|
|
if (value.Length > (maxLength + 1)) return $"{value.Substring(0, maxLength)}..";
|
|
return value.Substring(0, maxLength);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|