Esempio n. 1
0
		/* to build a ParameterInfo for the return type of a method */
		internal ParameterInfo (Type type, MemberInfo member, UnmanagedMarshal marshalAs) {
			this.ClassImpl = type;
			this.MemberImpl = member;
			this.NameImpl = "";
			this.PositionImpl = -1;	// since parameter positions are zero-based, return type pos is -1
			this.AttrsImpl = ParameterAttributes.Retval;
			this.marshalAs = marshalAs;
		}
 public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     if (unmanagedMarshal == null)
     {
         throw new ArgumentNullException("unmanagedMarshal");
     }
     byte[] bytes = unmanagedMarshal.InternalGetBytes();
     TypeBuilder.SetFieldMarshal(this.m_methodBuilder.GetModuleBuilder().GetNativeHandle(), this.m_pdToken.Token, bytes, bytes.Length);
 }
 public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     if (unmanagedMarshal == null)
     {
         throw new ArgumentNullException("unmanagedMarshal");
     }
     byte[] array = unmanagedMarshal.InternalGetBytes();
     TypeBuilder.SetFieldMarshal(this.m_methodBuilder.GetModuleBuilder().GetNativeHandle(), this.m_pdToken.Token, array, array.Length);
 }
Esempio n. 4
0
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     this.ThrowIfGeneric();
     this.m_containingType.ThrowIfCreated();
     if (this.m_retParam == null)
     {
         this.m_retParam = new ParameterBuilder(this, 0, ParameterAttributes.None, null);
     }
     this.m_retParam.SetMarshal(unmanagedMarshal);
 }
Esempio n. 5
0
        // sizeConst and sizeParamIndex can be -1 meaning they are not specified
        internal static UnmanagedMarshal DefineLPArrayInternal(UnmanagedType elemType, int sizeConst, int sizeParamIndex)
        {
            UnmanagedMarshal res = new UnmanagedMarshal(UnmanagedType.LPArray, elemType);

            res.count     = sizeConst;
            res.param_num = sizeParamIndex;
            res.has_size  = true;

            return(res);
        }
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     if (unmanagedMarshal == null)
     {
         throw new ArgumentNullException("unmanagedMarshal");
     }
     this.m_typeBuilder.ThrowIfCreated();
     byte[] array = unmanagedMarshal.InternalGetBytes();
     TypeBuilder.SetFieldMarshal(this.m_typeBuilder.GetModuleBuilder().GetNativeHandle(), this.GetToken().Token, array, array.Length);
 }
Esempio n. 7
0
        // set FieldMarshal
        /// <include file='doc\FieldBuilder.uex' path='docs/doc[@for="FieldBuilder.SetMarshal"]/*' />
        public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
        {
            m_typeBuilder.ThrowIfCreated();

            if (unmanagedMarshal == null)
            {
                throw new ArgumentNullException("unmanagedMarshal");
            }
            byte [] ubMarshal = unmanagedMarshal.InternalGetBytes();
            TypeBuilder.InternalSetMarshalInfo(m_typeBuilder.Module, GetToken().Token, ubMarshal, ubMarshal.Length);
        }
Esempio n. 8
0
     // set FieldMarshal
     /// <include file='doc\FieldBuilder.uex' path='docs/doc[@for="FieldBuilder.SetMarshal"]/*' />
     public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
     {
         m_typeBuilder.ThrowIfCreated();        
         
         if (unmanagedMarshal == null)
         {
 			throw new ArgumentNullException("unmanagedMarshal");
         }
         byte []        ubMarshal = unmanagedMarshal.InternalGetBytes();
         TypeBuilder.InternalSetMarshalInfo(m_typeBuilder.Module, GetToken().Token, ubMarshal, ubMarshal.Length);
     }
Esempio n. 9
0
        // set ParamMarshal
        /// <include file='doc\ParameterBuilder.uex' path='docs/doc[@for="ParameterBuilder.SetMarshal"]/*' />
        public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
        {
            if (unmanagedMarshal == null)
            {
                throw new ArgumentNullException("unmanagedMarshal");
            }

            byte [] ubMarshal = unmanagedMarshal.InternalGetBytes();
            TypeBuilder.InternalSetMarshalInfo(
                m_methodBuilder.GetModule(),
                m_pdToken.Token,
                ubMarshal,
                ubMarshal.Length);
        }
