public static T GetValue <T>(this ExtendedDataDictionary extendedData, string key) { if (!extendedData.ContainsKey(key)) { throw new KeyNotFoundException(String.Format("Key \"{0}\" not found in the dictionary.", key)); } object data = extendedData[key]; if (data is T) { return((T)data); } if (data is string) { try { return(JsonConvert.DeserializeObject <T>((string)data)); } catch {} } try { return(data.ToType <T>()); } catch {} return(default(T)); }
public void SetUp() { dictionary = new Dictionary <string, string> { { "key", "value" } }; extendedDataObj = new ExtendedDataDictionary(dictionary); }
public Parameter() { ExtendedData = new ExtendedDataDictionary(); GenericArguments = new GenericArguments(); }
public Module() { ExtendedData = new ExtendedDataDictionary(); }
public RequestInfo() { ExtendedData = new ExtendedDataDictionary(); Cookies = new Dictionary<string, string>(); QueryString = new Dictionary<string, string>(); }
public EnvironmentInfo() { ExtendedData = new ExtendedDataDictionary(); }
public Person(string name) { Name = name; ExtendedData = new ExtendedDataDictionary(); }
public ErrorInfo() { ExtendedData = new ExtendedDataDictionary(); StackTrace = new StackFrameCollection(); }
public Method() { ExtendedData = new ExtendedDataDictionary(); GenericArguments = new GenericArguments(); Parameters = new ParameterCollection(); }
internal static void SerializeExtendedDataObjectsToStrings(IConfigurationAndLogAccessor accessor, string id, ExtendedDataDictionary extendedData) { if (extendedData == null) { return; } // pre-serialize extended data objects so that we won't fail if we can't serialize them // also this allows us to log the exact one that caused an issue. var keys = new List <string>(extendedData.Keys); foreach (string key in keys) { if (key.AnyWildcardMatches(accessor.Configuration.DataExclusions, true)) { continue; } object data = extendedData[key]; if (data is string) { continue; } try { extendedData[key] = ModelSerializer.Current.SerializeToString(data, excludedPropertyNames: accessor.Configuration.DataExclusions); } catch (Exception ex) { accessor.Log.FormattedError(typeof(QueueManager), ex, "Unable to serialize extended data entry for '{0}' with key '{1}': {2}", id, key, ex.Message); extendedData[key] = String.Format("Unable to serialize extended data key \"{0}\" of type \"{1}\". {2}", key, extendedData[key].GetType(), ex); } } }
internal static void SerializeExtendedDataObjectsToStrings(IConfigurationAndLogAccessor accessor, string id, ExtendedDataDictionary extendedData) { if (extendedData == null) return; // pre-serialize extended data objects so that we won't fail if we can't serialize them // also this allows us to log the exact one that caused an issue. var keys = new List<string>(extendedData.Keys); foreach (string key in keys) { if (key.AnyWildcardMatches(accessor.Configuration.DataExclusions, true)) continue; object data = extendedData[key]; if (data is string) continue; try { extendedData[key] = ModelSerializer.Current.SerializeToString(data, excludedPropertyNames: accessor.Configuration.DataExclusions); } catch (Exception ex) { accessor.Log.FormattedError(typeof(QueueManager), ex, "Unable to serialize extended data entry for '{0}' with key '{1}': {2}", id, key, ex.Message); extendedData[key] = String.Format("Unable to serialize extended data key \"{0}\" of type \"{1}\". {2}", key, extendedData[key].GetType(), ex); } } }