/// <summary> /// Collect them from a given assembly. Also works for interfaces. /// </summary> static public List <Type> GetTypeChildrenTypes(Type typeSearched, System.Reflection.Assembly assembly) { List <Type> result = new List <Type>(); Type[] types; try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { string message = string.Empty; foreach (Exception subEx in ex.LoaderExceptions) { message += "{" + CommonHelper.GetExceptionMessage(subEx) + "}"; } CoreSystemMonitor.OperationError("Failed to load assembly types for [" + typeSearched.Name + ", " + assembly.GetName().Name + "] [" + CommonHelper.GetExceptionMessage(ex) + ", " + message + "]."); return(result); } catch (Exception ex) { CoreSystemMonitor.OperationError("Failed to load assembly types for [" + typeSearched.Name + ", " + assembly.GetName().Name + "] [" + CommonHelper.GetExceptionMessage(ex) + "]."); return(result); } foreach (Type type in types) { if (typeSearched.IsInterface) { List <Type> interfaces = new List <Type>(type.GetInterfaces()); if (interfaces.Contains(typeSearched)) { result.Add(type); } } else if (type.IsSubclassOf(typeSearched)) { result.Add(type); } } return(result); }
/// <summary> /// This allows parsing with taking TimeZones into the string in consideration. /// </summary> public static DateTime ParseDateTimeWithZone(string dateTime) { DateTime result = DateTime.MinValue; try { dateTime = dateTime.Trim(); if (string.IsNullOrEmpty(dateTime)) { return(result); } if (dateTime.Contains("/")) {// Some date time formats contain 2 zones like "Etc/GMT" - fix that here. dateTime = dateTime.Substring(0, dateTime.IndexOf("/")); } if (dateTime.Contains(".")) {// Some date time formats contain a dot, clear it. dateTime = dateTime.Replace(".", ""); } if (dateTime.Contains("Thur")) {// Thur occurs in some feeds and is not recognized. dateTime = dateTime.Replace("Thur", ""); } // The dateTime parameter is either local (no time // zone specified), or it has a time zone. // Use the regex to examine the last part of the // dateTime string and determine which category it falls into. Match m = Regex.Match(dateTime.Trim(), @"(\b\w{3,4}|[+-]?\d{4})$"); //Match m = Regex.Match(dateTime.Trim(), @"(\b\w{3,4})$"); if (m.Value == DateTime.Now.Year.ToString() || m.Value == (DateTime.Now.Year - 1).ToString() || m.Value == (DateTime.Now.Year - 2).ToString() || m.Value == (DateTime.Now.Year - 3).ToString()) {// Sometimes the year is passed this way and the algo confuses it with a timizing zone. m = null; } if (m == null || m.Length == 0) { //result = DateTime.Parse(dateTime); if (DateTimeHelper.TryParse(dateTime, DateTimeHelper.DateTimeFormat.USA_DATE, out result) == false) { result = DateTime.MinValue; } } else { // Date w/ time zone. m.Value holds the time zone info // (either a time zone name (e.g. PST), or the // numeric offset (e.g. -0800). result = ConvertToLocalDateTime(dateTime, m.Value); } } catch (Exception ex) { CoreSystemMonitor.OperationError("Failed to parse time.", ex); } return(result); }