Esempio n. 10
0
     // set ParamMarshal
     /// <include file='doc\ParameterBuilder.uex' path='docs/doc[@for="ParameterBuilder.SetMarshal"]/*' />
     public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
     {
         if (unmanagedMarshal == null)
         {
 			throw new ArgumentNullException("unmanagedMarshal");
         }
         
         byte []        ubMarshal = unmanagedMarshal.InternalGetBytes();        
         TypeBuilder.InternalSetMarshalInfo(
             m_methodBuilder.GetModule(),
             m_pdToken.Token, 
             ubMarshal, 
             ubMarshal.Length);
     }
Esempio n. 11
0
        public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
        {
            if (unmanagedMarshal == null)
            {
                throw new ArgumentNullException("unmanagedMarshal");
            }
            Contract.EndContractBlock();

            m_typeBuilder.ThrowIfCreated();

            byte[] ubMarshal = unmanagedMarshal.InternalGetBytes();

            TypeBuilder.SetFieldMarshal(m_typeBuilder.GetModuleBuilder().GetNativeHandle(), GetToken().Token, ubMarshal, ubMarshal.Length);
        }
Esempio n. 12
0
        public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
        {
            RejectIfCreated();

            if (customBuilder == null)
            {
                throw new ArgumentNullException("customBuilder");
            }

            string attrname = customBuilder.Ctor.ReflectedType.FullName;

            if (attrname == "System.Runtime.InteropServices.FieldOffsetAttribute")
            {
                byte[] data = customBuilder.Data;
                offset  = (int)data [2];
                offset |= ((int)data [3]) << 8;
                offset |= ((int)data [4]) << 16;
                offset |= ((int)data [5]) << 24;
                return;
            }
            else if (attrname == "System.NonSerializedAttribute")
            {
                attrs |= FieldAttributes.NotSerialized;
                return;
            }
            else if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute")
            {
                attrs |= FieldAttributes.SpecialName;
                return;
            }
            else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute")
            {
                attrs       |= FieldAttributes.HasFieldMarshal;
                marshal_info = CustomAttributeBuilder.get_umarshal(customBuilder, true);
                /* FIXME: check for errors */
                return;
            }
            if (cattrs != null)
            {
                CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
                cattrs.CopyTo(new_array, 0);
                new_array [cattrs.Length] = customBuilder;
                cattrs = new_array;
            }
            else
            {
                cattrs     = new CustomAttributeBuilder [1];
                cattrs [0] = customBuilder;
            }
        }
Esempio n. 13
0
        public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
        {
            if (unmanagedMarshal == null)
            {
                throw new ArgumentNullException("unmanagedMarshal");
            }
            byte[]        bytes        = unmanagedMarshal.InternalGetBytes();
            RuntimeModule nativeHandle = this.m_methodBuilder.GetModuleBuilder().GetNativeHandle();
            int           token        = this.m_pdToken.Token;

            byte[] ubMarshal = bytes;
            int    length    = ubMarshal.Length;

            TypeBuilder.SetFieldMarshal(nativeHandle, token, ubMarshal, length);
        }
Esempio n. 14
0
        public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
        {
            ThrowIfGeneric();

            // set Marshal info for the return type

            m_containingType.ThrowIfCreated();

            if (m_retParam == null)
            {
                m_retParam = new ParameterBuilder(this, 0, 0, null);
            }

            m_retParam.SetMarshal(unmanagedMarshal);
        }
Esempio n. 15
0
        public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
        {
            if (unmanagedMarshal == null)
            {
                throw new ArgumentNullException(nameof(unmanagedMarshal));
            }
            Contract.EndContractBlock();

            byte [] ubMarshal = unmanagedMarshal.InternalGetBytes();
            TypeBuilder.SetFieldMarshal(
                m_methodBuilder.GetModuleBuilder().GetNativeHandle(),
                m_pdToken.Token,
                ubMarshal,
                ubMarshal.Length);
        }
