コード例 #1
0
        public void ThrowException(Type exceptionType)
        {
            this.CheckForDisposed();

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

            if (this.Document != null)
            {
                this.CurrentIndent = Indention.KeepCurrent;
                var codeLines = new List <CodeLine>();

                var ctor = exceptionType.GetConstructor(Type.EmptyTypes);
                codeLines.Add(new CodeLine(this.GetLabelPrefix() + "newobj " +
                                           MethodDescriptorFactory.Create(ctor).Value,
                                           this.CurrentIndent, true));
                this.LabelIndex += 5;

                codeLines.Add(new CodeLine(this.GetLabelPrefix() + "throw " + new TypeDescriptor(
                                               exceptionType, this.Builder.DeclaringType.Assembly).Value,
                                           this.CurrentIndent, true));
                this.LabelIndex += OpCodes.Throw.Size;

                this.TempDocument.WriteText(
                    codeLines, this.Generator, this.SymbolDocument);
                this.CurrentIndent = Indention.KeepCurrent;
            }

            this.Generator.ThrowException(exceptionType);
        }
コード例 #2
0
        private string EmitCallConsoleWriteLine(Type type)
        {
            var writer = typeof(TextWriter);

            var writeLine = writer.GetMethod("WriteLine", BindingFlags.Instance | BindingFlags.Public,
                                             null, new Type[] { type }, null);

            return(this.GetLabelPrefix() + "callvirt " + MethodDescriptorFactory.Create(writeLine).Value);
        }
コード例 #3
0
 public void EmitCall(OpCode opCode, MethodInfo methodInfo, Type[] optionalParameterTypes)
 {
     this.CheckForDisposed();
     this.TempDocument.WriteText(
         new CodeLine(this.GetLabelPrefix() + opCode.ToString() + " " +
                      MethodDescriptorFactory.Create(methodInfo).Value,
                      this.CurrentIndent, true), this.Generator, this.SymbolDocument);
     this.LabelIndex += opCode.Size + 4;
     this.Generator.EmitCall(opCode, methodInfo, optionalParameterTypes);
 }
コード例 #4
0
 private void BeginMethod(MethodBase method)
 {
     if (this.Document != null)
     {
         this.TempDocument = new CodeDocument(
             this.Document.LinesOfCode, this.Document.IndentLevel);
         this.TempDocument.WriteText(new CodeLine(
                                         MethodDescriptorFactory.Create(method, true).Value, this.CurrentIndent));
         this.TempDocument.WriteText(new CodeLine("{"));
         this.CurrentIndent = Indention.Increase;
         this.TempDocument.WriteText(
             new CodeLine(".locals init ({0})", this.CurrentIndent));
         this.CurrentIndent = Indention.KeepCurrent;
     }
 }
コード例 #5
0
        public void Emit(OpCode opCode, MethodInfo method)
        {
            this.CheckForDisposed();

            if (this.Document != null)
            {
                this.TempDocument.WriteText(
                    new CodeLine(this.GetLabelPrefix() + opCode.ToString() +
                                 " " + MethodDescriptorFactory.Create(method).Value, this.CurrentIndent, true),
                    this.Generator, this.SymbolDocument);
                this.CurrentIndent = Indention.KeepCurrent;
                this.LabelIndex   += opCode.Size + 4;
            }

            this.Generator.Emit(opCode, method);
        }
コード例 #6
0
 internal static MethodDescriptor Create(MethodBase method)
 {
     return(MethodDescriptorFactory.Create(method, method.DeclaringType.Assembly, false));
 }
コード例 #7
0
 internal static MethodDescriptor Create(MethodBase method, Assembly containingAssembly)
 {
     return(MethodDescriptorFactory.Create(method, containingAssembly, false));
 }
コード例 #8
0
 internal static MethodDescriptor Create(MethodBase method, bool isDeclaration)
 {
     return(MethodDescriptorFactory.Create(method, method.DeclaringType.Assembly, isDeclaration));
 }
コード例 #9
0
 private string EmitCallConsoleGetOutMethod()
 {
     return(this.GetLabelPrefix() + "call " + MethodDescriptorFactory.Create(
                typeof(Console).GetProperty("Out", BindingFlags.Static | BindingFlags.Public).GetGetMethod()).Value);
 }