GetSerializableMembers() public static method

public static GetSerializableMembers ( Type type ) : System.Reflection.MemberInfo[]
type System.Type
return System.Reflection.MemberInfo[]
Esempio n. 1
0
        // Token: 0x0600506D RID: 20589 RVA: 0x0011A9FC File Offset: 0x00118BFC
        private static MemberInfo[] InternalGetSerializableMembers(RuntimeType type)
        {
            if (type.IsInterface)
            {
                return(new MemberInfo[0]);
            }
            if (!FormatterServices.CheckSerializable(type))
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", new object[]
                {
                    type.FullName,
                    type.Module.Assembly.FullName
                }));
            }
            MemberInfo[] array       = FormatterServices.GetSerializableMembers(type);
            RuntimeType  runtimeType = (RuntimeType)type.BaseType;

            if (runtimeType != null && runtimeType != (RuntimeType)typeof(object))
            {
                RuntimeType[] array2      = null;
                int           num         = 0;
                bool          parentTypes = FormatterServices.GetParentTypes(runtimeType, out array2, out num);
                if (num > 0)
                {
                    List <SerializationFieldInfo> list = new List <SerializationFieldInfo>();
                    for (int i = 0; i < num; i++)
                    {
                        runtimeType = array2[i];
                        if (!FormatterServices.CheckSerializable(runtimeType))
                        {
                            throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", new object[]
                            {
                                runtimeType.FullName,
                                runtimeType.Module.Assembly.FullName
                            }));
                        }
                        FieldInfo[] fields     = runtimeType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
                        string      namePrefix = parentTypes ? runtimeType.Name : runtimeType.FullName;
                        foreach (FieldInfo fieldInfo in fields)
                        {
                            if (!fieldInfo.IsNotSerialized)
                            {
                                list.Add(new SerializationFieldInfo((RuntimeFieldInfo)fieldInfo, namePrefix));
                            }
                        }
                    }
                    if (list != null && list.Count > 0)
                    {
                        MemberInfo[] array4 = new MemberInfo[list.Count + array.Length];
                        Array.Copy(array, array4, array.Length);
                        ((ICollection)list).CopyTo(array4, array.Length);
                        array = array4;
                    }
                }
            }
            return(array);
        }
        internal static SerializationInfo PrepareConstructorArgs(object serObj, string[] fieldNames, object[] fieldValues, out StreamingContext context)
        {
            SerializationInfo serializationInfo = null;

            if (serObj is ISerializable)
            {
                serializationInfo = new SerializationInfo(serObj.GetType(), ObjectCloneHelper.s_converter);
                for (int i = 0; i < fieldNames.Length; i++)
                {
                    if (fieldNames[i] != null)
                    {
                        serializationInfo.AddValue(fieldNames[i], fieldValues[i]);
                    }
                }
            }
            else
            {
                Hashtable hashtable = new Hashtable();
                int       j         = 0;
                int       num       = 0;
                while (j < fieldNames.Length)
                {
                    if (fieldNames[j] != null)
                    {
                        hashtable[fieldNames[j]] = fieldValues[j];
                        num++;
                    }
                    j++;
                }
                MemberInfo[] serializableMembers = FormatterServices.GetSerializableMembers(serObj.GetType());
                for (int k = 0; k < serializableMembers.Length; k++)
                {
                    string name = serializableMembers[k].Name;
                    if (!hashtable.Contains(name))
                    {
                        object[] customAttributes = serializableMembers[k].GetCustomAttributes(typeof(OptionalFieldAttribute), false);
                        if (customAttributes == null || customAttributes.Length == 0)
                        {
                            throw new SerializationException(Environment.GetResourceString("Serialization_MissingMember", new object[]
                            {
                                serializableMembers[k],
                                serObj.GetType(),
                                typeof(OptionalFieldAttribute).FullName
                            }));
                        }
                    }
                    else
                    {
                        object value = hashtable[name];
                        FormatterServices.SerializationSetValue(serializableMembers[k], serObj, value);
                    }
                }
            }
            context = ObjectCloneHelper.s_cloneContext;
            return(serializationInfo);
        }
