using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Eugen.ESystem { public static class RemoveLeadingTrailingCharacter { #region Version und Copyright // Version und Copyright static string dllName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen static string dllVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); static string copyright = GenerateCopyright(); //Assembly Datum und Zeit static DateTime value = AssemblyDateTime(); static string date = value.ToShortDateString(); static string time = value.ToLongTimeString(); private static DateTime AssemblyDateTime() { var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision)); //Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original) return buildDateTime; } private static string CurrentYear() { DateTime dtn = DateTime.Now; return dtn.Year.ToString(); } private static string StartYear() { string startYear = ""; if (((AssemblyCopyrightAttribute)attributes[0]).Copyright.Contains("Copyright © ")) { startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace("Copyright © ", ""); while (startYear.StartsWith(" ")) { startYear = startYear.Remove(0, 1); } startYear = startYear.Remove(startYear.IndexOf(" ")); return startYear; } else { DateTime dtn = DateTime.Now; return dtn.Year.ToString(); } } private static string GenerateCopyright() { string startYear = StartYear(); string currentYear = CurrentYear(); if (startYear == currentYear) { return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; } else { return ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace(startYear, String.Concat(startYear, "-", currentYear)); } } #endregion #region DLL-Info /// /// Contains the name of the dll file. /// public static string DllName { private set; get; } /// /// Contains the version of the dll file. /// public static string DllVersion { private set; get; } /// /// Contains the copyright notice. /// public static string Copyright { private set; get; } /// /// Contains the name-, version- and copyright-information of the dll file. /// public static string[] DllInfo { private set; get; } static private void SetDllInfo() { //Name, Version und Copyright setzen DllName = dllName; DllVersion = dllVersion; Copyright = copyright; string[] dllInfo = new string[3]; dllInfo[0] = dllName; dllInfo[1] = dllVersion; dllInfo[2] = copyright; DllInfo = dllInfo; } #endregion /// /// Removes leading or trailing characters /// static RemoveLeadingTrailingCharacter() { SetDllInfo(); } /// /// Removes leading characters /// /// String with leading characters. /// Leading character which should be removed. /// String without leading characters. public static string RemoveLeadingCharacter(string text, char[] character) { return text.TrimStart(character); } /// /// Removes trailing characters /// /// String with trailing characters. /// Trailing character which should be removed. /// String without trailing characters. public static string RemoveTrailingCharacter(string text, char[] character) { return text.TrimEnd(character); } /// /// Removes leading and trailing characters. /// /// String with leading and trailing characters. /// Character which should be removed. /// String without leading and trailing characters. public static string RemoveLeadingAndTrailingCharacter(string text, char[] character) { return text.Trim(character); } } }