Lidgren.Network.NetUtility.SortMembersList C# (CSharp) Méthode

SortMembersList() static private méthode

static private SortMembersList ( System list ) : void
list System
Résultat void
		internal static void SortMembersList(System.Reflection.MemberInfo[] list)
		{
			int h;
			int j;
			System.Reflection.MemberInfo tmp;

			h = 1;
			while (h * 3 + 1 <= list.Length)
				h = 3 * h + 1;

			while (h > 0)
			{
				for (int i = h - 1; i < list.Length; i++)
				{
					tmp = list[i];
					j = i;
					while (true)
					{
						if (j >= h)
						{
							if (string.Compare(list[j - h].Name, tmp.Name, StringComparison.InvariantCulture) > 0)
							{
								list[j] = list[j - h];
								j -= h;
							}
							else
								break;
						}
						else
							break;
					}

					list[j] = tmp;
				}
				h /= 3;
			}
		}

Usage Example

        /// <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);
                }
            }
        }
All Usage Examples Of Lidgren.Network.NetUtility::SortMembersList