Esempio n. 16
0
 public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     if (unmanagedMarshal == null)
     {
         throw new ArgumentNullException("unmanagedMarshal");
     }
     Contract.EndContractBlock();
     
     byte []        ubMarshal = unmanagedMarshal.InternalGetBytes();
     TypeBuilder.SetFieldMarshal(
         m_methodBuilder.GetModuleBuilder().GetNativeHandle(),
         m_pdToken.Token, 
         ubMarshal, 
         ubMarshal.Length);
 }
Esempio n. 17
0
        // set Marshal info for the return type
        /// <include file='doc\MethodBuilder.uex' path='docs/doc[@for="MethodBuilder.SetMarshal"]/*' />
        public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
        {
            m_containingType.ThrowIfCreated();

            if (m_retParam == null)
            {
                m_retParam = new ParameterBuilder(this, 0, 0, null);
            }

            if (m_retParam == null)
            {
                m_retParam = new ParameterBuilder(this, 0, 0, null);
            }
            m_retParam.SetMarshal(unmanagedMarshal);
        }
Esempio n. 18
0
        public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
        {
            string attrname = customBuilder.Ctor.ReflectedType.FullName;

            if (attrname == "System.Runtime.InteropServices.InAttribute")
            {
                attrs |= ParameterAttributes.In;
                return;
            }
            else if (attrname == "System.Runtime.InteropServices.OutAttribute")
            {
                attrs |= ParameterAttributes.Out;
                return;
            }
            else if (attrname == "System.Runtime.InteropServices.OptionalAttribute")
            {
                attrs |= ParameterAttributes.Optional;
                return;
            }
            else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute")
            {
                attrs       |= ParameterAttributes.HasFieldMarshal;
                marshal_info = CustomAttributeBuilder.get_umarshal(customBuilder, false);
                /* FIXME: check for errors */
                return;
            }
            else if (attrname == "System.Runtime.InteropServices.DefaultParameterValueAttribute")
            {
                /* MS.NET doesn't handle this attribute but we handle it for consistency */
                CustomAttributeBuilder.CustomAttributeInfo cinfo = CustomAttributeBuilder.decode_cattr(customBuilder);
                /* FIXME: check for type compatibility */
                SetConstant(cinfo.ctorArgs [0]);
                return;
            }

            if (cattrs != null)
            {
                CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
                cattrs.CopyTo(new_array, 0);
                new_array [cattrs.Length] = customBuilder;
                cattrs = new_array;
            }
            else
            {
                cattrs     = new CustomAttributeBuilder [1];
                cattrs [0] = customBuilder;
            }
        }
Esempio n. 19
0
 // Set the marshalling information for the return type.
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     try
     {
         type.StartSync();
         if (returnBuilder != null)
         {
             returnBuilder = new ParameterBuilder
                                 (type, this, 0, ParameterAttributes.None, null);
         }
         returnBuilder.SetMarshal(unmanagedMarshal);
     }
     finally
     {
         type.EndSync();
     }
 }
        public static UnmanagedMarshal DefineCustom(Type typeref, string cookie, string mtype, Guid id)
        {
            UnmanagedMarshal unmanagedMarshal = new UnmanagedMarshal(UnmanagedType.CustomMarshaler, UnmanagedType.CustomMarshaler);

            unmanagedMarshal.mcookie        = cookie;
            unmanagedMarshal.marshaltype    = mtype;
            unmanagedMarshal.marshaltyperef = typeref;
            if (id == Guid.Empty)
            {
                unmanagedMarshal.guid = string.Empty;
            }
            else
            {
                unmanagedMarshal.guid = id.ToString();
            }
            return(unmanagedMarshal);
        }
Esempio n. 21
0
        internal static UnmanagedMarshal DefineCustom(Type typeref, string cookie, string mtype, Guid id)
        {
            UnmanagedMarshal res = new UnmanagedMarshal(UnmanagedType.CustomMarshaler, UnmanagedType.CustomMarshaler);

            res.mcookie        = cookie;
            res.marshaltype    = mtype;
            res.marshaltyperef = typeref;
            if (id == Guid.Empty)
            {
                res.guid = String.Empty;
            }
            else
            {
                res.guid = id.ToString();
            }
            return(res);
        }
