• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CodeDom.CodeTryCatchFinallyStatement类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.CodeDom.CodeTryCatchFinallyStatement的典型用法代码示例。如果您正苦于以下问题:C# CodeTryCatchFinallyStatement类的具体用法?C# CodeTryCatchFinallyStatement怎么用?C# CodeTryCatchFinallyStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CodeTryCatchFinallyStatement类属于System.CodeDom命名空间,在下文中一共展示了CodeTryCatchFinallyStatement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Constructor0_Deny_Unrestricted

		public void Constructor0_Deny_Unrestricted ()
		{
			CodeTryCatchFinallyStatement ctcfs = new CodeTryCatchFinallyStatement ();
			Assert.AreEqual (0, ctcfs.CatchClauses.Count, "CatchClauses");
			Assert.AreEqual (0, ctcfs.FinallyStatements.Count, "FinallyStatements");
			Assert.AreEqual (0, ctcfs.TryStatements.Count, "TryStatements");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:CodeTryCatchFinallyStatementCas.cs


示例2: Emit

        // Generate a codedom exception handler statement
        public static CodeStatement Emit(ExceptionHandler ex)
        {
            // Create the codedom exception handler statement
            var codeTry = new CodeTryCatchFinallyStatement();

            // Add the statements in the try block
            foreach (var e in ex.Try.ChildExpressions)
                codeTry.TryStatements.Add(CodeDomEmitter.EmitCodeStatement(e));

            // Add all the catch clauses.
            foreach (var c in ex.CatchClauses)
            {
                // Create the codedom catch statement.
                var catchClause = new CodeCatchClause();
                // To do: replace with non-test code
                catchClause.CatchExceptionType = new CodeTypeReference("System.Exception");
                catchClause.LocalName = "ex";
                codeTry.CatchClauses.Add(catchClause);

                // Add the statemnts in the catch block
                foreach(var e in c.ChildExpressions)
                    catchClause.Statements.Add(CodeDomEmitter.EmitCodeStatement(e));
            }

            // Add the statements in the finally block.
            foreach (var e in ex.Finally.ChildExpressions)
                codeTry.FinallyStatements.Add(CodeDomEmitter.EmitCodeStatement(e));

            return codeTry;
        }
开发者ID:maleficus1234,项目名称:Pie,代码行数:31,代码来源:ExceptionHandlerEmitter.cs


示例3: Constructor1_Deny_Unrestricted

		public void Constructor1_Deny_Unrestricted ()
		{
			CodeStatement[] try_statements = new CodeStatement[1] { new CodeStatement () };
			CodeCatchClause[] catch_clauses = new CodeCatchClause[1] { new CodeCatchClause () };
			CodeTryCatchFinallyStatement ctcfs = new CodeTryCatchFinallyStatement (try_statements, catch_clauses);
			Assert.AreEqual (1, ctcfs.CatchClauses.Count, "CatchClauses");
			Assert.AreEqual (0, ctcfs.FinallyStatements.Count, "FinallyStatements");
			Assert.AreEqual (1, ctcfs.TryStatements.Count, "TryStatements");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:CodeTryCatchFinallyStatementCas.cs


示例4: TypescriptTryCatchFinallyStatement

 public TypescriptTryCatchFinallyStatement(
     IStatementFactory statementFactory,
     IExpressionFactory expressionFactory,
     CodeTryCatchFinallyStatement statement,
     CodeGeneratorOptions options)
 {
     _statementFactory = statementFactory;
     _expressionFactory = expressionFactory;
     _statement = statement;
     _options = options;
     _typescriptTypeMapper = new TypescriptTypeMapper();
 }
开发者ID:s2quake,项目名称:TypescriptCodeDom,代码行数:12,代码来源:TypescriptTryCatchFinallyStatement.cs


示例5: Clone

 public static CodeTryCatchFinallyStatement Clone(this CodeTryCatchFinallyStatement statement)
 {
     if (statement == null) return null;
     CodeTryCatchFinallyStatement s = new CodeTryCatchFinallyStatement();
     s.CatchClauses.AddRange(statement.CatchClauses.Clone());
     s.EndDirectives.AddRange(statement.EndDirectives);
     s.FinallyStatements.AddRange(statement.FinallyStatements.Clone());
     s.LinePragma = statement.LinePragma;
     s.StartDirectives.AddRange(statement.StartDirectives);
     s.TryStatements.AddRange(statement.TryStatements.Clone());
     s.UserData.AddRange(statement.UserData);
     return s;
 }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:13,代码来源:CodeTryCatchFinallyStatementExtensions.cs


示例6: CreateMember

        /// <summary>
        /// 
        /// </summary>
        /// <param name="member"></param>
        /// <param name="inner"></param>
        /// <param name="attrs"></param>
        /// <returns></returns>
        public CodeTypeMember CreateMember(MemberInfo member, CodeFieldReferenceExpression inner, MemberAttributes attrs)
        {
            Debug.Assert(member is MethodInfo);
            MethodInfo method = member as MethodInfo;
            CodeMemberMethod codeMethod = new CodeMemberMethod();

            codeMethod.Name = method.Name;
            codeMethod.ReturnType = new CodeTypeReference(method.ReturnType);
            codeMethod.Attributes = attrs;

            // try
            CodeTryCatchFinallyStatement tryCode = new CodeTryCatchFinallyStatement();

            // decleare parameters
            List<CodeArgumentReferenceExpression> codeParamiteRefrs = new List<CodeArgumentReferenceExpression>();

            foreach (ParameterInfo codeParameter in method.GetParameters()) {
                CodeParameterDeclarationExpression codeParameterDeclare = new CodeParameterDeclarationExpression(codeParameter.ParameterType, codeParameter.Name);
                codeMethod.Parameters.Add(codeParameterDeclare);
                codeParamiteRefrs.Add(new CodeArgumentReferenceExpression(codeParameter.Name));
            }

            // invoke
            CodeMethodInvokeExpression invokeMethod = new CodeMethodInvokeExpression(
                inner, method.Name, codeParamiteRefrs.ToArray());
            if (method.ReturnType.Name.ToLower() == "void") {
                tryCode.TryStatements.Add(invokeMethod);
            } else {
                CodeVariableDeclarationStatement var = new CodeVariableDeclarationStatement(method.ReturnType, "returnObject", invokeMethod);
                //CodeAssignStatement assign = new CodeAssignStatement(var, invokeMethod);
                tryCode.TryStatements.Add(var);

                CodeCommentStatement todo = new CodeCommentStatement("TODO: your code", false);
                tryCode.TryStatements.Add(todo);

                CodeVariableReferenceExpression varRef = new CodeVariableReferenceExpression("returnObject");
                CodeMethodReturnStatement codeReturn = new CodeMethodReturnStatement(varRef);
                tryCode.TryStatements.Add(codeReturn);
            }

            // catch
            CodeTypeReference codeTypeRef = new CodeTypeReference(typeof(Exception));
            CodeCatchClause catchClause = new CodeCatchClause("ex", codeTypeRef);
            catchClause.Statements.Add(new CodeThrowExceptionStatement());
            tryCode.CatchClauses.Add(catchClause);

            codeMethod.Statements.Add(tryCode);
            return codeMethod;
        }
开发者ID:yangwen27,项目名称:moonlit,代码行数:56,代码来源:MemberMethodInfoFactory.cs


示例7: VisitUsingStatement

        public override object VisitUsingStatement(UsingStatement usingStatement, object data)
        {
            // using (new expr) { stmts; }
            //
            // emulate with
            //      object _dispose;
            //      try
            //      {
            //          _dispose = new expr;
            //
            //          stmts;
            //      }
            //      finally
            //      {
            //          if (((_dispose != null)
            //              && (typeof(System.IDisposable).IsInstanceOfType(_dispose) == true)))
            //          {
            //              ((System.IDisposable)(_dispose)).Dispose();
            //          }
            //      }
            //

            usingId++; // in case nested using() statements
            string name = "_dispose" + usingId.ToString();

            CodeVariableDeclarationStatement disposable = new CodeVariableDeclarationStatement("System.Object", name, new CodePrimitiveExpression(null));

            AddStmt(disposable);

            CodeTryCatchFinallyStatement tryStmt = new CodeTryCatchFinallyStatement();

            CodeVariableReferenceExpression left1 = new CodeVariableReferenceExpression(name);

            codeStack.Push(NullStmtCollection); // send statements to nul Statement collection
            CodeExpression right1 = (CodeExpression)usingStatement.ResourceAcquisition.AcceptVisitor(this, data);
            codeStack.Pop();

            CodeAssignStatement assign1 = new CodeAssignStatement(left1, right1);

            tryStmt.TryStatements.Add(assign1);
            tryStmt.TryStatements.Add(new CodeSnippetStatement());

            codeStack.Push(tryStmt.TryStatements);
            usingStatement.EmbeddedStatement.AcceptChildren(this, data);
            codeStack.Pop();

            CodeMethodInvokeExpression isInstanceOfType = new CodeMethodInvokeExpression(new CodeTypeOfExpression(typeof(IDisposable)), "IsInstanceOfType", new CodeExpression[] { left1 });

            CodeConditionStatement if1 = new CodeConditionStatement();
            if1.Condition = new CodeBinaryOperatorExpression(new CodeBinaryOperatorExpression(left1, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)),
                                                             CodeBinaryOperatorType.BooleanAnd,
                                                             new CodeBinaryOperatorExpression(isInstanceOfType, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(true)));
            if1.TrueStatements.Add(new CodeMethodInvokeExpression(new CodeCastExpression(typeof(IDisposable),left1), "Dispose", new CodeExpression[] { }));

            tryStmt.FinallyStatements.Add(if1);

            // Add Statement to Current Statement Collection
            AddStmt(tryStmt);

            return null;
        }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:61,代码来源:CodeDOMOutputVisitor.cs


示例8: GenerateTryCatchFinallyStatement

		protected override void GenerateTryCatchFinallyStatement (CodeTryCatchFinallyStatement e)
		{
		}
开发者ID:Profit0004,项目名称:mono,代码行数:3,代码来源:CodeGeneratorCas.cs


示例9: GenerateTryCatchFinallyStatement

		protected override void GenerateTryCatchFinallyStatement (CodeTryCatchFinallyStatement statement)
		{
			TextWriter output = Output;

			output.WriteLine ("Try ");
			++Indent;
			GenerateStatements (statement.TryStatements);
			--Indent;
			
			foreach (CodeCatchClause clause in statement.CatchClauses) {
				output.Write ("Catch ");
				OutputTypeNamePair (clause.CatchExceptionType, clause.LocalName);
				output.WriteLine ();
				++Indent;
				GenerateStatements (clause.Statements);
				--Indent;
			}

			CodeStatementCollection finallies = statement.FinallyStatements;
			if (finallies.Count > 0) {
				output.WriteLine ("Finally");
				++Indent;
				GenerateStatements (finallies);
				--Indent;
			}

			output.WriteLine("End Try");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:28,代码来源:VBCodeGenerator.cs


示例10: Visit

			public void Visit (CodeTryCatchFinallyStatement o)
			{
				g.GenerateTryCatchFinallyStatement (o);
			}
开发者ID:carrie901,项目名称:mono,代码行数:4,代码来源:CodeGenerator.cs


示例11: BuildCodeDomTree

		public override void BuildCodeDomTree (CodeCompileUnit compileUnit)
		{
         
			CodeThisReferenceExpression @this = new CodeThisReferenceExpression ();
			CodeBaseReferenceExpression @base = new CodeBaseReferenceExpression ();
			CodeTypeReferenceExpression thisType = new CodeTypeReferenceExpression (new CodeTypeReference (GeneratedTypeName));
			CodeTypeReference uriType = new CodeTypeReference (typeof(Uri));

			CodeMemberField executableField = new CodeMemberField {
            Name = "_Executable",
            Type = new CodeTypeReference(typeof(XsltExecutable)),
            Attributes = MemberAttributes.Private | MemberAttributes.Static
         };

			// methods

			// cctor
			CodeTypeConstructor cctor = new CodeTypeConstructor {
            CustomAttributes = { 
               new CodeAttributeDeclaration(DebuggerNonUserCodeTypeReference)
            }
         };

			CodeVariableDeclarationStatement procVar = new CodeVariableDeclarationStatement {
            Name = "proc",
            Type = new CodeTypeReference(typeof(IXsltProcessor)),
            InitExpression = new CodeIndexerExpression {
               TargetObject = new CodePropertyReferenceExpression {
                  PropertyName = "Xslt",
                  TargetObject = new CodeTypeReferenceExpression(typeof(Processors))
               },
               Indices = { 
                  new CodePrimitiveExpression(parser.ProcessorName)
               }
            } 
         };

			CodeVariableDeclarationStatement sourceVar = new CodeVariableDeclarationStatement {
            Name = "source",
            Type = new CodeTypeReference(typeof(Stream)),
            InitExpression = new CodePrimitiveExpression(null)
         };

			CodeVariableDeclarationStatement sourceUriVar = new CodeVariableDeclarationStatement {
            Name = "sourceUri",
            Type = uriType,
            InitExpression = new CodeObjectCreateExpression {
               CreateType = uriType,
               Parameters = {
                  new CodePrimitiveExpression(ValidatorUri.AbsoluteUri)
               }
            }
         };

			CodeVariableDeclarationStatement resolverVar = new CodeVariableDeclarationStatement {
            Name = "resolver",
            Type = new CodeTypeReference(typeof(XmlResolver)),
            InitExpression = new CodeObjectCreateExpression(typeof(XmlEmbeddedResourceResolver))
         };

			CodeTryCatchFinallyStatement trySt = new CodeTryCatchFinallyStatement { 
            TryStatements = {
               new CodeAssignStatement {
                  Left = new CodeVariableReferenceExpression(sourceVar.Name),
                  Right = new CodeCastExpression {
                     TargetType = new CodeTypeReference(typeof(Stream)),
                     Expression = new CodeMethodInvokeExpression {
                        Method = new CodeMethodReferenceExpression {
                           MethodName = "GetEntity",
                           TargetObject = new CodeVariableReferenceExpression(resolverVar.Name)
                        },
                        Parameters = {
                           new CodeVariableReferenceExpression(sourceUriVar.Name),
                           new CodePrimitiveExpression(null),
                           new CodeTypeOfExpression(typeof(Stream))
                        }
                     }
                  }
               }
            }
         };

			CodeVariableDeclarationStatement optionsVar = new CodeVariableDeclarationStatement {
            Name = "options",
            Type = new CodeTypeReference(typeof(XsltCompileOptions)),
         };
			optionsVar.InitExpression = new CodeObjectCreateExpression (optionsVar.Type);

			trySt.TryStatements.Add (optionsVar);
			trySt.TryStatements.Add (new CodeAssignStatement {
            Left = new CodePropertyReferenceExpression {
               PropertyName = "BaseUri",
               TargetObject = new CodeVariableReferenceExpression(optionsVar.Name)
            },
            Right = new CodeVariableReferenceExpression(sourceUriVar.Name)
         });
			trySt.TryStatements.Add (new CodeAssignStatement {
            Left = new CodeFieldReferenceExpression {
               FieldName = executableField.Name,
               TargetObject = thisType
//.........这里部分代码省略.........
开发者ID:nuxleus,项目名称:Nuxleus,代码行数:101,代码来源:SchematronValidatorCodeDomTreeGenerator.cs


示例12: AddToTimeSpanFunction


//.........这里部分代码省略.........
            cboe.Left = new CodePropertyReferenceExpression(new CodeVariableReferenceExpression(tsParam),"Length");
            cboe.Right = new CodePrimitiveExpression(DMTF_DATETIME_STR_LENGTH);
            cboe.Operator = CodeBinaryOperatorType.IdentityInequality;

            cis = new CodeConditionStatement();
            cis.Condition = cboe;
            cis.TrueStatements.Add(new CodeThrowExceptionStatement(codeThrowException));

            cmmts.Statements.Add(cis);
            
            /*
                if(dmtfTimespan.Substring(21,4) != ":000")
                {
                    throw new System.ArgumentOutOfRangeException();
                }
            */
            
            CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression();
            cmie.Method = new CodeMethodReferenceExpression(new CodeVariableReferenceExpression(tsParam),"Substring");
            cmie.Parameters.Add(new CodePrimitiveExpression(21));
            cmie.Parameters.Add(new CodePrimitiveExpression(4));

            cboe = new CodeBinaryOperatorExpression();
            cboe.Left = cmie;
            cboe.Right = new CodePrimitiveExpression(":000");
            cboe.Operator = CodeBinaryOperatorType.IdentityInequality;

            cis = new CodeConditionStatement();
            cis.Condition = cboe;
            cis.TrueStatements.Add(new CodeThrowExceptionStatement(codeThrowException));

            cmmts.Statements.Add(cis);

            CodeTryCatchFinallyStatement tryblock = new CodeTryCatchFinallyStatement();

            /*
                string tempString = System.String.Empty;
            */

            string strTemp = "tempString";
            tryblock.TryStatements.Add(new CodeVariableDeclarationStatement(new CodeTypeReference("System.String"),strTemp,
                new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("System.String"),"Empty")));
            /*
                tempString = dmtfTimespan.Substring(0, 8);
                days = System.Int32.Parse(tempString);

                tempString = dmtfTimespan.Substring(8, 2);
                hours = System.Int32.Parse(tempString);

                tempString = dmtfTimespan.Substring(10, 2);
                minutes = System.Int32.Parse(tempString);

                tempString = dmtfTimespan.Substring(12, 2);
                seconds = System.Int32.Parse(tempString);
            */

            ToTimeSpanHelper(0,8,days,tryblock.TryStatements);
            ToTimeSpanHelper(8,2,hours,tryblock.TryStatements);
            ToTimeSpanHelper(10,2,minutes,tryblock.TryStatements);
            ToTimeSpanHelper(12,2,seconds,tryblock.TryStatements);

            /*
                tempString = dmtfTimespan.Substring(15, 6);
            */

            cmie = new CodeMethodInvokeExpression();
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:67,代码来源:WMIGenerator.cs


示例13: AddToDateTimeFunction


//.........这里部分代码省略.........
                    throw new System.ArgumentOutOfRangeException();
                }
            */

            cboe = new CodeBinaryOperatorExpression();
            cboe.Left = new CodePropertyReferenceExpression(new CodeVariableReferenceExpression(dmtf),"Length");
            cboe.Right = new CodePrimitiveExpression(0);
            cboe.Operator = CodeBinaryOperatorType.ValueEquality;

            cis = new CodeConditionStatement();
            cis.Condition = cboe;

            cis.TrueStatements.Add(new CodeThrowExceptionStatement(codeThrowException));

            cmmdt.Statements.Add(cis);

            /*
                if (str.Length != DMTF_DATETIME_STR_LENGTH )
                {
                    throw new System.ArgumentOutOfRangeException();
                }
            */
            cboe = new CodeBinaryOperatorExpression();
            cboe.Left = new CodePropertyReferenceExpression(new CodeVariableReferenceExpression(dmtf),"Length");
            cboe.Right = new CodePrimitiveExpression(DMTF_DATETIME_STR_LENGTH);
            cboe.Operator = CodeBinaryOperatorType.IdentityInequality;

            cis = new CodeConditionStatement();
            cis.Condition = cboe;
            cis.TrueStatements.Add(new CodeThrowExceptionStatement(codeThrowException));

            cmmdt.Statements.Add(cis);

            CodeTryCatchFinallyStatement tryblock = new CodeTryCatchFinallyStatement();
            DateTimeConversionFunctionHelper(tryblock.TryStatements,"****",tempStr,dmtf,year,0,4);
            DateTimeConversionFunctionHelper(tryblock.TryStatements,"**",tempStr,dmtf,month,4,2);
            DateTimeConversionFunctionHelper(tryblock.TryStatements,"**",tempStr,dmtf,day,6,2);
            DateTimeConversionFunctionHelper(tryblock.TryStatements,"**",tempStr,dmtf,hour,8,2);
            DateTimeConversionFunctionHelper(tryblock.TryStatements,"**",tempStr,dmtf,minute,10,2);
            DateTimeConversionFunctionHelper(tryblock.TryStatements,"**",tempStr,dmtf,second,12,2);

            /*
                tempString = dmtf.Substring(15, 6);
                if (("******" != tempString)) 
                {
                    ticks = (System.Int64.Parse(tempString)) * (System.TimeSpan.TicksPerMillisecond/1000);
                }
            */

            CodeMethodReferenceExpression  cmre = new CodeMethodReferenceExpression(new CodeVariableReferenceExpression(dmtf),"Substring");
            CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression();
            cmie.Method = cmre;
            cmie.Parameters.Add(new CodePrimitiveExpression(15));
            cmie.Parameters.Add(new CodePrimitiveExpression(6));
            tryblock.TryStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression(tempStr), cmie));


            cboe = new CodeBinaryOperatorExpression();
            cboe.Left = new CodePrimitiveExpression("******");
            cboe.Right = new CodeVariableReferenceExpression(tempStr);
            cboe.Operator = CodeBinaryOperatorType.IdentityInequality;
            cis = new CodeConditionStatement();
            cis.Condition = cboe;

            CodeMethodReferenceExpression  cmre1 = new CodeMethodReferenceExpression(new CodeTypeReferenceExpression("System.Int64"),"Parse");
            CodeMethodInvokeExpression cmie1 = new CodeMethodInvokeExpression();
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:67,代码来源:WMIGenerator.cs


示例14: VisitCodeTryCatchFinallyStatement

		void VisitCodeTryCatchFinallyStatement(CodeTryCatchFinallyStatement tryStatement)
		{
			WriteLine("VisitCodeTryCatchFinallyStatement");
			using (IDisposable currentLevel = Indentation.IncrementLevel()) {
				WriteLine("Try statements follow: Count: " + tryStatement.TryStatements.Count);
				foreach (CodeStatement statement in tryStatement.TryStatements) {
					VisitCodeStatement(statement);
				}
				
				WriteLine("Catch clauses follow: Count: " + tryStatement.CatchClauses.Count);
				foreach (CodeCatchClause catchClause in tryStatement.CatchClauses) {
					VisitCodeCatchClause(catchClause);
				}				
				
				WriteLine("Finally statements follow: Count: " + tryStatement.FinallyStatements);
				foreach (CodeStatement statement in tryStatement.FinallyStatements) {
					VisitCodeStatement(statement);
				}				
			}
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:20,代码来源:CodeDomVisitor.cs


示例15: WriteHookupMethods

 private void WriteHookupMethods(CodeTypeDeclaration cls)
 {
     if (this.axctlEventsType != null)
     {
         CodeMemberMethod method = new CodeMemberMethod {
             Name = "CreateSink",
             Attributes = MemberAttributes.Family | MemberAttributes.Override
         };
         CodeObjectCreateExpression expression = new CodeObjectCreateExpression(this.axctl + "EventMulticaster", new CodeExpression[0]);
         expression.Parameters.Add(new CodeThisReferenceExpression());
         CodeAssignStatement statement = new CodeAssignStatement(this.multicasterRef, expression);
         CodeObjectCreateExpression expression2 = new CodeObjectCreateExpression(typeof(AxHost.ConnectionPointCookie).FullName, new CodeExpression[0]);
         expression2.Parameters.Add(this.memIfaceRef);
         expression2.Parameters.Add(this.multicasterRef);
         expression2.Parameters.Add(new CodeTypeOfExpression(this.axctlEvents));
         CodeAssignStatement statement2 = new CodeAssignStatement(this.cookieRef, expression2);
         CodeTryCatchFinallyStatement statement3 = new CodeTryCatchFinallyStatement();
         statement3.TryStatements.Add(statement);
         statement3.TryStatements.Add(statement2);
         statement3.CatchClauses.Add(new CodeCatchClause("", new CodeTypeReference(typeof(Exception))));
         method.Statements.Add(statement3);
         cls.Members.Add(method);
         CodeMemberMethod method2 = new CodeMemberMethod {
             Name = "DetachSink",
             Attributes = MemberAttributes.Family | MemberAttributes.Override
         };
         CodeFieldReferenceExpression targetObject = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), this.cookie);
         CodeMethodInvokeExpression expression4 = new CodeMethodInvokeExpression(targetObject, "Disconnect", new CodeExpression[0]);
         statement3 = new CodeTryCatchFinallyStatement();
         statement3.TryStatements.Add(expression4);
         statement3.CatchClauses.Add(new CodeCatchClause("", new CodeTypeReference(typeof(Exception))));
         method2.Statements.Add(statement3);
         cls.Members.Add(method2);
     }
     CodeMemberMethod method3 = new CodeMemberMethod {
         Name = "AttachInterfaces",
         Attributes = MemberAttributes.Family | MemberAttributes.Override
     };
     CodeCastExpression right = new CodeCastExpression(this.axctlType.FullName, new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "GetOcx", new CodeExpression[0]));
     CodeAssignStatement statement4 = new CodeAssignStatement(this.memIfaceRef, right);
     CodeTryCatchFinallyStatement statement5 = new CodeTryCatchFinallyStatement();
     statement5.TryStatements.Add(statement4);
     statement5.CatchClauses.Add(new CodeCatchClause("", new CodeTypeReference(typeof(Exception))));
     method3.Statements.Add(statement5);
     cls.Members.Add(method3);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:46,代码来源:AxWrapperGen.cs


示例16: GenerateTryCatchFinallyStatement

        /// <include file='doc\CSharpCodeProvider.uex' path='docs/doc[@for="CSharpCodeGenerator.GenerateTryCatchFinallyStatement"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Generates code for the specified CodeDom based try catch finally
        ///       statement representation.
        ///    </para>
        /// </devdoc>
        protected override void GenerateTryCatchFinallyStatement(CodeTryCatchFinallyStatement e) {
            Output.Write("try");
            OutputStartingBrace();
            Indent++;
            GenerateStatements(e.TryStatements);
            Indent--;
            CodeCatchClauseCollection catches = e.CatchClauses;
            if (catches.Count > 0) {
                IEnumerator en = catches.GetEnumerator();
                while (en.MoveNext()) {
                    Output.Write("}");
                    if (Options.ElseOnClosing) {
                        Output.Write(" ");
                    } 
                    else {
                        Output.WriteLine("");
                    }
                    CodeCatchClause current = (CodeCatchClause)en.Current;
                    Output.Write("catch (");
                    OutputType(current.CatchExceptionType);
                    Output.Write(" ");
                    OutputIdentifier(current.LocalName);
                    Output.Write(")");
                    OutputStartingBrace();
                    Indent++;
                    GenerateStatements(current.Statements);
                    Indent--;
                }
            }

            CodeStatementCollection finallyStatements = e.FinallyStatements;
            if (finallyStatements.Count > 0) {
                Output.Write("}");
                if (Options.ElseOnClosing) {
                    Output.Write(" ");
                } 
                else {
                    Output.WriteLine("");
                }
                Output.Write("finally");
                OutputStartingBrace();
                Indent++;
                GenerateStatements(finallyStatements);
                Indent--;
            }
            Output.WriteLine("}");
        }
开发者ID:ArildF,项目名称:masters,代码行数:54,代码来源:csharpcodeprovider.cs


示例17: GenerateLoadPixbuf

		public CodeExpression GenerateLoadPixbuf (string name, Gtk.IconSize size)
		{
			bool found = false;
			foreach (CodeTypeDeclaration t in cns.Types) {
				if (t.Name == "IconLoader") {
					found = true;
					break;
				}
			}
			
			if (!found)
			{
				CodeTypeDeclaration cls = new CodeTypeDeclaration ("IconLoader");
				cls.Attributes = MemberAttributes.Private;
				cls.TypeAttributes = System.Reflection.TypeAttributes.NestedAssembly;
				cns.Types.Add (cls);
				
				CodeMemberMethod met = new CodeMemberMethod ();
				cls.Members.Add (met);
				met.Attributes = MemberAttributes.Public | MemberAttributes.Static;
				met.Name = "LoadIcon";
				met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(Gtk.Widget), "widget"));
				met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(string), "name"));
				met.Parameters.Add (new CodeParameterDeclarationExpression (typeof(Gtk.IconSize), "size"));
				met.ReturnType = new CodeTypeReference (typeof(Gdk.Pixbuf));
				
				CodeExpression widgetExp = new CodeVariableReferenceExpression ("widget");
				CodeExpression nameExp = new CodeVariableReferenceExpression ("name");
				CodeExpression sizeExp = new CodeVariableReferenceExpression ("size");
				CodeExpression szExp = new CodeVariableReferenceExpression ("sz");
				CodeExpression mgExp = new CodeBinaryOperatorExpression (szExp,  CodeBinaryOperatorType.Divide, new CodePrimitiveExpression (4));
				CodeExpression pmapExp = new CodeVariableReferenceExpression ("pmap");
				CodeExpression gcExp = new CodeVariableReferenceExpression ("gc");
				CodeExpression szM1Exp = new CodeBinaryOperatorExpression (szExp, CodeBinaryOperatorType.Subtract, new CodePrimitiveExpression (1));
				CodeExpression zeroExp = new CodePrimitiveExpression (0);
				CodeExpression resExp = new CodeVariableReferenceExpression ("res");
				
				met.Statements.Add (
					new CodeVariableDeclarationStatement (typeof(Gdk.Pixbuf), "res",
						new CodeMethodInvokeExpression (
							widgetExp,
							"RenderIcon",
							nameExp,
							sizeExp,
							new CodePrimitiveExpression (null)
						)
					)
				);
				
				CodeConditionStatement nullcheck = new CodeConditionStatement ();
				met.Statements.Add (nullcheck);
				nullcheck.Condition = new CodeBinaryOperatorExpression (
					resExp,
					CodeBinaryOperatorType.IdentityInequality,
					new CodePrimitiveExpression (null)
				);
				nullcheck.TrueStatements.Add (new CodeMethodReturnStatement (resExp));
				
				// int sz, h;
				// Gtk.Icon.SizeLookup (size, out sz, out h);

				nullcheck.FalseStatements.Add (new CodeVariableDeclarationStatement (typeof(int), "sz"));
				nullcheck.FalseStatements.Add (new CodeVariableDeclarationStatement (typeof(int), "sy"));
				nullcheck.FalseStatements.Add (new CodeMethodInvokeExpression (
				    new CodeTypeReferenceExpression (typeof(Gtk.Icon).ToGlobalTypeRef ()),
				    "SizeLookup",
				    sizeExp,
				    new CodeDirectionExpression (FieldDirection.Out, szExp),
				    new CodeDirectionExpression (FieldDirection.Out, new CodeVariableReferenceExpression ("sy"))
				));

				CodeTryCatchFinallyStatement trycatch = new CodeTryCatchFinallyStatement ();
				nullcheck.FalseStatements.Add (trycatch);
				trycatch.TryStatements.Add (
					new CodeMethodReturnStatement (
						new CodeMethodInvokeExpression (
							new CodePropertyReferenceExpression (
								new CodeTypeReferenceExpression (new CodeTypeReference (typeof(Gtk.IconTheme))),
								"Default"
							),
							"LoadIcon",
							nameExp,
							szExp,
							zeroExp
						)
					)
				);
				
				CodeCatchClause ccatch = new CodeCatchClause ();
				trycatch.CatchClauses.Add (ccatch);				
				
				CodeConditionStatement cond = new CodeConditionStatement ();
				ccatch.Statements.Add (cond);
				
				cond.Condition = new CodeBinaryOperatorExpression (
					nameExp,
					CodeBinaryOperatorType.IdentityInequality,
					new CodePrimitiveExpression ("gtk-missing-image")
				);
				
