System.Runtime.Serialization.Formatters.Binary.ReadObjectInfo.GetMemberTypes C# (CSharp) Method

GetMemberTypes() private method

private GetMemberTypes ( string inMemberNames, Type objectType ) : System.Type[]
inMemberNames string
objectType System.Type
return System.Type[]
        internal Type[] GetMemberTypes(string[] inMemberNames, Type objectType)
        {
            if (_isSi)
            {
                throw new SerializationException(SR.Format(SR.Serialization_ISerializableTypes, objectType));
            }

            if (_cache == null)
            {
                return null;
            }

            if (_cache._memberTypes == null)
            {
                _cache._memberTypes = new Type[_count];
                for (int i = 0; i < _count; i++)
                {
                    _cache._memberTypes[i] = GetMemberType(_cache._memberInfos[i]);
                }
            }

            bool memberMissing = false;
            if (inMemberNames.Length < _cache._memberInfos.Length)
            {
                memberMissing = true;
            }

            Type[] outMemberTypes = new Type[_cache._memberInfos.Length];
            bool isFound = false;
            for (int i = 0; i < _cache._memberInfos.Length; i++)
            {
                if (!memberMissing && inMemberNames[i].Equals(_cache._memberInfos[i].Name))
                {
                    outMemberTypes[i] = _cache._memberTypes[i];
                }
                else
                {
                    // MemberNames on wire in different order then memberInfos returned by reflection
                    isFound = false;
                    for (int j = 0; j < inMemberNames.Length; j++)
                    {
                        if (_cache._memberInfos[i].Name.Equals(inMemberNames[j]))
                        {
                            outMemberTypes[i] = _cache._memberTypes[i];
                            isFound = true;
                            break;
                        }
                    }
                    if (!isFound)
                    {
                        // A field on the type isn't found. See if the field has OptionalFieldAttribute.  We only throw
                        // when the assembly format is set appropriately.
                        if (!_isSimpleAssembly &&
                            _cache._memberInfos[i].GetCustomAttribute(typeof(OptionalFieldAttribute), inherit: false) == null)
                        {
                            throw new SerializationException(SR.Format(SR.Serialization_MissingMember, _cache._memberNames[i], objectType, typeof(OptionalFieldAttribute).FullName));
                        }
                    }
                }
            }

            return outMemberTypes;
        }

Usage Example

示例#1
0
        internal ObjectMap(string objectName, string[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, object?[] typeInformationA, int[] memberAssemIds, ObjectReader objectReader, int objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable)
        {
            _objectName       = objectName;
            _memberNames      = memberNames;
            _binaryTypeEnumA  = binaryTypeEnumA;
            _typeInformationA = typeInformationA;
            _objectReader     = objectReader;
            _objectId         = objectId;
            _assemblyInfo     = assemblyInfo;

            if (assemblyInfo == null)
            {
                throw new SerializationException(SR.Format(SR.Serialization_Assembly, objectName));
            }

            _objectType  = objectReader.GetType(assemblyInfo, objectName);
            _memberTypes = new Type[memberNames.Length];

            for (int i = 0; i < memberNames.Length; i++)
            {
                BinaryTypeConverter.TypeFromInfo(
                    binaryTypeEnumA[i], typeInformationA[i], objectReader, (BinaryAssemblyInfo?)assemIdToAssemblyTable[memberAssemIds[i]],
                    out _, out _, out Type? type, out _);
                _memberTypes[i] = type;
            }

            _objectInfo = objectReader.CreateReadObjectInfo(_objectType, memberNames, null);
            if (!_objectInfo._isSi)
            {
                _objectInfo.GetMemberTypes(memberNames, _objectInfo._objectType);  // Check version match
            }
        }
All Usage Examples Of System.Runtime.Serialization.Formatters.Binary.ReadObjectInfo::GetMemberTypes