DefineByValTStr() public static method

public static DefineByValTStr ( int elemCount ) : UnmanagedMarshal
elemCount int
return UnmanagedMarshal
コード例 #1
0
        internal static UnmanagedMarshal get_umarshal(CustomAttributeBuilder customBuilder, bool is_field)
        {
            byte[]        data           = customBuilder.Data;
            UnmanagedType subtype        = (UnmanagedType)0x50;      /* NATIVE_MAX */
            int           sizeConst      = -1;
            int           sizeParamIndex = -1;
            bool          hasSize        = false;
            int           value;
            int           utype;   /* the (stupid) ctor takes a short or an enum ... */
            string        marshalTypeName = null;
            Type          marshalTypeRef  = null;
            string        marshalCookie   = String.Empty;

            utype  = (int)data [2];
            utype |= ((int)data [3]) << 8;

            string first_type_name = customBuilder.Ctor.GetParameters()[0].ParameterType.FullName;
            int    pos             = 6;

            if (first_type_name == "System.Int16")
            {
                pos = 4;
            }
            int nnamed = (int)data [pos++];

            nnamed |= ((int)data [pos++]) << 8;

            for (int i = 0; i < nnamed; ++i)
            {
                int paramType;                 // What is this ?
                paramType  = (int)data [pos++];
                paramType |= ((int)data [pos++]) << 8;
                int    len        = decode_len(data, pos, out pos);
                string named_name = string_from_bytes(data, pos, len);
                pos += len;

                switch (named_name)
                {
                case "ArraySubType":
                    value   = (int)data [pos++];
                    value  |= ((int)data [pos++]) << 8;
                    value  |= ((int)data [pos++]) << 16;
                    value  |= ((int)data [pos++]) << 24;
                    subtype = (UnmanagedType)value;
                    break;

                case "SizeConst":
                    value     = (int)data [pos++];
                    value    |= ((int)data [pos++]) << 8;
                    value    |= ((int)data [pos++]) << 16;
                    value    |= ((int)data [pos++]) << 24;
                    sizeConst = value;
                    hasSize   = true;
                    break;

                case "SizeParamIndex":
                    value          = (int)data [pos++];
                    value         |= ((int)data [pos++]) << 8;
                    sizeParamIndex = value;
                    hasSize        = true;
                    break;

                case "MarshalType":
                    len             = decode_len(data, pos, out pos);
                    marshalTypeName = string_from_bytes(data, pos, len);
                    pos            += len;
                    break;

                case "MarshalTypeRef":
                    len             = decode_len(data, pos, out pos);
                    marshalTypeName = string_from_bytes(data, pos, len);
                    marshalTypeRef  = Type.GetType(marshalTypeName);
                    pos            += len;
                    break;

                case "MarshalCookie":
                    len           = decode_len(data, pos, out pos);
                    marshalCookie = string_from_bytes(data, pos, len);
                    pos          += len;
                    break;

                default:
                    len = decode_len(data, pos, out pos);
                    string_from_bytes(data, pos, len);
                    pos += len;
                    break;
                }
            }

            switch ((UnmanagedType)utype)
            {
            case UnmanagedType.LPArray:
                if (hasSize)
                {
                    return(UnmanagedMarshal.DefineLPArrayInternal(subtype, sizeConst, sizeParamIndex));
                }
                else
                {
                    return(UnmanagedMarshal.DefineLPArray(subtype));
                }

            case UnmanagedType.SafeArray:
                return(UnmanagedMarshal.DefineSafeArray(subtype));

            case UnmanagedType.ByValArray:
                return(UnmanagedMarshal.DefineByValArray(sizeConst));

            case UnmanagedType.ByValTStr:
                return(UnmanagedMarshal.DefineByValTStr(sizeConst));

            case UnmanagedType.CustomMarshaler:
                return(UnmanagedMarshal.DefineCustom(marshalTypeRef, marshalCookie, marshalTypeName, Guid.Empty));

            default:
                return(UnmanagedMarshal.DefineUnmanagedMarshal((UnmanagedType)utype));
            }
        }
