Ejemplo n.º 1
0
        /// <summary>
        /// Fetch a MethodRef descriptor for the method "retType name (pars)".
        /// If one exists, it is returned, else one is created.
        /// </summary>
        /// <param name="name">method name</param>
        /// <param name="retType">return type</param>
        /// <param name="pars">method parameter types</param>
        /// <returns>a descriptor for this method in anther module</returns>
        public MethodRef AddMethod(string name, Type retType, Type[] pars)
        {
            Contract.Requires(name != null);
            Contract.Requires(retType != null);
            Contract.Requires(pars != null);
            MethodRef meth = defaultClass.AddMethod(name, retType, pars);

            return(meth);
        }
Ejemplo n.º 2
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);
        }