Esempio n. 3
0
        internal static SerializationInfo PrepareConstructorArgs(object serObj, string[] fieldNames, object[] fieldValues, out StreamingContext context)
        {
            SerializationInfo info = null;

            if (serObj is ISerializable)
            {
                info = new SerializationInfo(serObj.GetType(), s_converter);
                for (int i = 0; i < fieldNames.Length; i++)
                {
                    if (fieldNames[i] != null)
                    {
                        info.AddValue(fieldNames[i], fieldValues[i]);
                    }
                }
            }
            else
            {
                Hashtable hashtable = new Hashtable();
                int       index     = 0;
                int       num3      = 0;
                while (index < fieldNames.Length)
                {
                    if (fieldNames[index] != null)
                    {
                        hashtable[fieldNames[index]] = fieldValues[index];
                        num3++;
                    }
                    index++;
                }
                MemberInfo[] serializableMembers = FormatterServices.GetSerializableMembers(serObj.GetType());
                for (int j = 0; j < serializableMembers.Length; j++)
                {
                    string name = serializableMembers[j].Name;
                    if (!hashtable.Contains(name))
                    {
                        object[] customAttributes = serializableMembers[j].GetCustomAttributes(typeof(OptionalFieldAttribute), false);
                        if ((customAttributes == null) || (customAttributes.Length == 0))
                        {
                            throw new SerializationException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_MissingMember"), new object[] { serializableMembers[j], serObj.GetType(), typeof(OptionalFieldAttribute).FullName }));
                        }
                    }
                    else
                    {
                        object obj2 = hashtable[name];
                        FormatterServices.SerializationSetValue(serializableMembers[j], serObj, obj2);
                    }
                }
            }
            context = s_cloneContext;
            return(info);
        }
Esempio n. 4
0
        internal static SerializationInfo PrepareConstructorArgs(object serObj, string[] fieldNames, object[] fieldValues, out StreamingContext context)
        {
            SerializationInfo serializationInfo = (SerializationInfo)null;

            if (serObj is ISerializable)
            {
                serializationInfo = new SerializationInfo(serObj.GetType(), ObjectCloneHelper.s_converter);
                for (int index = 0; index < fieldNames.Length; ++index)
                {
                    if (fieldNames[index] != null)
                    {
                        serializationInfo.AddValue(fieldNames[index], fieldValues[index]);
                    }
                }
            }
            else
            {
                Hashtable hashtable = new Hashtable();
                int       index1    = 0;
                int       num       = 0;
                for (; index1 < fieldNames.Length; ++index1)
                {
                    if (fieldNames[index1] != null)
                    {
                        hashtable[(object)fieldNames[index1]] = fieldValues[index1];
                        ++num;
                    }
                }
                MemberInfo[] serializableMembers = FormatterServices.GetSerializableMembers(serObj.GetType());
                for (int index2 = 0; index2 < serializableMembers.Length; ++index2)
                {
                    string name = serializableMembers[index2].Name;
                    if (!hashtable.Contains((object)name))
                    {
                        object[] customAttributes = serializableMembers[index2].GetCustomAttributes(typeof(OptionalFieldAttribute), false);
                        if (customAttributes == null || customAttributes.Length == 0)
                        {
                            throw new SerializationException(Environment.GetResourceString("Serialization_MissingMember", (object)serializableMembers[index2], (object)serObj.GetType(), (object)typeof(OptionalFieldAttribute).FullName));
                        }
                    }
                    else
                    {
                        object obj = hashtable[(object)name];
                        FormatterServices.SerializationSetValue(serializableMembers[index2], serObj, obj);
                    }
                }
            }
            context = ObjectCloneHelper.s_cloneContext;
            return(serializationInfo);
        }
