Example #1
0
        /**
         *
         */

        /// <summary>
        /// Appends the fields and values defined by the given object of the given Class.
        /// </summary>
        /// <param name="builder">the builder to Append to</param>
        /// <param name="clazz">the class to Append details of</param>
        /// <param name="obj">the object to Append details of</param>
        /// <param name="useTransients">whether to use transient fields</param>
        private static void reflectionAppend(object obj, Type clazz, HashCodeBuilder builder, bool useTransients)
        {
            //TODO: atrosin what does it mean? f.Name.IndexOf('$')
            //TODO: atrosin //AccessibleObject.setAccessible(fields, true);

            FieldInfo[] fields =
                clazz.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                                | BindingFlags.GetField);
            //AccessibleObject.setAccessible(fields, true);
            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo f = fields[i];

                if ((f.Name.IndexOf('$') == -1) &&
                    (useTransients || !isTransient(f)) &&
                    !f.IsStatic)
                {
                    try
                    {
                        builder.Append(f.GetValue(obj));
                    } //TODO: atrosin revise for more specific exc.
                    catch (Exception e)
                    {
                        //this can't happen. Would get a Security exception instead
                        //throw a runtime exception in case the impossible happens.
                        throw new Exception("Unexpected IllegalAccessException");
                    }
                }
            }
        }
Example #2
0
        /**

         */
        /// <summary>
        /// Appends the fields and values defined by the given object of the given Class.        
        /// </summary>
        /// <param name="builder">the builder to Append to</param>
        /// <param name="clazz">the class to Append details of</param>
        /// <param name="obj">the object to Append details of</param>
        /// <param name="useTransients">whether to use transient fields</param>        
        private static void reflectionAppend(object obj, Type clazz, HashCodeBuilder builder, bool useTransients)
        {
            //TODO: atrosin what does it mean? f.Name.IndexOf('$')
            //TODO: atrosin //AccessibleObject.setAccessible(fields, true);

            FieldInfo[] fields =
                clazz.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                                | BindingFlags.GetField);
            //AccessibleObject.setAccessible(fields, true);
            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo f = fields[i];

                if ((f.Name.IndexOf('$') == -1)
                    && (useTransients || !isTransient(f))
                    && !f.IsStatic)
                {
                    try
                    {
                        builder.Append(f.GetValue(obj));
                    } //TODO: atrosin revise for more specific exc.
                    catch (Exception e)
                    {
                        //this can't happen. Would get a Security exception instead
                        //throw a runtime exception in case the impossible happens.
                        throw new Exception("Unexpected IllegalAccessException");
                    }
                }
            }
        }