77 lines
2.0 KiB
C#
77 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace UCS.ConfigFile
|
|
{
|
|
public static class Helpers
|
|
{
|
|
//private static readonly log4net.ILog Errorlog = log4net.LogManager.GetLogger("Error");
|
|
|
|
public static bool IsCellInteger(object value)
|
|
{
|
|
if ((int.TryParse(value.ToString(), out _)))
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
public static bool IsCellUInt16(object value)
|
|
{
|
|
if ((UInt16.TryParse(value.ToString(), out _)))
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
public static bool IsCellUInt32(object value)
|
|
{
|
|
if ((UInt32.TryParse(value.ToString(), out _)))
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
public static bool IsCellByte(object value)
|
|
{
|
|
if ((byte.TryParse(value.ToString(), out _)))
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
public static bool IsCellHexValue(object value)
|
|
{
|
|
foreach (var C in value.ToString())
|
|
{
|
|
if (Uri.IsHexDigit(C) == false)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static bool IsCellValidLogtype(string str)
|
|
{
|
|
// logtype bitmasker checken
|
|
string pattern = "^[0-1]{7,}$";
|
|
Regex reg = new Regex(pattern);
|
|
return reg.IsMatch(str);
|
|
}
|
|
|
|
public static string ReplaceSpecialChars(string str)
|
|
{
|
|
if (str.Contains("&"))
|
|
{
|
|
return str.Replace("&", "&")
|
|
.Replace("<", "<")
|
|
.Replace(">", ">")
|
|
.Replace(""", "\"")
|
|
.Replace("'", "'");
|
|
}
|
|
return str;
|
|
}
|
|
}
|
|
} |