Ejemplo n.º 1
0
        /// <summary>
        /// Makes the assembly debuggable by attaching the DebuggableAttribute
        /// to the Assembly. Call immediately before calling WritePEFile.
        /// </summary>
        /// <param name="allowDebug">set true to enable debugging, false otherwise</param>
        /// <param name="suppressOpt">set true to disable optimizations that affect debugging</param>
        public void MakeDebuggable(bool allowDebug, bool suppressOpt)
        {
            Type[]   twoBools = new Type[] { PrimitiveType.Boolean, PrimitiveType.Boolean };
            ClassRef debugRef = MSCorLib.mscorlib.GetClass("System.Diagnostics", "DebuggableAttribute");

            if (debugRef == null)
            {
                debugRef = MSCorLib.mscorlib.AddClass("System.Diagnostics", "DebuggableAttribute");
            }
            MethodRef dCtor = debugRef.GetMethod(".ctor", twoBools);

            if (dCtor == null)
            {
                dCtor = debugRef.AddMethod(".ctor", PrimitiveType.Void, twoBools);
                dCtor.AddCallConv(CallConv.Instance);
            }
            Constant[] dbgArgs = new Constant[] { new BoolConst(allowDebug), new BoolConst(suppressOpt) };
            thisAssembly.AddCustomAttribute(dCtor, dbgArgs);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the MethodRef equivalent to this MethodDef.  If one
        /// does not exist, then create it.
        /// </summary>
        /// <returns>MethodRef for this MethodDef</returns>
        public MethodRef MakeRefOf()
        {
            if (refOf != null)
            {
                return(refOf);
            }
            ClassRef parRef = ((ClassDef)parent).MakeRefOf();

            refOf = parRef.GetMethod(name, sig.parTypes);
            if (refOf == null)
            {
                Type   rType  = sig.MakeRefRetType();
                Type[] pTypes = sig.MakeRefParTypes();
                refOf       = new MethodRef(parRef, name, rType, pTypes);
                refOf.defOf = this;
                refOf.AddCallConv(this.GetCallConv());
            }
            return(refOf);
        }
Ejemplo n.º 3
0
        //		internal void CheckAddMethod(MethodRef meth) {
        //			defaultClass.CheckAddMethod(meth);
        //		}

        /*
         *  internal void CheckAddMethods(ArrayList meths) {
         *    for (int i=0; i < meths.Count; i++) {
         *      Method meth = (Method)meths[i];
         *      defaultClass.CheckAddMethod(meth);
         *      meth.SetParent(this);
         *    }
         *  }
         *
         *  internal MethodRef GetMethod(string name, uint sigIx) {
         *    return defaultClass.GetMethod(name,sigIx);
         *  }
         */

        /// <summary>
        /// Get a method of this scope, if it exists.
        /// </summary>
        /// <param name="name">The name of the method.</param>
        /// <returns>MethodRef for "name", or null if none exists.</returns>
        public MethodRef GetMethod(string name)
        {
            Contract.Requires(name != null);
            return(defaultClass.GetMethod(name));
        }