本文整理汇总了C#中System.CodeDom.CodeCatchClause类的典型用法代码示例。如果您正苦于以下问题:C# CodeCatchClause类的具体用法?C# CodeCatchClause怎么用?C# CodeCatchClause使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeCatchClause类属于System.CodeDom命名空间,在下文中一共展示了CodeCatchClause类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Constructor0
public void Constructor0 ()
{
CodeCatchClause ccc = new CodeCatchClause ();
Assert.IsNotNull (ccc.CatchExceptionType, "#1");
Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#2");
Assert.IsNotNull (ccc.LocalName, "#3");
Assert.AreEqual (string.Empty, ccc.LocalName, "#4");
Assert.IsNotNull (ccc.Statements, "#5");
Assert.AreEqual (0, ccc.Statements.Count, "#6");
ccc.LocalName = null;
Assert.IsNotNull (ccc.LocalName, "#7");
Assert.AreEqual (string.Empty, ccc.LocalName, "#8");
string localName = "mono";
ccc.LocalName = localName;
Assert.AreSame (localName, ccc.LocalName, "#9");
ccc.CatchExceptionType = null;
Assert.IsNotNull (ccc.CatchExceptionType, "#10");
Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#11");
CodeTypeReference cet = new CodeTypeReference("SomeException");
ccc.CatchExceptionType = cet;
Assert.AreSame (cet, ccc.CatchExceptionType, "#12");
}
示例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;
}
示例3: AddRange
/// <devdoc>
/// <para>Copies the elements of an array to the end of the <see cref='System.CodeDom.CodeCatchClauseCollection'/>.</para>
/// </devdoc>
public void AddRange(CodeCatchClause[] value) {
if (value == null) {
throw new ArgumentNullException("value");
}
for (int i = 0; ((i) < (value.Length)); i = ((i) + (1))) {
this.Add(value[i]);
}
}
示例4: CodeTryCatchFinallyStatement
public CodeTryCatchFinallyStatement (CodeStatement [] tryStatements,
CodeCatchClause [] catchClauses,
CodeStatement [] finallyStatements)
{
TryStatements.AddRange( tryStatements );
CatchClauses.AddRange( catchClauses );
FinallyStatements.AddRange( finallyStatements );
}
示例5: CodeTryCatchFinallyStatement
public CodeTryCatchFinallyStatement(CodeStatement[] tryStatements, CodeCatchClause[] catchClauses)
{
this.tryStatments = new CodeStatementCollection();
this.finallyStatments = new CodeStatementCollection();
this.catchClauses = new CodeCatchClauseCollection();
this.TryStatements.AddRange(tryStatements);
this.CatchClauses.AddRange(catchClauses);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:CodeTryCatchFinallyStatement.cs
示例6: Constructor1_NullItem
public void Constructor1_NullItem ()
{
CodeCatchClause[] catchClauses = new CodeCatchClause[] {
new CodeCatchClause (), null };
CodeCatchClauseCollection coll = new CodeCatchClauseCollection (
catchClauses);
}
示例7: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeCatchClause ccc = new CodeCatchClause ("mono");
Assert.AreEqual ("System.Exception", ccc.CatchExceptionType.BaseType, "CatchExceptionType.BaseType");
ccc.CatchExceptionType = new CodeTypeReference ("System.Void");
Assert.AreEqual ("mono", ccc.LocalName, "LocalName");
ccc.LocalName = String.Empty;
Assert.AreEqual (0, ccc.Statements.Count, "Statements");
}
示例8: Clone
public static CodeCatchClause Clone(this CodeCatchClause clause)
{
if (clause == null) return null;
CodeCatchClause c = new CodeCatchClause();
c.CatchExceptionType = clause.CatchExceptionType.Clone();
c.LocalName = clause.LocalName;
c.Statements.AddRange(clause.Statements.Clone());
return c;
}
示例9: 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");
}
示例10: Catch
private static CodeCatchClause Catch(System.Type type, string name, CodeStatement catchStmnt)
{
CodeCatchClause clause = new CodeCatchClause {
CatchExceptionType = Type(type),
LocalName = name
};
clause.Statements.Add(catchStmnt);
return clause;
}
示例11: AddRange
public void AddRange (CodeCatchClause [] value)
{
if (value == null) {
throw new ArgumentNullException ("value");
}
for (int i = 0; i < value.Length; i++) {
Add (value[i]);
}
}
示例12: PushCatch
public CodeDomStatments PushCatch(string localName)
{
Pop();
var SS = _Data.Peek();
var S = SS[SS.Count - 1] as CodeTryCatchFinallyStatement;
var c = new CodeCatchClause(localName);
S.CatchClauses.Add(c);
_Data.Push(c.Statements);
return this;
}
示例13: Catch
internal static CodeCatchClause Catch(CodeTypeReference type, string name, CodeStatement catchStmnt)
{
CodeCatchClause clause = new CodeCatchClause {
CatchExceptionType = type,
LocalName = name
};
if (catchStmnt != null)
{
clause.Statements.Add(catchStmnt);
}
return clause;
}
示例14: Constructor1
public void Constructor1 ()
{
CodeCatchClause cc1 = new CodeCatchClause ();
CodeCatchClause cc2 = new CodeCatchClause ();
CodeCatchClause[] catchClauses = new CodeCatchClause[] { cc1, cc2 };
CodeCatchClauseCollection coll = new CodeCatchClauseCollection (
catchClauses);
Assert.AreEqual (2, coll.Count, "#1");
Assert.AreEqual (0, coll.IndexOf (cc1), "#2");
Assert.AreEqual (1, coll.IndexOf (cc2), "#3");
}
示例15: Constructor2
public void Constructor2 ()
{
CodeCatchClause cc1 = new CodeCatchClause ();
CodeCatchClause cc2 = new CodeCatchClause ();
CodeCatchClauseCollection c = new CodeCatchClauseCollection ();
c.Add (cc1);
c.Add (cc2);
CodeCatchClauseCollection coll = new CodeCatchClauseCollection (c);
Assert.AreEqual (2, coll.Count, "#1");
Assert.AreEqual (0, coll.IndexOf (cc1), "#2");
Assert.AreEqual (1, coll.IndexOf (cc2), "#3");
}