private static void Append(this HashAlgorithm algorithm, PropertyInfo value, bool isFinalAppend = false)
        {
            algorithm.Append(PropertyPrefix);
            algorithm.AppendMemberInfo(value, AttributeBehavior.Include);
            var indexParameters = value.GetIndexParameters();

            foreach (var i in indexParameters)
            {
                algorithm.Append(i);
            }
            algorithm.Append(indexParameters.Length);

            if (value.GetMethod == null)
            {
                algorithm.Append(ExplicitNull);
            }
            else
            {
                algorithm.Append(value.GetMethod);
            }
            if (value.SetMethod == null)
            {
                algorithm.Append(ExplicitNull);
            }
            else
            {
                algorithm.Append(value.SetMethod);
            }

            algorithm.AppendType(value.PropertyType, isFinalAppend);
        }
Пример #2
0
 private void Hash(HashAlgorithm algorithm, bool isFinalAppend)
 {
     algorithm.Append(Name);
     algorithm.AppendType(Type);
     // TODO Find a way to include the serializer and deserializer in the identity hash
     //algorithm.Append(Serializer);
     //algorithm.Append(Deserializer);
     algorithm.Append(Id.Id, isFinalAppend);
 }
        private static void Append(this HashAlgorithm algorithm, MethodInfo value, bool isFinalAppend = false)
        {
            algorithm.Append(MethodPrefix);
            algorithm.AppendMemberInfo(value, AttributeBehavior.Include);
            algorithm.Append((int)value.Attributes);

            if (value.IsGenericMethod)
            {
                algorithm.Append(ExplicitTrue);
                if (value.IsGenericMethodDefinition)
                {
                    algorithm.Append(ExplicitTrue);
                }
                else
                {
                    algorithm.Append(ExplicitFalse);
                }

                var genericArguments = value.GetGenericArguments();
                foreach (var arg in genericArguments)
                {
                    algorithm.AppendType(arg);
                }
                algorithm.Append(genericArguments.Length);
            }
            else
            {
                algorithm.Append(ExplicitFalse);
            }

            var parameters = value.GetParameters();

            foreach (var p in parameters)
            {
                algorithm.Append(p);
            }
            algorithm.Append(parameters.Length);

            algorithm.AppendType(value.ReturnType, isFinalAppend);
        }
        private static void Append(this HashAlgorithm algorithm, Type value, AttributeBehavior attributeBehavior, bool isFinalAppend = false)
        {
            algorithm.Append(TypePrefix);
            if (value.IsGenericType)
            {
                algorithm.Append(ExplicitTrue);
            }
            else
            {
                algorithm.Append(ExplicitFalse);
            }
            if (value.IsGenericTypeDefinition)
            {
                algorithm.Append(ExplicitTrue);
            }
            else
            {
                algorithm.Append(ExplicitFalse);
            }

            // TODO Add more explicit type info for generic versions
            if (value.IsGenericParameter)
            {
                algorithm.Append(ExplicitTrue);
            }
            else
            {
                algorithm.Append(ExplicitFalse);
            }

            if (value.ContainsGenericParameters)
            {
                algorithm.Append(ExplicitTrue);
            }
            else
            {
                algorithm.Append(ExplicitFalse);
            }


            if (value.IsArray)
            {
                algorithm.Append(ExplicitTrue);
                algorithm.AppendType(value.GetElementType());
            }
            else
            {
                algorithm.Append(ExplicitFalse);
            }

            algorithm.AppendMemberInfo(value, attributeBehavior, isFinalAppend);
        }
        private static void Append(this HashAlgorithm algorithm, ParameterInfo value, bool isFinalAppend = false)
        {
            algorithm.Append(ParameterPrefix);
            algorithm.Append((int)value.Attributes);
            algorithm.Append(value.Name);
            algorithm.Append(value.Position);
            int attributeCount = 0;

            foreach (var a in value.GetCustomAttributes <Attribute>())
            {
                algorithm.Append(a);
                ++attributeCount;
            }
            algorithm.Append(attributeCount);
            algorithm.AppendType(value.ParameterType, isFinalAppend);
        }
        /// <summary>
        /// Calculates a hash of a Delegate object. The resulting hash can be used to validate that two different Delegate instanses
        /// are setup in the same way (meaning they have the same type of targets and in the same order).
        /// The hash value is also stable outside of the current process lifetime, so it can be used to validate saved data.
        /// </summary>
        /// <param name="algorithm"></param>
        /// <param name="value"></param>
        /// <param name="isFinalAppend"></param>
        public static void Append(this HashAlgorithm algorithm, Delegate value, bool isFinalAppend = false)
        {
            algorithm.Append(DelegatePrefix);
            var invocationList = value.GetInvocationList();

            foreach (var d in invocationList)
            {
                if (d.Target == null)
                {
                    algorithm.Append(ExplicitNull);
                }
                else
                {
                    algorithm.AppendType(d.Target.GetType());
                }
                algorithm.Append(d.Method);
            }
            algorithm.Append(invocationList.Length, isFinalAppend);
        }
 public static byte[] CalculateTypeHash(this HashAlgorithm algorithm, Type value)
 {
     algorithm.Initialize();
     algorithm.AppendType(value, true);
     return(algorithm.Hash);
 }