public TypeDesc GetTypeFromSerializedName(string name)
        {
            if (name == null)
            {
                return(null);
            }

            return(_module.GetTypeByCustomAttributeTypeName(name));
        }
Exemple #2
0
        public MarshalAsDescriptor ParseMarshalAsDescriptor()
        {
            Debug.Assert(_reader.RemainingBytes != 0);

            NativeTypeKind type = (NativeTypeKind)_reader.ReadByte();
            NativeTypeKind arraySubType = NativeTypeKind.Default;
            uint?          paramNum = null, numElem = null;
            string         cookie         = null;
            TypeDesc       marshallerType = null;

            switch (type)
            {
            case NativeTypeKind.Array:
            {
                if (_reader.RemainingBytes != 0)
                {
                    arraySubType = (NativeTypeKind)_reader.ReadByte();
                }

                if (_reader.RemainingBytes != 0)
                {
                    paramNum = (uint)_reader.ReadCompressedInteger();
                }

                if (_reader.RemainingBytes != 0)
                {
                    numElem = (uint)_reader.ReadCompressedInteger();
                }

                if (_reader.RemainingBytes != 0)
                {
                    int flag = _reader.ReadCompressedInteger();
                    if (flag == 0)
                    {
                        paramNum = null;         //paramNum is just a place holder so that numElem can be present
                    }
                }
            }
            break;

            case NativeTypeKind.ByValArray:
            {
                if (_reader.RemainingBytes != 0)
                {
                    numElem = (uint)_reader.ReadCompressedInteger();
                }

                if (_reader.RemainingBytes != 0)
                {
                    arraySubType = (NativeTypeKind)_reader.ReadByte();
                }
            }
            break;

            case NativeTypeKind.ByValTStr:
            {
                if (_reader.RemainingBytes != 0)
                {
                    numElem = (uint)_reader.ReadCompressedInteger();
                }
            }
            break;

            case NativeTypeKind.SafeArray:
            {
                // There's nobody to consume SafeArrays, so let's just parse the data
                // to avoid asserting later.

                // Get optional VARTYPE for the element
                if (_reader.RemainingBytes != 0)
                {
                    _reader.ReadCompressedInteger();
                }

                // VARTYPE can be followed by optional type name
                if (_reader.RemainingBytes != 0)
                {
                    _reader.ReadSerializedString();
                }
            }
            break;

            case NativeTypeKind.CustomMarshaler:
            {
                // Read typelib guid
                _reader.ReadSerializedString();

                // Read native type name
                _reader.ReadSerializedString();

                // Read managed marshaler name
                var customMarshallerTypeName = _reader.ReadSerializedString();
                marshallerType = _ecmaModule.GetTypeByCustomAttributeTypeName(customMarshallerTypeName, true);

                // Read cookie
                cookie = _reader.ReadSerializedString();
            }
            break;

            default:
                break;
            }

            Debug.Assert(_reader.RemainingBytes == 0);

            return(new MarshalAsDescriptor(type, arraySubType, paramNum, numElem, marshallerType, cookie));
        }