/// <summary> /// Performs ducking with property name redirection /// </summary> /// <param name="src">Dictionary to duck</param> /// <param name="toNativeTransform">Func to transform from keys corresponding to T's interface properties to keys that are found in src</param> /// <param name="fromNativeTransform">Reverse of toNativeTransform</param> /// <param name="throwOnError">Flag to throw exception on error instead of just silent failure</param> /// <typeparam name="T">Interface to duck this dictionary as</typeparam> /// <returns>New instance of an object implementing T, passing through to the dictionary, or null if unable to duck</returns> public static T DuckAs <T>( this IDictionary <string, object> src, TransformFunc toNativeTransform, TransformFunc fromNativeTransform, bool throwOnError ) where T : class { var redirector = new RedirectingDictionary <object>( src, toNativeTransform, fromNativeTransform ); return(redirector.DuckAs <T>(throwOnError)); }
/// <summary> /// Performs fuzzy ducking with property name redirection /// </summary> /// <param name="src">Dictionary to duck</param> /// <param name="toNativeTransform">Func to transform from keys corresponding to T's interface properties to keys that are found in src</param> /// <param name="fromNativeTransform">Reverse of toNativeTransform</param> /// <param name="throwOnError">Flag to throw exception on error instead of just silent failure</param> /// <typeparam name="T">Interface to duck this dictionary as</typeparam> /// <returns>New instance of an object implementing T, passing through to the dictionary, or null if unable to duck</returns> public static T FuzzyDuckAs <T>( this NameValueCollection src, TransformFunc toNativeTransform, TransformFunc fromNativeTransform, bool throwOnError ) where T : class { var redirector = new RedirectingDictionary <object>( new DictionaryWrappingNameValueCollection(src, false), toNativeTransform, fromNativeTransform ); return(redirector.FuzzyDuckAs <T>(throwOnError)); }