Ejemplo n.º 1
0
        private static IEnumerable <string> GetParametersFromCollection(System.Collections.ICollection collection, IHashCodeBuilderFactory builderFactory)
        {
            var values = new List <string>();

            if (collection == null)
            {
                return(values);
            }

            foreach (object element in collection)
            {
                if (element == null)
                {
                    continue;
                }

                if (element is System.Collections.ICollection)
                {
                    values.AddRange(GetParametersFromCollection(element as System.Collections.ICollection, builderFactory));
                    continue;
                }

                Type instanceType = element.GetType();
                var  builder      = builderFactory.CreateInstance(element.GetType()) as ReflectionHashCodeBuilder;

                if (builder != null)
                {
                    values.AddRange(GetParameters(element, builder.TargetProperties, builderFactory));
                }
            }

            return(values);
        }
Ejemplo n.º 2
0
        public static string[] GetParameters(object instance, IEnumerable <PropertyInfo> properties, IHashCodeBuilderFactory builderFactory)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            var parameterValues = new List <string>();

            foreach (PropertyInfo property in properties)
            {
                object propValue = property.GetValue(instance, null);
                if (propValue == null)
                {
                    continue;
                }

                Type propertyType = property.PropertyType;
                if (propValue is System.Collections.ICollection)
                {
                    parameterValues.AddRange(GetParametersFromCollection(propValue as System.Collections.ICollection, builderFactory));
                    continue;
                }

                if (Helpers.IsPrimitiveType(propertyType))
                {
                    parameterValues.Add(propValue.ToString());
                }
                else
                {
                    var hashCodeBuilder     = builderFactory.CreateInstance(propertyType) as ReflectionHashCodeBuilder;
                    var propValueProperties = hashCodeBuilder != null ?
                                              hashCodeBuilder.TargetProperties : HashCodeParameterAttribute.GetDemarcatedProperties(propertyType);

                    parameterValues.AddRange(GetParameters(propValue, propValueProperties, builderFactory));
                }
            }

            return(parameterValues
                   .Where(val => !string.IsNullOrEmpty(val))
                   .ToArray());
        }