Esempio n. 22
0
        /// <summary>Sets a custom attribute using a custom attribute builder.</summary>
        /// <param name="customBuilder">An instance of a helper class to define the custom attribute. </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="con" /> is null. </exception>
        /// <exception cref="T:System.InvalidOperationException">The parent type of this field is complete. </exception>
        public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
        {
            this.RejectIfCreated();
            string fullName = customBuilder.Ctor.ReflectedType.FullName;

            if (fullName == "System.Runtime.InteropServices.FieldOffsetAttribute")
            {
                byte[] data = customBuilder.Data;
                this.offset  = (int)data[2];
                this.offset |= (int)data[3] << 8;
                this.offset |= (int)data[4] << 16;
                this.offset |= (int)data[5] << 24;
                return;
            }
            if (fullName == "System.NonSerializedAttribute")
            {
                this.attrs |= FieldAttributes.NotSerialized;
                return;
            }
            if (fullName == "System.Runtime.CompilerServices.SpecialNameAttribute")
            {
                this.attrs |= FieldAttributes.SpecialName;
                return;
            }
            if (fullName == "System.Runtime.InteropServices.MarshalAsAttribute")
            {
                this.attrs       |= FieldAttributes.HasFieldMarshal;
                this.marshal_info = CustomAttributeBuilder.get_umarshal(customBuilder, true);
                return;
            }
            if (this.cattrs != null)
            {
                CustomAttributeBuilder[] array = new CustomAttributeBuilder[this.cattrs.Length + 1];
                this.cattrs.CopyTo(array, 0);
                array[this.cattrs.Length] = customBuilder;
                this.cattrs = array;
            }
            else
            {
                this.cattrs    = new CustomAttributeBuilder[1];
                this.cattrs[0] = customBuilder;
            }
        }
        /// <summary>Set a custom attribute using a custom attribute builder.</summary>
        /// <param name="customBuilder">An instance of a helper class to define the custom attribute. </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="con" /> is null. </exception>
        public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
        {
            string fullName = customBuilder.Ctor.ReflectedType.FullName;

            if (fullName == "System.Runtime.InteropServices.InAttribute")
            {
                this.attrs |= ParameterAttributes.In;
                return;
            }
            if (fullName == "System.Runtime.InteropServices.OutAttribute")
            {
                this.attrs |= ParameterAttributes.Out;
                return;
            }
            if (fullName == "System.Runtime.InteropServices.OptionalAttribute")
            {
                this.attrs |= ParameterAttributes.Optional;
                return;
            }
            if (fullName == "System.Runtime.InteropServices.MarshalAsAttribute")
            {
                this.attrs       |= ParameterAttributes.HasFieldMarshal;
                this.marshal_info = CustomAttributeBuilder.get_umarshal(customBuilder, false);
                return;
            }
            if (fullName == "System.Runtime.InteropServices.DefaultParameterValueAttribute")
            {
                this.SetConstant(CustomAttributeBuilder.decode_cattr(customBuilder).ctorArgs[0]);
                return;
            }
            if (this.cattrs != null)
            {
                CustomAttributeBuilder[] array = new CustomAttributeBuilder[this.cattrs.Length + 1];
                this.cattrs.CopyTo(array, 0);
                array[this.cattrs.Length] = customBuilder;
                this.cattrs = array;
            }
            else
            {
                this.cattrs    = new CustomAttributeBuilder[1];
                this.cattrs[0] = customBuilder;
            }
        }
Esempio n. 24
0
 // Set the marshalling information for this field.
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     try
     {
         type.StartSync();
         if (unmanagedMarshal == null)
         {
             throw new ArgumentNullException("unmanagedMarshal");
         }
         lock (typeof(AssemblyBuilder))
         {
             ClrFieldSetMarshal
                 (privateData, unmanagedMarshal.ToBytes());
         }
     }
     finally
     {
         type.EndSync();
     }
 }
Esempio n. 25
0
        // Define a custom-marshaler. This is an extension to MS.NET
        public static UnmanagedMarshal DefineCustom
            (Type typeRef, string cookie, string type, Guid guid)
        {
            UnmanagedMarshal custom =
                new UnmanagedMarshal(UnmanagedType.CustomMarshaler);

            if (type == null || type.Length == 0)
            {
                custom.marshalType = typeRef.AssemblyQualifiedName;
            }
            else
            {
                custom.marshalType = type;
            }
            // Should throw an exception if neither typeRef or type given

            custom.marshalCookie = cookie;

            // guid is ignored

            return(custom);
        }
