internal static string[] GetCachedPropertyNames(Type objectType) { string[] propertyNames; if (MethodCaller._propertyNameCache.TryGetValue(objectType, out propertyNames)) { return(propertyNames); } lock (MethodCaller._propertyNameCache) { if (!MethodCaller._propertyNameCache.TryGetValue(objectType, out propertyNames)) { propertyNames = MethodCaller.GetPropertyNames(objectType); MethodCaller._propertyNameCache.Add(objectType, propertyNames); } } return(propertyNames); }
/// <summary> /// Copies values from the source into the target <see cref="T:System.Collections.IDictionary" />. /// </summary> /// <param name="source">The source object.</param> /// <param name="target">The target <see cref="T:System.Collections.IDictionary" />.</param> /// <param name="settings">The settings to use when copying properties.</param> public static void Copy(object source, IDictionary <string, object> target, ObjectCopierSettings settings) { string[] cachedPropertyNames; if (source == null) { throw new ArgumentNullException("source", "Source object can not be Null."); } if (target == null) { throw new ArgumentNullException("target", "Target object can not be Null."); } if (settings == null) { settings = new ObjectCopierSettings(); } if (settings.UseDynamicCache) { cachedPropertyNames = MethodCaller.GetCachedPropertyNames(source.GetType()); } else { cachedPropertyNames = MethodCaller.GetPropertyNames(source.GetType()); } foreach (string str in cachedPropertyNames) { if (!settings.IgnoreList.Contains(str)) { try { object obj2 = GetPropertyValue(source, str, settings.UseDynamicCache); target.Add(str, obj2); } catch (Exception exception) { if (!settings.SuppressExceptions) { throw new ArgumentException(string.Format("Property '{0}' copy failed.", str), exception); } } } } }