/// <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 });
                }
            }
        }
Пример #2
0
        /// <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);
                }
            }
        }
        /// <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);
                }
            }
        }
Пример #4
0
        /// <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((flags & BindingFlags.NonPublic) == BindingFlags.NonPublic);
                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 });
                }
            }
        }