private static void EnforcePrimitiveType(Type instanceType)
 {
     if (!Helpers.IsPrimitiveType(instanceType))
     {
         throw new NotSupportedException($"The type '{instanceType.AssemblyQualifiedName}' is not supported by '{typeof(PrimitiveTypeHashCodeBuilder).FullName}'");
     }
 }
Esempio 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());
        }
Esempio n. 3
0
        public IHashCodeBuilder CreateInstance(Type targetType)
        {
            if (Helpers.IsPrimitiveType(targetType)) return PrimitiveTypeHashCodeBuilder.Instance;

            return GetBuilder(targetType);
        }