internal void AddFormatter(System.Type targetType, IConfigNodeTypeFormatter impl) { if (handlers.ContainsKey(targetType)) { handlers[targetType] = impl; return; } handlers.Add(targetType, impl); }
internal void AddFormatter(Type targetType, IConfigNodeTypeFormatter impl) { if (handlers.ContainsKey(targetType)) { Log.Verbose("ConfigNodeTypeHandler: Already have handler for type '{0}', it will be overwritten.", targetType.FullName); handlers[targetType] = impl; } else { handlers.Add(targetType, impl); } }
internal string Serialize <T>(ref T obj) { System.Type typeFromHandle = typeof(T); if (handlers.ContainsKey(typeFromHandle)) { IConfigNodeTypeFormatter configNodeTypeFormatter = handlers[typeFromHandle]; return(configNodeTypeFormatter.Serialize(obj)); } if (typeFromHandle.IsEnum) { return(obj.ToString()); } return(obj.ToString()); }
internal void AddFormatter(System.Type targetType, System.Type formatter) { try { if (!typeof(IConfigNodeTypeFormatter).IsAssignableFrom(formatter)) { return; } IConfigNodeTypeFormatter value = (IConfigNodeTypeFormatter)System.Activator.CreateInstance(formatter); if (handlers.ContainsKey(targetType)) { handlers[targetType] = value; } else { handlers.Add(targetType, value); } } catch (System.Exception ex) { Log.Debug("[ScienceAlert]:ConfigNodeTypeHandler.AddFormatter: Exception while attempting to add handler for type '{0}' (of type {1}): {2}", targetType.FullName, formatter.FullName, ex); } }