SortMembersList() static private méthode

static private SortMembersList ( System list ) : void
list System
Résultat void
        /// <summary>
        /// Reads all fields with the specified binding of the object in alphabetical order using reflection
        /// </summary>
        public void ReadAllFields(object target, BindingFlags flags)
        {
            if (target == null)
            {
                return;
            }
            Type tp = target.GetType();

            FieldInfo[] fields = tp.GetFields(flags);
            NetUtility.SortMembersList(fields);

            foreach (FieldInfo fi in fields)
            {
                object value;

                // find read method
                MethodInfo readMethod;
                if (s_readMethods.TryGetValue(fi.FieldType, out readMethod))
                {
                    // read value
                    value = readMethod.Invoke(this, null);

                    // set the value
                    fi.SetValue(target, value);
                }
            }
        }
        /// <summary>
        /// Reads all fields with the specified binding of the object in alphabetical order using reflection
        /// </summary>
        public void ReadAllProperties(object target, BindingFlags flags)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            if (target == null)
            {
                return;
            }
            Type tp = target.GetType();

            PropertyInfo[] fields = tp.GetProperties(flags);
            NetUtility.SortMembersList(fields);
            foreach (PropertyInfo fi in fields)
            {
                object value;

                // find read method
                MethodInfo readMethod;
                if (s_readMethods.TryGetValue(fi.PropertyType, out readMethod))
                {
                    // read value
                    value = readMethod.Invoke(this, null);

                    // set the value
                    MethodInfo setMethod = fi.GetSetMethod((flags & BindingFlags.NonPublic) == BindingFlags.NonPublic);
                    setMethod.Invoke(target, new object[] { value });
                }
            }
        }
        /// <summary>
        /// Writes all properties with specified binding in alphabetical order using reflection
        /// </summary>
        public void WriteAllProperties(object ob, BindingFlags flags)
        {
            if (ob == null)
            {
                return;
            }
            Type tp = ob.GetType();

            PropertyInfo[] fields = tp.GetProperties(flags);
            NetUtility.SortMembersList(fields);

            foreach (PropertyInfo fi in fields)
            {
                MethodInfo getMethod = fi.GetGetMethod();
                if (getMethod != null)
                {
                    object value = getMethod.Invoke(ob, null);

                    // find the appropriate Write method
                    MethodInfo writeMethod;
                    if (s_writeMethods.TryGetValue(fi.PropertyType, out writeMethod))
                    {
                        writeMethod.Invoke(this, new object[] { value });
                    }
                }
            }
        }
        /// <summary>
        /// Writes all fields with specified binding in alphabetical order using reflection
        /// </summary>
        public void WriteAllFields(object ob, BindingFlags flags)
        {
            if (ob == null)
            {
                return;
            }
            Type tp = ob.GetType();

            FieldInfo[] fields = tp.GetFields(flags);
            NetUtility.SortMembersList(fields);

            foreach (FieldInfo fi in fields)
            {
                object value = fi.GetValue(ob);

                // find the appropriate Write method
                MethodInfo writeMethod;
                if (s_writeMethods.TryGetValue(fi.FieldType, out writeMethod))
                {
                    writeMethod.Invoke(this, new object[] { value });
                }
                else
                {
                    throw new NetException("Failed to find write method for type " + fi.FieldType);
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Reads all fields with the specified binding of the object in alphabetical order using reflection
        /// </summary>
        public void ReadAllProperties(object target, BindingFlags flags)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            Type tp = target.GetType();

            PropertyInfo[] fields = tp.GetProperties(flags);
            NetUtility.SortMembersList(fields);
            foreach (PropertyInfo fi in fields)
            {
                object value;

                // find read method
                if (s_readMethods.TryGetValue(fi.PropertyType, out var readMethod))
                {
                    // read value
                    value = readMethod.Invoke(this, null);

                    // set the value
#if UNITY_WEBPLAYER || UNITY_4_5
                    var setMethod = fi.GetSetMethod();
#else
                    var setMethod = fi.SetMethod;
#endif
                    if (setMethod != null)
                    {
                        setMethod.Invoke(target, new object[] { value });
                    }
                }
            }
        }
        /// <summary>
        /// Writes all properties with specified binding in alphabetical order using reflection
        /// </summary>
        public void WriteAllProperties(object ob, BindingFlags flags)
        {
            if (ob == null)
            {
                return;
            }
            Type tp = ob.GetType();

            PropertyInfo[] fields = tp.GetProperties(flags);
            NetUtility.SortMembersList(fields);

            foreach (PropertyInfo fi in fields)
            {
#if UNITY_WEBPLAYER || UNITY_4_5
                MethodInfo getMethod = fi.GetGetMethod();
#else
                //This must be changed to the above as this cannot be done in .Net 3.5
                //Reflection is not too fancy in 3.5
                //Previous: MethodInfo getMethod = fi.GetMethod;
                MethodInfo getMethod = fi.GetSetMethod();
#endif

                if (getMethod != null)
                {
                    object value = getMethod.Invoke(ob, null);

                    // find the appropriate Write method
                    MethodInfo writeMethod;
                    if (s_writeMethods.TryGetValue(fi.PropertyType, out writeMethod))
                    {
                        writeMethod.Invoke(this, new object[] { value });
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Reads all fields with the specified binding of the object in alphabetical order using reflection
        /// </summary>
        public void ReadAllProperties(object target, BindingFlags flags)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            Type tp = target.GetType();

            PropertyInfo[] fields = tp.GetProperties(flags);
            NetUtility.SortMembersList(fields);
            foreach (PropertyInfo fi in fields)
            {
                object value;

                // find read method
                MethodInfo readMethod;
                if (s_readMethods.TryGetValue(fi.PropertyType, out readMethod))
                {
                    // read value
                    value = readMethod.Invoke(this, null);

                    // set the value
#if UNITY_WEBPLAYER || UNITY_4_5
                    var setMethod = fi.GetSetMethod();
#else
                    //This must be changed to the above as this cannot be done in .Net 3.5
                    //Reflection is not too fancy in 3.5
                    //Previous: var setMethod = fi.SetMethod;
                    var setMethod = fi.GetSetMethod();
#endif
                    if (setMethod != null)
                    {
                        setMethod.Invoke(target, new object[] { value });
                    }
                }
            }
        }