Esempio n. 26
0
        public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
        {
            if (unmanagedMarshal == null)
                throw new ArgumentNullException("unmanagedMarshal");
            Contract.EndContractBlock();

            m_typeBuilder.ThrowIfCreated();

            byte[] ubMarshal = unmanagedMarshal.InternalGetBytes();

            TypeBuilder.SetFieldMarshal(m_typeBuilder.GetModuleBuilder().GetNativeHandle(), GetToken().Token, ubMarshal, ubMarshal.Length);
        }
	// Define a custom-marshaler. This is an extension to MS.NET
	public static UnmanagedMarshal DefineCustom
			(Type typeRef, string cookie, string type, Guid guid)
		{
			UnmanagedMarshal custom =
				new UnmanagedMarshal(UnmanagedType.CustomMarshaler);

			if (type == null || type.Length == 0)
				custom.marshalType = typeRef.AssemblyQualifiedName;
			else
				custom.marshalType = type;
			// Should throw an exception if neither typeRef or type given

			custom.marshalCookie = cookie;

			// guid is ignored

			return custom;
		}
 public void SetMarshal(UnmanagedMarshal !unmanagedMarshal)
 {
     CodeContract.Requires(unmanagedMarshal != null);
 }
 public virtual new void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
 }
Esempio n. 30
0
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     RejectIfCreated();
     marshal_info = unmanagedMarshal;
     attrs       |= FieldAttributes.HasFieldMarshal;
 }
Esempio n. 31
0
		public void SetMarshal (UnmanagedMarshal unmanagedMarshal)
		{
			RejectIfCreated ();
			throw new NotImplementedException ();
		}
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     throw new PlatformNotSupportedException();
 }
Esempio n. 33
0
		public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
			string attrname = customBuilder.Ctor.ReflectedType.FullName;
			if (attrname == "System.Runtime.InteropServices.InAttribute") {
				attrs |= ParameterAttributes.In;
				return;
			} else if (attrname == "System.Runtime.InteropServices.OutAttribute") {
				attrs |= ParameterAttributes.Out;
				return;
			} else if (attrname == "System.Runtime.InteropServices.OptionalAttribute") {
				attrs |= ParameterAttributes.Optional;
				return;
			} else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute") {
				attrs |= ParameterAttributes.HasFieldMarshal;
				marshal_info = CustomAttributeBuilder.get_umarshal (customBuilder, false);
				/* FIXME: check for errors */
				return;
			} else if (attrname == "System.Runtime.InteropServices.DefaultParameterValueAttribute") {
				/* MS.NET doesn't handle this attribute but we handle it for consistency */
				CustomAttributeBuilder.CustomAttributeInfo cinfo = CustomAttributeBuilder.decode_cattr (customBuilder);
				/* FIXME: check for type compatibility */
				SetConstant (cinfo.ctorArgs [0]);
				return;
			}

			if (cattrs != null) {
				CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
				cattrs.CopyTo (new_array, 0);
				new_array [cattrs.Length] = customBuilder;
				cattrs = new_array;
			} else {
				cattrs = new CustomAttributeBuilder [1];
				cattrs [0] = customBuilder;
			}
		}
Esempio n. 34
0
		/* this one is missing from the MS implementation */
		public static UnmanagedMarshal DefineCustom (Type typeref, string cookie, string mtype, Guid id) {
			UnmanagedMarshal res = new UnmanagedMarshal (UnmanagedType.CustomMarshaler, UnmanagedType.CustomMarshaler);
			res.mcookie = cookie;
			res.marshaltype = mtype;
			res.marshaltyperef = typeref;
			if (id == Guid.Empty)
				res.guid = String.Empty;
			else
				res.guid = id.ToString ();
			return res;
		}
Esempio n. 35
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));
            }
        }
 public virtual new void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
 }
        public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
        {
            ThrowIfGeneric ();

            // set Marshal info for the return type

            m_containingType.ThrowIfCreated();
            
            if (m_retParam == null)
            {
                m_retParam = new ParameterBuilder(this, 0, 0, null);
            }

            m_retParam.SetMarshal(unmanagedMarshal);
        }
Esempio n. 38
0
		public void SetMarshal( UnmanagedMarshal unmanagedMarshal) {
			RejectIfCreated ();
			marshal_info = unmanagedMarshal;
			attrs |= FieldAttributes.HasFieldMarshal;
		}
Esempio n. 39
0
 public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     marshal_info = unmanagedMarshal;
     attrs       |= ParameterAttributes.HasFieldMarshal;
 }
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     if (unmanagedMarshal == null)
     {
         throw new ArgumentNullException("unmanagedMarshal");
     }
     this.m_typeBuilder.ThrowIfCreated();
     byte[] bytes = unmanagedMarshal.InternalGetBytes();
     TypeBuilder.SetFieldMarshal(this.m_typeBuilder.GetModuleBuilder().GetNativeHandle(), this.GetToken().Token, bytes, bytes.Length);
 }
	// Set the marshalling information for this parameter.
	public virtual void SetMarshal(UnmanagedMarshal unmanagedMarshal)
			{
				try
				{
					type.StartSync();
					if(unmanagedMarshal == null)
					{
						throw new ArgumentNullException("unmanagedMarshal");
					}
					lock(typeof(AssemblyBuilder))
					{
						FieldBuilder.ClrFieldSetMarshal
							(privateData, unmanagedMarshal.ToBytes());
					}
				}
				finally
				{
					type.EndSync();
				}
			}
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
 }
        public void SetMarshal (UnmanagedMarshal! unmanagedMarshal) {
            CodeContract.Requires(unmanagedMarshal != null);

        }
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     this.ThrowIfGeneric();
     this.m_containingType.ThrowIfCreated();
     if (this.m_retParam == null)
     {
         this.m_retParam = new ParameterBuilder(this, 0, ParameterAttributes.None, null);
     }
     this.m_retParam.SetMarshal(unmanagedMarshal);
 }
Esempio n. 45
0
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     throw new NotImplementedException();
 }
Esempio n. 46
0
		// sizeConst and sizeParamIndex can be -1 meaning they are not specified
		internal static UnmanagedMarshal DefineLPArrayInternal (UnmanagedType elemType, int sizeConst, int sizeParamIndex) {
			UnmanagedMarshal res = new UnmanagedMarshal (UnmanagedType.LPArray, elemType);
			res.count = sizeConst;
			res.param_num = sizeParamIndex;
			res.has_size = true;

			return res;
		}
Esempio n. 47
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));
            }
        }
Esempio n. 48
0
		public virtual void SetMarshal( UnmanagedMarshal unmanagedMarshal) {
			marshal_info = unmanagedMarshal;
			attrs |= ParameterAttributes.HasFieldMarshal;
		}
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
 }
Esempio n. 50
0
 public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
 {
     RejectIfCreated();
     throw new NotImplementedException();
 }
Esempio n. 51
0
		public void SetCustomAttribute (CustomAttributeBuilder customBuilder) {
			RejectIfCreated ();

			string attrname = customBuilder.Ctor.ReflectedType.FullName;
			if (attrname == "System.Runtime.InteropServices.FieldOffsetAttribute") {
				byte[] data = customBuilder.Data;
				offset = (int)data [2];
				offset |= ((int)data [3]) << 8;
				offset |= ((int)data [4]) << 16;
				offset |= ((int)data [5]) << 24;
				return;
			} else if (attrname == "System.NonSerializedAttribute") {
				attrs |= FieldAttributes.NotSerialized;
				return;
			} else if (attrname == "System.Runtime.CompilerServices.SpecialNameAttribute") {
				attrs |= FieldAttributes.SpecialName;
				return;
			} else if (attrname == "System.Runtime.InteropServices.MarshalAsAttribute") {
				attrs |= FieldAttributes.HasFieldMarshal;
				marshal_info = CustomAttributeBuilder.get_umarshal (customBuilder, true);
				/* FIXME: check for errors */
				return;
			}
			if (cattrs != null) {
				CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
				cattrs.CopyTo (new_array, 0);
				new_array [cattrs.Length] = customBuilder;
				cattrs = new_array;
			} else {
				cattrs = new CustomAttributeBuilder [1];
				cattrs [0] = customBuilder;
			}
		}