示例#1
0
        private static MemberInfo[] GetSerializableMembers(RuntimeType type)
        {
            FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            int         length = 0;

            for (int index = 0; index < fields.Length; ++index)
            {
                if ((fields[index].Attributes & FieldAttributes.NotSerialized) != FieldAttributes.NotSerialized)
                {
                    ++length;
                }
            }
            if (length == fields.Length)
            {
                return((MemberInfo[])fields);
            }
            FieldInfo[] fieldInfoArray = new FieldInfo[length];
            int         index1         = 0;

            for (int index2 = 0; index2 < fields.Length; ++index2)
            {
                if ((fields[index2].Attributes & FieldAttributes.NotSerialized) != FieldAttributes.NotSerialized)
                {
                    fieldInfoArray[index1] = fields[index2];
                    ++index1;
                }
            }
            return((MemberInfo[])fieldInfoArray);
        }
示例#2
0
        private static MemberInfo[] GetSerializableMembers(RuntimeType type)
        {
            // get the list of all fields
            FieldInfo[] fields      = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            int         countProper = 0;

            for (int i = 0; i < fields.Length; i++)
            {
                if ((fields[i].Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized)
                {
                    continue;
                }
                countProper++;
            }
            if (countProper != fields.Length)
            {
                FieldInfo[] properFields = new FieldInfo[countProper];
                countProper = 0;
                for (int i = 0; i < fields.Length; i++)
                {
                    if ((fields[i].Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized)
                    {
                        continue;
                    }
                    properFields[countProper] = fields[i];
                    countProper++;
                }
                return(properFields);
            }
            else
            {
                return(fields);
            }
        }
        private static MemberInfo[] GetSerializableMembers(RuntimeType type)
        {
            FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
            int         index  = 0;

            for (int i = 0; i < fields.Length; i++)
            {
                if ((fields[i].Attributes & FieldAttributes.NotSerialized) != FieldAttributes.NotSerialized)
                {
                    index++;
                }
            }
            if (index == fields.Length)
            {
                return(fields);
            }
            FieldInfo[] infoArray2 = new FieldInfo[index];
            index = 0;
            for (int j = 0; j < fields.Length; j++)
            {
                if ((fields[j].Attributes & FieldAttributes.NotSerialized) != FieldAttributes.NotSerialized)
                {
                    infoArray2[index] = fields[j];
                    index++;
                }
            }
            return(infoArray2);
        }
示例#4
0
        // Token: 0x0600506B RID: 20587 RVA: 0x0011A968 File Offset: 0x00118B68
        private static MemberInfo[] GetSerializableMembers(RuntimeType type)
        {
            FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            int         num    = 0;

            for (int i = 0; i < fields.Length; i++)
            {
                if ((fields[i].Attributes & FieldAttributes.NotSerialized) != FieldAttributes.NotSerialized)
                {
                    num++;
                }
            }
            if (num != fields.Length)
            {
                FieldInfo[] array = new FieldInfo[num];
                num = 0;
                for (int j = 0; j < fields.Length; j++)
                {
                    if ((fields[j].Attributes & FieldAttributes.NotSerialized) != FieldAttributes.NotSerialized)
                    {
                        array[num] = fields[j];
                        num++;
                    }
                }
                return(array);
            }
            return(fields);
        }
示例#5
0
        public override FieldInfo[] GetFields(BindingFlags bindingFlags)
        {
            if (RuntimeType == null)
            {
                return(new FieldInfo[0]);
            }

            return(RuntimeType.GetFields(bindingFlags));
        }
示例#6
0
        public override FieldInfo[] GetFields(BindingFlags bindingFlags)
        {
            if (RuntimeType == null)
            {
                return(Array.Empty <FieldInfo>());
            }

            return(RuntimeType.GetFields(bindingFlags));
        }
示例#7
0
        public FieldInfo[] GetFields()
        {
            if (RuntimeType == null)
            {
                return(new FieldInfo[0]);
            }

            return(RuntimeType.GetFields());
        }
示例#8
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);
        }
        private static MemberInfo[] InternalGetSerializableMembers(RuntimeType type)
        {
            List <SerializationFieldInfo> list = null;

            if (type.IsInterface)
            {
                return(new MemberInfo[0]);
            }
            if (!CheckSerializable(type))
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", new object[] { type.FullName, type.Module.Assembly.FullName }));
            }
            MemberInfo[] serializableMembers = GetSerializableMembers(type);
            RuntimeType  baseType            = (RuntimeType)type.BaseType;

            if ((baseType != null) && (baseType != ((RuntimeType)typeof(object))))
            {
                RuntimeType[] parentTypes     = null;
                int           parentTypeCount = 0;
                bool          flag            = GetParentTypes(baseType, out parentTypes, out parentTypeCount);
                if (parentTypeCount <= 0)
                {
                    return(serializableMembers);
                }
                list = new List <SerializationFieldInfo>();
                for (int i = 0; i < parentTypeCount; i++)
                {
                    baseType = parentTypes[i];
                    if (!CheckSerializable(baseType))
                    {
                        throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", new object[] { baseType.FullName, baseType.Module.Assembly.FullName }));
                    }
                    FieldInfo[] fields     = baseType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
                    string      namePrefix = flag ? baseType.Name : baseType.FullName;
                    foreach (FieldInfo info in fields)
                    {
                        if (!info.IsNotSerialized)
                        {
                            list.Add(new SerializationFieldInfo((RuntimeFieldInfo)info, namePrefix));
                        }
                    }
                }
                if ((list != null) && (list.Count > 0))
                {
                    MemberInfo[] destinationArray = new MemberInfo[list.Count + serializableMembers.Length];
                    Array.Copy(serializableMembers, destinationArray, serializableMembers.Length);
                    list.CopyTo(destinationArray, serializableMembers.Length);
                    serializableMembers = destinationArray;
                }
            }
            return(serializableMembers);
        }
