Example #1
0
        /// <inheritdoc />
        public void Assign(IReflectExtensionProperties reflector, IExtension extension, IConsumeConfiguration consumer, IHaveConversionCallbacks conversionCallbacksProvider, IHaveDefaultConversionCallback defaultConversionCallbackProvider)
        {
            Ensure.ArgumentNotNull(reflector, "reflector");
            Ensure.ArgumentNotNull(consumer, "consumer");
            Ensure.ArgumentNotNull(conversionCallbacksProvider, "conversionCallbacksProvider");
            Ensure.ArgumentNotNull(defaultConversionCallbackProvider, "defaultConversionCallbackProvider");

            var properties = reflector.Reflect(extension).ToList();
            IDictionary <string, IConversionCallback> conversionCallbacks = conversionCallbacksProvider.ConversionCallbacks;
            IConversionCallback defaultCallback = defaultConversionCallbackProvider.DefaultConversionCallback;

            foreach (KeyValuePair <string, string> keyValuePair in consumer.Configuration)
            {
                KeyValuePair <string, string> pair = keyValuePair;

                var matchedProperty = properties.SingleOrDefault(property => property.Name.Equals(pair.Key, StringComparison.OrdinalIgnoreCase));

                if (matchedProperty == null)
                {
                    continue;
                }

                IConversionCallback conversionCallback;
                if (!conversionCallbacks.TryGetValue(pair.Key, out conversionCallback))
                {
                    conversionCallback = defaultCallback;
                }

                matchedProperty.SetValue(extension, conversionCallback.Convert(pair.Value, matchedProperty), null);
            }
        }
        /// <inheritdoc />
        public void Assign(IReflectExtensionProperties reflector, IExtension extension, IConsumeConfiguration consumer, IHaveConversionCallbacks callbackProvider)
        {
            Ensure.ArgumentNotNull(reflector, "reflector");
            Ensure.ArgumentNotNull(consumer, "consumer");
            Ensure.ArgumentNotNull(callbackProvider, "callbackProvider");

            IEnumerable <PropertyInfo> properties = reflector.Reflect(extension);
            IDictionary <string, Func <string, PropertyInfo, object> > conversionCallbacks = callbackProvider.ConversionCallbacks;
            Func <string, PropertyInfo, object> defaultCallback = callbackProvider.DefaultConversionCallback;

            foreach (KeyValuePair <string, string> keyValuePair in consumer.Configuration)
            {
                KeyValuePair <string, string> pair = keyValuePair;

                var matchedProperty = properties.Where(property => property.Name.Equals(pair.Key, StringComparison.OrdinalIgnoreCase))
                                      .SingleOrDefault();

                if (matchedProperty == null)
                {
                    continue;
                }

                Func <string, PropertyInfo, object> conversionCallback;
                if (!conversionCallbacks.TryGetValue(pair.Key, out conversionCallback))
                {
                    conversionCallback = defaultCallback;
                }

                matchedProperty.SetValue(extension, conversionCallback(pair.Value, matchedProperty), null);
            }
        }
        /// <inheritdoc />
        public void Assign(IReflectExtensionProperties reflector, IExtension extension, IConsumeConfiguration consumer, IHaveConversionCallbacks callbackProvider)
        {
            Ensure.ArgumentNotNull(reflector, "reflector");
            Ensure.ArgumentNotNull(consumer, "consumer");
            Ensure.ArgumentNotNull(callbackProvider, "callbackProvider");

            IEnumerable<PropertyInfo> properties = reflector.Reflect(extension);
            IDictionary<string, Func<string, PropertyInfo, object>> conversionCallbacks = callbackProvider.ConversionCallbacks;
            Func<string, PropertyInfo, object> defaultCallback = callbackProvider.DefaultConversionCallback;

            foreach (KeyValuePair<string, string> keyValuePair in consumer.Configuration)
            {
                KeyValuePair<string, string> pair = keyValuePair;

                var matchedProperty = properties.Where(property => property.Name.Equals(pair.Key, StringComparison.OrdinalIgnoreCase))
                    .SingleOrDefault();

                if (matchedProperty == null)
                {
                    continue;
                }

                Func<string, PropertyInfo, object> conversionCallback;
                if (!conversionCallbacks.TryGetValue(pair.Key, out conversionCallback))
                {
                    conversionCallback = defaultCallback;
                }

                matchedProperty.SetValue(extension, conversionCallback(pair.Value, matchedProperty), null);
            }
        }
        /// <inheritdoc />
        public void Assign(IReflectExtensionProperties reflector, IExtension extension, IConsumeConfiguration consumer, IHaveConversionCallbacks conversionCallbacksProvider, IHaveDefaultConversionCallback defaultConversionCallbackProvider)
        {
            Ensure.ArgumentNotNull(reflector, "reflector");
            Ensure.ArgumentNotNull(consumer, "consumer");
            Ensure.ArgumentNotNull(conversionCallbacksProvider, "conversionCallbacksProvider");
            Ensure.ArgumentNotNull(defaultConversionCallbackProvider, "defaultConversionCallbackProvider");

            var properties = reflector.Reflect(extension).ToList();
            IDictionary<string, IConversionCallback> conversionCallbacks = conversionCallbacksProvider.ConversionCallbacks;
            IConversionCallback defaultCallback = defaultConversionCallbackProvider.DefaultConversionCallback;

            foreach (KeyValuePair<string, string> keyValuePair in consumer.Configuration)
            {
                KeyValuePair<string, string> pair = keyValuePair;

                var matchedProperty = properties.SingleOrDefault(property => property.Name.Equals(pair.Key, StringComparison.OrdinalIgnoreCase));

                if (matchedProperty == null)
                {
                    continue;
                }

                IConversionCallback conversionCallback;
                if (!conversionCallbacks.TryGetValue(pair.Key, out conversionCallback))
                {
                    conversionCallback = defaultCallback;
                }

                matchedProperty.SetValue(extension, conversionCallback.Convert(pair.Value, matchedProperty), null);
            }
        }