public abstract bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal);
 public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
 {
     return(forward.__TryGetFieldMarshal(out fieldMarshal));
 }
 public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
 {
     fieldMarshal = new FieldMarshal();
     return(false);
 }
Пример #4
0
        internal static CustomAttributeData CreateMarshalAsPseudoCustomAttribute(Module module, FieldMarshal fm)
        {
            Type typeofMarshalAs     = module.universe.System_Runtime_InteropServices_MarshalAsAttribute;
            Type typeofUnmanagedType = module.universe.System_Runtime_InteropServices_UnmanagedType;
            Type typeofVarEnum       = module.universe.System_Runtime_InteropServices_VarEnum;
            Type typeofType          = module.universe.System_Type;
            List <CustomAttributeNamedArgument> named = new List <CustomAttributeNamedArgument>();

            AddNamedArgument(named, typeofMarshalAs, "ArraySubType", typeofUnmanagedType, (int)(fm.ArraySubType ?? 0));
            AddNamedArgument(named, typeofMarshalAs, "SizeParamIndex", module.universe.System_Int16, fm.SizeParamIndex ?? 0);
            AddNamedArgument(named, typeofMarshalAs, "SizeConst", module.universe.System_Int32, fm.SizeConst ?? 0);
            AddNamedArgument(named, typeofMarshalAs, "IidParameterIndex", module.universe.System_Int32, fm.IidParameterIndex ?? 0);
            AddNamedArgument(named, typeofMarshalAs, "SafeArraySubType", typeofVarEnum, (int)(fm.SafeArraySubType ?? 0));
            if (fm.SafeArrayUserDefinedSubType != null)
            {
                AddNamedArgument(named, typeofMarshalAs, "SafeArrayUserDefinedSubType", typeofType, fm.SafeArrayUserDefinedSubType);
            }
            if (fm.MarshalType != null)
            {
                AddNamedArgument(named, typeofMarshalAs, "MarshalType", module.universe.System_String, fm.MarshalType);
            }
            if (fm.MarshalTypeRef != null)
            {
                AddNamedArgument(named, typeofMarshalAs, "MarshalTypeRef", module.universe.System_Type, fm.MarshalTypeRef);
            }
            if (fm.MarshalCookie != null)
            {
                AddNamedArgument(named, typeofMarshalAs, "MarshalCookie", module.universe.System_String, fm.MarshalCookie);
            }
            ConstructorInfo constructor = typeofMarshalAs.GetPseudoCustomAttributeConstructor(typeofUnmanagedType);

            return(new CustomAttributeData(module, constructor, new object[] { (int)fm.UnmanagedType }, named));
        }
Пример #5
0
 public bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
 {
     return(FieldMarshal.ReadFieldMarshal(this.Module, GetCurrentToken(), out fieldMarshal));
 }
        internal static bool ReadFieldMarshal(Module module, int token, out FieldMarshal fm)
        {
            fm = new FieldMarshal();
            foreach (int i in module.FieldMarshal.Filter(token))
            {
                ByteReader blob = module.GetBlob(module.FieldMarshal.records[i].NativeType);
                fm.UnmanagedType = (UnmanagedType)blob.ReadCompressedUInt();
                if (fm.UnmanagedType == UnmanagedType.LPArray)
                {
                    fm.ArraySubType = (UnmanagedType)blob.ReadCompressedUInt();
                    if (fm.ArraySubType == NATIVE_TYPE_MAX)
                    {
                        fm.ArraySubType = null;
                    }
                    if (blob.Length != 0)
                    {
                        fm.SizeParamIndex = (short)blob.ReadCompressedUInt();
                        if (blob.Length != 0)
                        {
                            fm.SizeConst = blob.ReadCompressedUInt();
                            if (blob.Length != 0 && blob.ReadCompressedUInt() == 0)
                            {
                                fm.SizeParamIndex = null;
                            }
                        }
                    }
                }
                else if (fm.UnmanagedType == UnmanagedType.SafeArray)
                {
                    if (blob.Length != 0)
                    {
                        fm.SafeArraySubType = (VarEnum)blob.ReadCompressedUInt();
                        if (blob.Length != 0)
                        {
                            fm.SafeArrayUserDefinedSubType = ReadType(module, blob);
                        }
                    }
                }
                else if (fm.UnmanagedType == UnmanagedType.ByValArray)
                {
                    fm.SizeConst = blob.ReadCompressedUInt();
                    if (blob.Length != 0)
                    {
                        fm.ArraySubType = (UnmanagedType)blob.ReadCompressedUInt();
                    }
                }
                else if (fm.UnmanagedType == UnmanagedType.ByValTStr)
                {
                    fm.SizeConst = blob.ReadCompressedUInt();
                }
                else if (fm.UnmanagedType == UnmanagedType.Interface ||
                         fm.UnmanagedType == UnmanagedType.IDispatch ||
                         fm.UnmanagedType == UnmanagedType.IUnknown)
                {
                    if (blob.Length != 0)
                    {
                        fm.IidParameterIndex = blob.ReadCompressedUInt();
                    }
                }
                else if (fm.UnmanagedType == UnmanagedType_CustomMarshaler)
                {
                    blob.ReadCompressedUInt();
                    blob.ReadCompressedUInt();
                    fm.MarshalType   = ReadString(blob);
                    fm.MarshalCookie = ReadString(blob);

                    TypeNameParser parser = TypeNameParser.Parse(fm.MarshalType, false);
                    if (!parser.Error)
                    {
                        fm.MarshalTypeRef = parser.GetType(module.universe, module, false, fm.MarshalType, false, false);
                    }
                }
                return(true);
            }
            return(false);
        }