示例#10
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);
        }
示例#11
0
        public EnumMap(
            Type type, QName qname, KnownTypeCollection knownTypes)
            : base(type, qname, knownTypes)
        {
            bool has_dc = false;

            object [] atts = RuntimeType.GetCustomAttributes(
                typeof(DataContractAttribute), false);
            if (atts.Length != 0)
            {
                has_dc = true;
            }
            flag_attr = type.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0;

            enum_members = new List <EnumMemberInfo> ();
            BindingFlags flags = BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Static;

            foreach (FieldInfo fi in RuntimeType.GetFields(flags))
            {
                string name = fi.Name;
                if (has_dc)
                {
                    EnumMemberAttribute ema =
                        GetEnumMemberAttribute(fi);
                    if (ema == null)
                    {
                        continue;
                    }

                    if (ema.Value != null)
                    {
                        name = ema.Value;
                    }
                }

                enum_members.Add(new EnumMemberInfo(name, fi.GetValue(null)));
            }
        }
示例#12
0
        public override bool Equals (Object obj) {
            BCLDebug.Perf(false, "ValueType::Equals is not fast.  "+this.GetType().FullName+" should override Equals(Object)");
            if (null==obj) {
                return false;
            }
            RuntimeType thisType = (RuntimeType)this.GetType();
            RuntimeType thatType = (RuntimeType)obj.GetType();
 
            if (thatType!=thisType) {
                return false;
            }
 
            Object thisObj = (Object)this;
            Object thisResult, thatResult;
 
            // if there are no GC references in this object we can avoid reflection 
            // and do a fast memcmp
            if (CanCompareBits(this))
                return FastEqualsCheck(thisObj, obj);
 
            FieldInfo[] thisFields = thisType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
 
            for (int i=0; i<thisFields.Length; i++) {
                thisResult = ((RtFieldInfo)thisFields[i]).UnsafeGetValue(thisObj);
                thatResult = ((RtFieldInfo)thisFields[i]).UnsafeGetValue(obj);
                
                if (thisResult == null) {
                    if (thatResult != null)
                        return false;
                }
                else
                if (!thisResult.Equals(thatResult)) {
                    return false;
                }
            }
 
            return true;
        }