コード例 #2
0
        internal static UnmanagedMarshal get_umarshal(CustomAttributeBuilder customBuilder, bool is_field)
        {
            byte[]        data           = customBuilder.Data;
            UnmanagedType subtype        = (UnmanagedType)0x50;      /* NATIVE_MAX */
            int           sizeConst      = -1;
            int           sizeParamIndex = -1;
            bool          hasSize        = false;
            int           value;
            int           utype;   /* the (stupid) ctor takes a short or an enum ... */
            string        marshalTypeName = null;
            Type          marshalTypeRef  = null;
            string        marshalCookie   = String.Empty;

            utype  = (int)data [2];
            utype |= ((int)data [3]) << 8;

            string first_type_name = GetParameters(customBuilder.Ctor) [0].ParameterType.FullName;
            int    pos             = 6;

            if (first_type_name == "System.Int16")
            {
                pos = 4;
            }
            int nnamed = (int)data [pos++];

            nnamed |= ((int)data [pos++]) << 8;

            for (int i = 0; i < nnamed; ++i)
            {
                int paramType;                 // What is this ?

                /* Skip field/property signature */
                pos++;
                /* Read type */
                paramType = ((int)data [pos++]);
                if (paramType == 0x55)
                {
                    /* enums, the value is preceeded by the type */
                    int len2 = decode_len(data, pos, out pos);
                    string_from_bytes(data, pos, len2);
                    pos += len2;
                }
                int    len        = decode_len(data, pos, out pos);
                string named_name = string_from_bytes(data, pos, len);
                pos += len;

                switch (named_name)
                {
                case "ArraySubType":
                    value   = (int)data [pos++];
                    value  |= ((int)data [pos++]) << 8;
                    value  |= ((int)data [pos++]) << 16;
                    value  |= ((int)data [pos++]) << 24;
                    subtype = (UnmanagedType)value;
                    break;

                case "SizeConst":
                    value     = (int)data [pos++];
                    value    |= ((int)data [pos++]) << 8;
                    value    |= ((int)data [pos++]) << 16;
                    value    |= ((int)data [pos++]) << 24;
                    sizeConst = value;
                    hasSize   = true;
                    break;

                case "SafeArraySubType":
                    value   = (int)data[pos++];
                    value  |= ((int)data[pos++]) << 8;
                    value  |= ((int)data[pos++]) << 16;
                    value  |= ((int)data[pos++]) << 24;
                    subtype = (UnmanagedType)value;
                    break;

                case "IidParameterIndex":
                    pos += 4;
                    break;

                case "SafeArrayUserDefinedSubType":
                    len = decode_len(data, pos, out pos);
                    string_from_bytes(data, pos, len);
                    pos += len;
                    break;

                case "SizeParamIndex":
                    value          = (int)data [pos++];
                    value         |= ((int)data [pos++]) << 8;
                    sizeParamIndex = value;
                    hasSize        = true;
                    break;

                case "MarshalType":
                    len             = decode_len(data, pos, out pos);
                    marshalTypeName = string_from_bytes(data, pos, len);
                    pos            += len;
                    break;

                case "MarshalTypeRef":
                    len             = decode_len(data, pos, out pos);
                    marshalTypeName = string_from_bytes(data, pos, len);
                    marshalTypeRef  = Type.GetType(marshalTypeName);
                    pos            += len;
                    break;

                case "MarshalCookie":
                    len           = decode_len(data, pos, out pos);
                    marshalCookie = string_from_bytes(data, pos, len);
                    pos          += len;
                    break;

                default:
                    throw new Exception("Unknown MarshalAsAttribute field: " + named_name);
                }
            }

            switch ((UnmanagedType)utype)
            {
            case UnmanagedType.LPArray:
                if (hasSize)
                {
                    return(UnmanagedMarshal.DefineLPArrayInternal(subtype, sizeConst, sizeParamIndex));
                }
                else
                {
                    return(UnmanagedMarshal.DefineLPArray(subtype));
                }

            case UnmanagedType.SafeArray:
                return(UnmanagedMarshal.DefineSafeArray(subtype));

            case UnmanagedType.ByValArray:
                if (!is_field)
                {
                    throw new ArgumentException("Specified unmanaged type is only valid on fields");
                }

                return(UnmanagedMarshal.DefineByValArray(sizeConst));

            case UnmanagedType.ByValTStr:
                return(UnmanagedMarshal.DefineByValTStr(sizeConst));

            case UnmanagedType.CustomMarshaler:
                return(UnmanagedMarshal.DefineCustom(marshalTypeRef, marshalCookie, marshalTypeName, Guid.Empty));

            default:
                return(UnmanagedMarshal.DefineUnmanagedMarshal((UnmanagedType)utype));
            }
        }
コード例 #3
0
        internal static UnmanagedMarshal get_umarshal(CustomAttributeBuilder customBuilder, bool is_field)
        {
            byte[]        array          = customBuilder.Data;
            UnmanagedType elemType       = (UnmanagedType)80;
            int           num            = -1;
            int           sizeParamIndex = -1;
            bool          flag           = false;
            string        text           = null;
            Type          typeref        = null;
            string        cookie         = string.Empty;
            int           num2           = (int)array[2];

            num2 |= (int)array[3] << 8;
            string fullName = CustomAttributeBuilder.GetParameters(customBuilder.Ctor)[0].ParameterType.FullName;
            int    num3     = 6;

            if (fullName == "System.Int16")
            {
                num3 = 4;
            }
            int num4 = (int)array[num3++];

            num4 |= (int)array[num3++] << 8;
            int i = 0;

            while (i < num4)
            {
                num3++;
                int num5 = (int)array[num3++];
                if (num5 == 85)
                {
                    int num6 = CustomAttributeBuilder.decode_len(array, num3, out num3);
                    CustomAttributeBuilder.string_from_bytes(array, num3, num6);
                    num3 += num6;
                }
                int    num7  = CustomAttributeBuilder.decode_len(array, num3, out num3);
                string text2 = CustomAttributeBuilder.string_from_bytes(array, num3, num7);
                num3 += num7;
                string text3 = text2;
                if (text3 != null)
                {
                    if (CustomAttributeBuilder.< > f__switch$map1C == null)
                    {
                        CustomAttributeBuilder.< > f__switch$map1C = new Dictionary <string, int>(9)
                        {
                            {
                                "ArraySubType",
                                0
                            },
                            {
                                "SizeConst",
                                1
                            },
                            {
                                "SafeArraySubType",
                                2
                            },
                            {
                                "IidParameterIndex",
                                3
                            },
                            {
                                "SafeArrayUserDefinedSubType",
                                4
                            },
                            {
                                "SizeParamIndex",
                                5
                            },
                            {
                                "MarshalType",
                                6
                            },
                            {
                                "MarshalTypeRef",
                                7
                            },
                            {
                                "MarshalCookie",
                                8
                            }
                        };
                    }
                    int num8;
                    if (CustomAttributeBuilder.< > f__switch$map1C.TryGetValue(text3, out num8))
                    {
                        switch (num8)
                        {
                        case 0:
                        {
                            int num9 = (int)array[num3++];
                            num9    |= (int)array[num3++] << 8;
                            num9    |= (int)array[num3++] << 16;
                            num9    |= (int)array[num3++] << 24;
                            elemType = (UnmanagedType)num9;
                            break;
                        }

                        case 1:
                        {
                            int num9 = (int)array[num3++];
                            num9 |= (int)array[num3++] << 8;
                            num9 |= (int)array[num3++] << 16;
                            num9 |= (int)array[num3++] << 24;
                            num   = num9;
                            flag  = true;
                            break;
                        }

                        case 2:
                        {
                            int num9 = (int)array[num3++];
                            num9    |= (int)array[num3++] << 8;
                            num9    |= (int)array[num3++] << 16;
                            num9    |= (int)array[num3++] << 24;
                            elemType = (UnmanagedType)num9;
                            break;
                        }

                        case 3:
                            num3 += 4;
                            break;

                        case 4:
                            num7 = CustomAttributeBuilder.decode_len(array, num3, out num3);
                            CustomAttributeBuilder.string_from_bytes(array, num3, num7);
                            num3 += num7;
                            break;

                        case 5:
                        {
                            int num9 = (int)array[num3++];
                            num9          |= (int)array[num3++] << 8;
                            sizeParamIndex = num9;
                            flag           = true;
                            break;
                        }

                        case 6:
                            num7  = CustomAttributeBuilder.decode_len(array, num3, out num3);
                            text  = CustomAttributeBuilder.string_from_bytes(array, num3, num7);
                            num3 += num7;
                            break;

                        case 7:
                            num7    = CustomAttributeBuilder.decode_len(array, num3, out num3);
                            text    = CustomAttributeBuilder.string_from_bytes(array, num3, num7);
                            typeref = Type.GetType(text);
                            num3   += num7;
                            break;

                        case 8:
                            num7   = CustomAttributeBuilder.decode_len(array, num3, out num3);
                            cookie = CustomAttributeBuilder.string_from_bytes(array, num3, num7);
                            num3  += num7;
                            break;

                        default:
                            goto IL_34F;
                        }
                        i++;
                        continue;
                    }
                }
IL_34F:
                throw new Exception("Unknown MarshalAsAttribute field: " + text2);
            }
            UnmanagedType unmanagedType = (UnmanagedType)num2;

            switch (unmanagedType)
            {
            case UnmanagedType.LPArray:
                if (flag)
                {
                    return(UnmanagedMarshal.DefineLPArrayInternal(elemType, num, sizeParamIndex));
                }
                return(UnmanagedMarshal.DefineLPArray(elemType));

            default:
                if (unmanagedType == UnmanagedType.SafeArray)
                {
                    return(UnmanagedMarshal.DefineSafeArray(elemType));
                }
                if (unmanagedType != UnmanagedType.ByValArray)
                {
                    if (unmanagedType != UnmanagedType.ByValTStr)
                    {
                        return(UnmanagedMarshal.DefineUnmanagedMarshal((UnmanagedType)num2));
                    }
                    return(UnmanagedMarshal.DefineByValTStr(num));
                }
                else
                {
                    if (!is_field)
                    {
                        throw new ArgumentException("Specified unmanaged type is only valid on fields");
                    }
                    return(UnmanagedMarshal.DefineByValArray(num));
                }
                break;

            case UnmanagedType.CustomMarshaler:
                return(UnmanagedMarshal.DefineCustom(typeref, cookie, text, Guid.Empty));
            }
        }