//.........这里部分代码省略.........
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:101,代码来源:GeneratorContext.cs


示例18: GenerateLoadMethod

        CodeMemberMethod GenerateLoadMethod()
        {
            ////Generate the following code:

            //private static System.Reflection.Assembly Load(string assemblyNameVal) {
            //    System.Reflection.AssemblyName assemblyName = new System.Reflection.AssemblyName(assemblyNameVal);
            //    byte[] publicKeyToken = assemblyName.GetPublicKeyToken();
            //    System.Reflection.Assembly asm = null;
            //    try {
            //        asm = System.Reflection.Assembly.Load(assemblyName.FullName);
            //    }
            //    catch (System.Exception ) {
            //        System.Reflection.AssemblyName shortName = new System.Reflection.AssemblyName(assemblyName.Name);
            //        if ((publicKeyToken != null)) {
            //            shortName.SetPublicKeyToken(publicKeyToken);
            //        }
            //        asm = System.Reflection.Assembly.Load(shortName);
            //    }
            //    return asm;
            //}

            CodeMemberMethod loadMethod = new CodeMemberMethod()
            {
                Name = "Load",
                Attributes = MemberAttributes.Private | MemberAttributes.Static,
                ReturnType = new CodeTypeReference(typeof(Assembly))
            };
            loadMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "assemblyNameVal"));
            CodeVariableReferenceExpression assemblyNameVal = new CodeVariableReferenceExpression("assemblyNameVal");

            CodeExpression initAssemblyName = typeof(AssemblyName).New(assemblyNameVal);
            CodeVariableReferenceExpression assemblyName = loadMethod.Statements.DeclareVar(typeof(AssemblyName), "assemblyName", initAssemblyName);

            CodeVariableReferenceExpression publicKeyToken = loadMethod.Statements.DeclareVar(typeof(byte[]),
                "publicKeyToken",
                new CodeMethodInvokeExpression()
                {
                    Method =
                    new CodeMethodReferenceExpression()
                    {
                        MethodName = "GetPublicKeyToken",
                        TargetObject = assemblyName,
                    },
                }
                );
            CodeVariableReferenceExpression asm = loadMethod.Statements.DeclareVar(typeof(Assembly), "asm", new CodePrimitiveExpression(null));

            CodeExpression publicKeyTokenNotNullExp = new CodeBinaryOperatorExpression(publicKeyToken,
                CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));

            CodeTryCatchFinallyStatement tryCatchExp = new CodeTryCatchFinallyStatement();

            tryCatchExp.TryStatements.Add(new CodeAssignStatement(asm,
                new CodeMethodInvokeExpression(
                    new CodeMethodReferenceExpression()
                    {
                        MethodName = "System.Reflection.Assembly.Load"
                    },
                    new CodePropertyReferenceExpression(assemblyName, "FullName")
                )
            ));

            CodeCatchClause catchClause = new CodeCatchClause();
            CodeVariableReferenceExpression shortName = catchClause.Statements.DeclareVar(typeof(AssemblyName), "shortName",
                typeof(AssemblyName).New(new CodePropertyReferenceExpression(assemblyName, "Name")));
            CodeConditionStatement setPublicKeyTokenExp = new CodeConditionStatement();
            setPublicKeyTokenExp.Condition = publicKeyTokenNotNullExp;
            setPublicKeyTokenExp.TrueStatements.Add(
                new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(shortName, "SetPublicKeyToken"), publicKeyToken)
            );
            catchClause.Statements.Add(setPublicKeyTokenExp);
            catchClause.Statements.Add(new CodeAssignStatement(asm,
                new CodeMethodInvokeExpression(
                    new CodeMethodReferenceExpression()
                    {
                        MethodName = "System.Reflection.Assembly.Load"
                    },
                    shortName
                )
            ));
            tryCatchExp.CatchClauses.Add(catchClause);

            loadMethod.Statements.Add(tryCatchExp);
            loadMethod.Statements.Add(new CodeMethodReturnStatement(asm));
            return loadMethod;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:86,代码来源:ClassGenerator.cs


