We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- namespace System.Runtime.InteropServices
- {
-
- using System;
- using System.Reflection;
-
- [AttributeUsage(AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class UnmanagedFunctionPointerAttribute : Attribute
- {
- CallingConvention m_callingConvention;
-
- public UnmanagedFunctionPointerAttribute(CallingConvention callingConvention)
- {
- m_callingConvention = callingConvention;
- }
-
- public CallingConvention CallingConvention {
- get { return m_callingConvention; }
- }
-
- public CharSet CharSet;
- public bool BestFitMapping;
- public bool ThrowOnUnmappableChar;
- public bool SetLastError;
-
- }
-
- [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Event, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class DispIdAttribute : Attribute
- {
- internal int _val;
- public DispIdAttribute(int dispId)
- {
- _val = dispId;
- }
- public int Value {
- get { return _val; }
- }
- }
-
- [Serializable()]
- [System.Runtime.InteropServices.ComVisible(true)]
- public enum ComInterfaceType
- {
- InterfaceIsDual = 0,
- InterfaceIsIUnknown = 1,
- InterfaceIsIDispatch = 2
- }
-
- [AttributeUsage(AttributeTargets.Interface, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class InterfaceTypeAttribute : Attribute
- {
- internal ComInterfaceType _val;
- public InterfaceTypeAttribute(ComInterfaceType interfaceType)
- {
- _val = interfaceType;
- }
- public InterfaceTypeAttribute(short interfaceType)
- {
- _val = (ComInterfaceType)interfaceType;
- }
- public ComInterfaceType Value {
- get { return _val; }
- }
- }
-
- [AttributeUsage(AttributeTargets.Class, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class ComDefaultInterfaceAttribute : Attribute
- {
- internal Type _val;
-
- public ComDefaultInterfaceAttribute(Type defaultInterface)
- {
- _val = defaultInterface;
- }
-
- public Type Value {
- get { return _val; }
- }
- }
-
- [Serializable()]
- [System.Runtime.InteropServices.ComVisible(true)]
- public enum ClassInterfaceType
- {
- None = 0,
- AutoDispatch = 1,
- AutoDual = 2
- }
-
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class ClassInterfaceAttribute : Attribute
- {
- internal ClassInterfaceType _val;
- public ClassInterfaceAttribute(ClassInterfaceType classInterfaceType)
- {
- _val = classInterfaceType;
-
- }
- public ClassInterfaceAttribute(short classInterfaceType)
- {
- _val = (ClassInterfaceType)classInterfaceType;
- }
- public ClassInterfaceType Value {
- get { return _val; }
- }
- }
-
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Delegate | AttributeTargets.Enum | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Property, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class ComVisibleAttribute : Attribute
- {
- internal bool _val;
- public ComVisibleAttribute(bool visibility)
- {
- _val = visibility;
- }
- public bool Value {
- get { return _val; }
- }
- }
-
- [AttributeUsage(AttributeTargets.Interface, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class TypeLibImportClassAttribute : Attribute
- {
- internal string _importClassName;
- public TypeLibImportClassAttribute(Type importClass)
- {
- _importClassName = importClass.ToString();
- }
- public string Value {
- get { return _importClassName; }
- }
- }
-
-
- [Serializable()]
- [System.Runtime.InteropServices.ComVisible(true)]
- public enum VarEnum
- {
- VT_EMPTY = 0,
- VT_NULL = 1,
- VT_I2 = 2,
- VT_I4 = 3,
- VT_R4 = 4,
- VT_R8 = 5,
- VT_CY = 6,
- VT_DATE = 7,
- VT_BSTR = 8,
- VT_ERROR = 10,
- VT_BOOL = 11,
- VT_VARIANT = 12,
- VT_UNKNOWN = 13,
- VT_DECIMAL = 14,
- VT_I1 = 16,
- VT_UI1 = 17,
- VT_UI2 = 18,
- VT_UI4 = 19,
- VT_I8 = 20,
- VT_UI8 = 21,
- VT_INT = 22,
- VT_UINT = 23,
- VT_VOID = 24,
- VT_HRESULT = 25,
- VT_PTR = 26,
- VT_SAFEARRAY = 27,
- VT_CARRAY = 28,
- VT_USERDEFINED = 29,
- VT_LPSTR = 30,
- VT_LPWSTR = 31,
- VT_RECORD = 36,
- VT_FILETIME = 64,
- VT_BLOB = 65,
- VT_STREAM = 66,
- VT_STORAGE = 67,
- VT_STREAMED_OBJECT = 68,
- VT_STORED_OBJECT = 69,
- VT_BLOB_OBJECT = 70,
- VT_CF = 71,
- VT_CLSID = 72,
- VT_VECTOR = 4096,
- VT_ARRAY = 8192,
- VT_BYREF = 16384
- }
-
- [Serializable()]
- [System.Runtime.InteropServices.ComVisible(true)]
- public enum UnmanagedType
- {
- Bool = 2,
-
- I1 = 3,
-
- U1 = 4,
-
- I2 = 5,
-
- U2 = 6,
-
- I4 = 7,
-
- U4 = 8,
-
- I8 = 9,
-
- U8 = 10,
-
- R4 = 11,
-
- R8 = 12,
-
- Currency = 15,
-
-
- LPStr = 20,
-
- LPWStr = 21,
-
- LPTStr = 22,
-
- ByValTStr = 23,
-
- IUnknown = 25,
-
-
- Struct = 27,
-
-
- ByValArray = 30,
-
- SysInt = 31,
-
- SysUInt = 32,
-
-
- FunctionPtr = 38,
-
- AsAny = 40,
-
- LPArray = 42,
-
- LPStruct = 43,
-
- CustomMarshaler = 44,
-
- Error = 45
- }
-
- [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.ReturnValue, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- unsafe public sealed class MarshalAsAttribute : Attribute
- {
- static internal Attribute GetCustomAttribute(ParameterInfo parameter)
- {
- return GetCustomAttribute(parameter.MetadataToken, parameter.Member.Module);
- }
-
- static internal bool IsDefined(ParameterInfo parameter)
- {
- return GetCustomAttribute(parameter) != null;
- }
-
- static internal Attribute GetCustomAttribute(RuntimeFieldInfo field)
- {
- return GetCustomAttribute(field.MetadataToken, field.Module);
- ;
- }
-
- static internal bool IsDefined(RuntimeFieldInfo field)
- {
- return GetCustomAttribute(field) != null;
- }
-
- static internal Attribute GetCustomAttribute(int token, Module scope)
- {
- UnmanagedType unmanagedType;
- UnmanagedType arraySubType;
- VarEnum safeArraySubType;
- int sizeParamIndex = 0;
- int sizeConst = 0;
- string marshalTypeName = null;
- string marshalCookie = null;
- string safeArrayUserDefinedTypeName = null;
- int iidParamIndex = 0;
-
- ConstArray nativeType = scope.ModuleHandle.GetMetadataImport().GetFieldMarshal(token);
-
- if (nativeType.Length == 0)
- return null;
-
- MetadataImport.GetMarshalAs(nativeType, out unmanagedType, out safeArraySubType, out safeArrayUserDefinedTypeName, out arraySubType, out sizeParamIndex, out sizeConst, out marshalTypeName, out marshalCookie, out iidParamIndex
- );
-
- Type safeArrayUserDefinedType = safeArrayUserDefinedTypeName == null || safeArrayUserDefinedTypeName.Length == 0 ? null : RuntimeTypeHandle.GetTypeByNameUsingCARules(safeArrayUserDefinedTypeName, scope);
- Type marshalTypeRef = null;
-
- try {
- marshalTypeRef = marshalTypeName == null ? null : RuntimeTypeHandle.GetTypeByNameUsingCARules(marshalTypeName, scope);
- }
- catch (System.TypeLoadException) {
-
-
- ASSERT.CONSISTENCY_CHECK(marshalTypeName != null);
- }
-
- return new MarshalAsAttribute(unmanagedType, safeArraySubType, safeArrayUserDefinedType, arraySubType, (short)sizeParamIndex, sizeConst, marshalTypeName, marshalTypeRef, marshalCookie, iidParamIndex
- );
- }
-
- internal MarshalAsAttribute(UnmanagedType val, VarEnum safeArraySubType, Type safeArrayUserDefinedSubType, UnmanagedType arraySubType, short sizeParamIndex, int sizeConst, string marshalType, Type marshalTypeRef, string marshalCookie, int iidParamIndex
- )
- {
- _val = val;
- ArraySubType = arraySubType;
- SizeParamIndex = sizeParamIndex;
- SizeConst = sizeConst;
- MarshalType = marshalType;
- MarshalTypeRef = marshalTypeRef;
- MarshalCookie = marshalCookie;
- }
-
- internal UnmanagedType _val;
- public MarshalAsAttribute(UnmanagedType unmanagedType)
- {
- _val = unmanagedType;
- }
- public MarshalAsAttribute(short unmanagedType)
- {
- _val = (UnmanagedType)unmanagedType;
- }
- public UnmanagedType Value {
- get { return _val; }
- }
-
-
-
-
- public UnmanagedType ArraySubType;
- public short SizeParamIndex;
-
- public int SizeConst;
-
-
- [System.Runtime.InteropServices.ComVisible(true)]
- public string MarshalType;
-
- [System.Runtime.InteropServices.ComVisible(true)]
- public Type MarshalTypeRef;
-
- public string MarshalCookie;
-
- }
-
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class ComImportAttribute : Attribute
- {
- static internal Attribute GetCustomAttribute(RuntimeType type)
- {
- if ((type.Attributes & TypeAttributes.Import) == 0)
- return null;
-
- return new ComImportAttribute();
- }
-
- static internal bool IsDefined(RuntimeType type)
- {
- return (type.Attributes & TypeAttributes.Import) != 0;
- }
-
- public ComImportAttribute()
- {
- }
- }
-
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct | AttributeTargets.Delegate, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class GuidAttribute : Attribute
- {
- internal string _val;
- public GuidAttribute(string guid)
- {
- _val = guid;
- }
- public string Value {
- get { return _val; }
- }
- }
-
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class PreserveSigAttribute : Attribute
- {
- static internal Attribute GetCustomAttribute(RuntimeMethodInfo method)
- {
- if ((method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) == 0)
- return null;
-
- return new PreserveSigAttribute();
- }
-
- static internal bool IsDefined(RuntimeMethodInfo method)
- {
- return (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0;
- }
-
- public PreserveSigAttribute()
- {
- }
- }
-
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class InAttribute : Attribute
- {
- static internal Attribute GetCustomAttribute(ParameterInfo parameter)
- {
- return parameter.IsIn ? new InAttribute() : null;
- }
- static internal bool IsDefined(ParameterInfo parameter)
- {
- return parameter.IsIn;
- }
-
- public InAttribute()
- {
- }
- }
-
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class OutAttribute : Attribute
- {
- static internal Attribute GetCustomAttribute(ParameterInfo parameter)
- {
- return parameter.IsOut ? new OutAttribute() : null;
- }
- static internal bool IsDefined(ParameterInfo parameter)
- {
- return parameter.IsOut;
- }
-
- public OutAttribute()
- {
- }
- }
-
- [AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class OptionalAttribute : Attribute
- {
- static internal Attribute GetCustomAttribute(ParameterInfo parameter)
- {
- return parameter.IsOptional ? new OptionalAttribute() : null;
- }
- static internal bool IsDefined(ParameterInfo parameter)
- {
- return parameter.IsOptional;
- }
-
- public OptionalAttribute()
- {
- }
- }
-
- [AttributeUsage(AttributeTargets.Method, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- unsafe public sealed class DllImportAttribute : Attribute
- {
- static internal Attribute GetCustomAttribute(RuntimeMethodInfo method)
- {
- if ((method.Attributes & MethodAttributes.PinvokeImpl) == 0)
- return null;
-
- MetadataImport scope = method.Module.ModuleHandle.GetMetadataImport();
- string entryPoint;
- string dllName = null;
- int token = method.MetadataToken;
- PInvokeAttributes flags = 0;
-
- scope.GetPInvokeMap(token, out flags, out entryPoint, out dllName);
-
- CharSet charSet = CharSet.None;
-
- switch (flags & PInvokeAttributes.CharSetMask) {
- case PInvokeAttributes.CharSetNotSpec:
- charSet = CharSet.None;
- break;
- case PInvokeAttributes.CharSetAnsi:
- charSet = CharSet.Ansi;
- break;
- case PInvokeAttributes.CharSetUnicode:
- charSet = CharSet.Unicode;
- break;
- case PInvokeAttributes.CharSetAuto:
- charSet = CharSet.Auto;
- break;
- default:
- ASSERT.UNREACHABLE();
- break;
- }
-
- CallingConvention callingConvention = CallingConvention.Cdecl;
-
- switch (flags & PInvokeAttributes.CallConvMask) {
- case PInvokeAttributes.CallConvWinapi:
- callingConvention = CallingConvention.Winapi;
- break;
- case PInvokeAttributes.CallConvCdecl:
- callingConvention = CallingConvention.Cdecl;
- break;
- case PInvokeAttributes.CallConvStdcall:
- callingConvention = CallingConvention.StdCall;
- break;
- case PInvokeAttributes.CallConvThiscall:
- callingConvention = CallingConvention.ThisCall;
- break;
- case PInvokeAttributes.CallConvFastcall:
- callingConvention = CallingConvention.FastCall;
- break;
- default:
-
- ASSERT.UNREACHABLE();
- break;
- }
-
- bool exactSpelling = (flags & PInvokeAttributes.NoMangle) != 0;
- bool setLastError = (flags & PInvokeAttributes.SupportsLastError) != 0;
- bool bestFitMapping = (flags & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
- bool throwOnUnmappableChar = (flags & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
- bool preserveSig = (method.GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0;
-
- return new DllImportAttribute(dllName, entryPoint, charSet, exactSpelling, setLastError, preserveSig, callingConvention, bestFitMapping, throwOnUnmappableChar);
- }
-
- static internal bool IsDefined(RuntimeMethodInfo method)
- {
- return (method.Attributes & MethodAttributes.PinvokeImpl) != 0;
- }
-
-
- internal DllImportAttribute(string dllName, string entryPoint, CharSet charSet, bool exactSpelling, bool setLastError, bool preserveSig, CallingConvention callingConvention, bool bestFitMapping, bool throwOnUnmappableChar)
- {
- _val = dllName;
- EntryPoint = entryPoint;
- CharSet = charSet;
- ExactSpelling = exactSpelling;
- SetLastError = setLastError;
- PreserveSig = preserveSig;
- CallingConvention = callingConvention;
- BestFitMapping = bestFitMapping;
- ThrowOnUnmappableChar = throwOnUnmappableChar;
- }
-
- internal string _val;
-
- public DllImportAttribute(string dllName)
- {
- _val = dllName;
- }
- public string Value {
- get { return _val; }
- }
-
- public string EntryPoint;
- public CharSet CharSet;
- public bool SetLastError;
- public bool ExactSpelling;
- public bool PreserveSig;
- public CallingConvention CallingConvention;
- public bool BestFitMapping;
- public bool ThrowOnUnmappableChar;
-
- }
-
- [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- unsafe public sealed class StructLayoutAttribute : Attribute
- {
- private const int DEFAULT_PACKING_SIZE = 8;
-
- static internal Attribute GetCustomAttribute(Type type)
- {
- if (!IsDefined(type))
- return null;
-
- int pack = 0;
- int size = 0;
- LayoutKind layoutKind = LayoutKind.Auto;
- switch (type.Attributes & TypeAttributes.LayoutMask) {
- case TypeAttributes.ExplicitLayout:
- layoutKind = LayoutKind.Explicit;
- break;
- case TypeAttributes.AutoLayout:
- layoutKind = LayoutKind.Auto;
- break;
- case TypeAttributes.SequentialLayout:
- layoutKind = LayoutKind.Sequential;
- break;
- default:
- ASSERT.UNREACHABLE();
- break;
- }
-
- CharSet charSet = CharSet.None;
- switch (type.Attributes & TypeAttributes.StringFormatMask) {
- case TypeAttributes.AnsiClass:
- charSet = CharSet.Ansi;
- break;
- case TypeAttributes.AutoClass:
- charSet = CharSet.Auto;
- break;
- case TypeAttributes.UnicodeClass:
- charSet = CharSet.Unicode;
- break;
- default:
- ASSERT.UNREACHABLE();
- break;
- }
- type.Module.MetadataImport.GetClassLayout(type.MetadataToken, out pack, out size);
-
-
-
-
- if (pack == 0)
- pack = DEFAULT_PACKING_SIZE;
-
- return new StructLayoutAttribute(layoutKind, pack, size, charSet);
- }
-
- static internal bool IsDefined(Type type)
- {
- if (type.IsInterface || type.HasElementType || type.IsGenericParameter)
- return false;
-
- return true;
- }
-
- internal LayoutKind _val;
-
- internal StructLayoutAttribute(LayoutKind layoutKind, int pack, int size, CharSet charSet)
- {
- _val = layoutKind;
- Pack = pack;
- Size = size;
- CharSet = charSet;
- }
-
- public StructLayoutAttribute(LayoutKind layoutKind)
- {
- _val = layoutKind;
- }
- public StructLayoutAttribute(short layoutKind)
- {
- _val = (LayoutKind)layoutKind;
- }
- public LayoutKind Value {
- get { return _val; }
- }
- public int Pack;
- public int Size;
- public CharSet CharSet;
- }
-
- [AttributeUsage(AttributeTargets.Field, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- unsafe public sealed class FieldOffsetAttribute : Attribute
- {
- static internal Attribute GetCustomAttribute(RuntimeFieldInfo field)
- {
- int fieldOffset;
-
- if (field.DeclaringType != null && field.Module.MetadataImport.GetFieldOffset(field.DeclaringType.MetadataToken, field.MetadataToken, out fieldOffset))
- return new FieldOffsetAttribute(fieldOffset);
-
- return null;
- }
-
- static internal bool IsDefined(RuntimeFieldInfo field)
- {
- return GetCustomAttribute(field) != null;
- }
-
- internal int _val;
- public FieldOffsetAttribute(int offset)
- {
- _val = offset;
- }
- public int Value {
- get { return _val; }
- }
- }
-
-
- [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class BestFitMappingAttribute : Attribute
- {
- internal bool _bestFitMapping;
-
- public BestFitMappingAttribute(bool BestFitMapping)
- {
- _bestFitMapping = BestFitMapping;
- }
-
- public bool BestFitMapping {
- get { return _bestFitMapping; }
- }
- public bool ThrowOnUnmappableChar;
- }
-
- [AttributeUsage(AttributeTargets.Module, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class DefaultCharSetAttribute : Attribute
- {
- internal CharSet _CharSet;
-
- public DefaultCharSetAttribute(CharSet charSet)
- {
- _CharSet = charSet;
- }
-
- public CharSet CharSet {
- get { return _CharSet; }
- }
- }
-
- [Obsolete("This attribute has been deprecated. Application Domains no longer respect Activation Context boundaries in IDispatch calls.", false)]
- [AttributeUsage(AttributeTargets.Assembly, Inherited = false)]
- [System.Runtime.InteropServices.ComVisible(true)]
- public sealed class SetWin32ContextInIDispatchAttribute : Attribute
- {
- public SetWin32ContextInIDispatchAttribute()
- {
- }
- }
- }