Esempio n. 5
0
        private static MemberInfo[] InternalGetSerializableMembers(RuntimeType type)
        {
            if (type.IsInterface)
            {
                return(new MemberInfo[0]);
            }
            if (!FormatterServices.CheckSerializable(type))
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", (object)type.FullName, (object)type.Module.Assembly.FullName));
            }
            MemberInfo[] memberInfoArray1 = FormatterServices.GetSerializableMembers(type);
            RuntimeType  parentType       = (RuntimeType)type.BaseType;

            if (parentType != (RuntimeType)null && parentType != (RuntimeType)typeof(object))
            {
                RuntimeType[] parentTypes1    = (RuntimeType[])null;
                int           parentTypeCount = 0;
                bool          parentTypes2    = FormatterServices.GetParentTypes(parentType, out parentTypes1, out parentTypeCount);
                if (parentTypeCount > 0)
                {
                    List <SerializationFieldInfo> serializationFieldInfoList = new List <SerializationFieldInfo>();
                    for (int index = 0; index < parentTypeCount; ++index)
                    {
                        RuntimeType type1 = parentTypes1[index];
                        if (!FormatterServices.CheckSerializable(type1))
                        {
                            throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", (object)type1.FullName, (object)type1.Module.Assembly.FullName));
                        }
                        FieldInfo[] fields     = type1.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
                        string      namePrefix = parentTypes2 ? type1.Name : type1.FullName;
                        foreach (FieldInfo fieldInfo in fields)
                        {
                            if (!fieldInfo.IsNotSerialized)
                            {
                                serializationFieldInfoList.Add(new SerializationFieldInfo((RuntimeFieldInfo)fieldInfo, namePrefix));
                            }
                        }
                    }
                    if (serializationFieldInfoList != null && serializationFieldInfoList.Count > 0)
                    {
                        MemberInfo[] memberInfoArray2 = new MemberInfo[serializationFieldInfoList.Count + memberInfoArray1.Length];
                        Array.Copy((Array)memberInfoArray1, (Array)memberInfoArray2, memberInfoArray1.Length);
                        ((ICollection)serializationFieldInfoList).CopyTo((Array)memberInfoArray2, memberInfoArray1.Length);
                        memberInfoArray1 = memberInfoArray2;
                    }
                }
            }
            return(memberInfoArray1);
        }
Esempio n. 6
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static SerializationInfo PrepareConstructorArgs(object serObj, string[] fieldNames, object[] fieldValues, out StreamingContext context)
        {
            SerializationInfo si = null;

            if (serObj is ISerializable)
            {
                si = new SerializationInfo(serObj.GetType(), s_converter);

                for (int i = 0; i < fieldNames.Length; i++)
                {
                    if (fieldNames[i] != null)
                    {
                        si.AddValue(fieldNames[i], fieldValues[i]);
                    }
                }
            }
            else
            {
                // We have a case where the from object was ISerializable and to object is not
                // @

                Hashtable fields             = new Hashtable();
                int       incomingFieldIndex = 0;
                int       numIncomingFields  = 0;
                for (; incomingFieldIndex < fieldNames.Length; incomingFieldIndex++)
                {
                    if (fieldNames[incomingFieldIndex] != null)
                    {
                        fields[fieldNames[incomingFieldIndex]] = fieldValues[incomingFieldIndex];
                        numIncomingFields++;
                    }
                }

                MemberInfo[] mi = FormatterServices.GetSerializableMembers(serObj.GetType());

                for (int index = 0; index < mi.Length; index++)
                {
                    string fieldName = mi[index].Name;
                    if (!fields.Contains(fieldName))
                    {
                        // If we are missing a field value then it's not necessarily
                        // the end of the world: check whether the field is marked
                        // [OptionalField].
                        Object [] attrs = mi[index].GetCustomAttributes(typeof(OptionalFieldAttribute), false);
                        if (attrs == null || attrs.Length == 0)
                        {
                            throw new SerializationException(Environment.GetResourceString("Serialization_MissingMember",
                                                                                           mi[index],
                                                                                           serObj.GetType(),
                                                                                           typeof(OptionalFieldAttribute).FullName));
                        }
                        continue;
                    }

                    object value = fields[fieldName];

                    FormatterServices.SerializationSetValue(mi[index], serObj, value);
                }
            }

            context = s_cloneContext;
            return(si);
        }
        /// <summary>Gets all the serializable members for a class of the specified <see cref="T:System.Type" />.</summary>
        /// <returns>An array of type <see cref="T:System.Reflection.MemberInfo" /> of the non-transient, non-static members.</returns>
        /// <param name="type">The type being serialized. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="type" /> parameter is null. </exception>
        /// <exception cref="T:System.Security.SecurityException">The caller does not have the required permission. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter" />
        /// </PermissionSet>
        public static MemberInfo[] GetSerializableMembers(Type type)
        {
            StreamingContext context = new StreamingContext(StreamingContextStates.All);

            return(FormatterServices.GetSerializableMembers(type, context));
        }
Esempio n. 8
0
 public static MemberInfo[] GetSerializableMembers(Type type)
 {
     return(RuntimeFormatterServices.GetSerializableMembers(type));
 }