示例19: AddVertexMethod

        // Add a new vertex method to the DryadLinq vertex class
        internal CodeMemberMethod AddVertexMethod(DLinqQueryNode node)
        {
            CodeMemberMethod vertexMethod = new CodeMemberMethod();
            vertexMethod.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            vertexMethod.ReturnType = new CodeTypeReference(typeof(int));
            vertexMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "args"));
            vertexMethod.Name = MakeUniqueName(node.NodeType.ToString());

            CodeTryCatchFinallyStatement tryBlock = new CodeTryCatchFinallyStatement();

            string startedMsg = "DryadLinqLog.AddInfo(\"Vertex " + vertexMethod.Name + 
                " started at {0}\", DateTime.Now.ToString(\"MM/dd/yyyy HH:mm:ss.fff\"))";
            vertexMethod.Statements.Add(new CodeSnippetExpression(startedMsg));

            // We need to add a call to CopyResources()
            vertexMethod.Statements.Add(new CodeSnippetExpression("CopyResources()"));
            
            if (StaticConfig.LaunchDebugger)
            {
                // If static config requests it, we do an unconditional Debugger.Launch() at vertex entry.
                // Currently this isn't used because StaticConfig.LaunchDebugger is hardcoded to false
                System.Console.WriteLine("Launch debugger: may block application");

                CodeExpression launchExpr = new CodeSnippetExpression("Syste 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CodeDom.CodeTypeDeclaration类代码示例发布时间:2022-05-26
下一篇:
C# CodeDom.CodeThrowExceptionStatement类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap