コード例 #1
0
ファイル: FieldBuilder.cs プロジェクト: yuxi214/mono
        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;
            }
        }
コード例 #2
0
ファイル: ParameterBuilder.cs プロジェクト: steinn/mono
        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;
            }
        }
コード例 #3
0
        /// <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;
            }
        }
コード例 #4
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;
            }
        }