本文整理汇总了C#中System.CodeDom.CodeCatchClause类的典型用法代码示例。如果您正苦于以下问题:C# CodeCatchClause类的具体用法?C# CodeCatchClause怎么用?C# CodeCatchClause使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeCatchClause类属于System.CodeDom命名空间,在下文中一共展示了CodeCatchClause类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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");
}
开发者ID:nlhepler,项目名称:mono,代码行数:29,代码来源:CodeCatchClauseTest.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: 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]);
}
}
开发者ID:uQr,项目名称:referencesource,代码行数:11,代码来源:CodeCatchClauseCollection.cs
示例4: CodeTryCatchFinallyStatement
public CodeTryCatchFinallyStatement (CodeStatement [] tryStatements,
CodeCatchClause [] catchClauses,
CodeStatement [] finallyStatements)
{
TryStatements.AddRange( tryStatements );
CatchClauses.AddRange( catchClauses );
FinallyStatements.AddRange( finallyStatements );
}
开发者ID:NelsonSantos,项目名称:fyiReporting-Android,代码行数:8,代码来源:CodeTryCatchFinallyStatement.cs
示例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);
}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:CodeCatchClauseCollectionTest.cs
示例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");
}
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:CodeCatchClauseCas.cs
示例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;
}
开发者ID:jw56578,项目名称:SpecFlowTest,代码行数:9,代码来源:CodeCatchClauseExtensions.cs
示例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");
}
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:CodeTryCatchFinallyStatementCas.cs
示例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;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:9,代码来源:TypedDataSetGenerator.cs
示例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]);
}
}
开发者ID:NelsonSantos,项目名称:fyiReporting-Android,代码行数:10,代码来源:CodeCatchClauseCollection.cs
示例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;
}
开发者ID:DzmitrySo,项目名称:mc,代码行数:10,代码来源:CodeDomStatments.cs
示例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;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:12,代码来源:CodeGenHelper.cs
示例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");
}
开发者ID:nlhepler,项目名称:mono,代码行数:13,代码来源:CodeCatchClauseCollectionTest.cs
示例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");
}
开发者ID:nlhepler,项目名称:mono,代码行数:14,代码来源:CodeCatchClauseCollectionTest.cs
示例16: 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
示例17: Constructor1
public void Constructor1 () {
string localName = "mono";
CodeCatchClause ccc = new CodeCatchClause (localName);
Assert.IsNotNull (ccc.CatchExceptionType, "#1");
Assert.AreEqual (typeof(Exception).FullName, ccc.CatchExceptionType.BaseType, "#2");
Assert.IsNotNull (ccc.LocalName, "#3");
Assert.AreEqual (localName, ccc.LocalName, "#4");
Assert.AreSame (localName, ccc.LocalName, "#5");
Assert.IsNotNull (ccc.Statements, "#6");
Assert.AreEqual (0, ccc.Statements.Count, "#7");
ccc.LocalName = null;
Assert.IsNotNull (ccc.LocalName, "#8");
Assert.AreEqual (string.Empty, ccc.LocalName, "#9");
ccc = new CodeCatchClause ((string) null);
Assert.IsNotNull (ccc.LocalName, "#10");
Assert.AreEqual (string.Empty, ccc.LocalName, "#22");
}
开发者ID:nlhepler,项目名称:mono,代码行数:23,代码来源:CodeCatchClauseTest.cs
示例18: Insert
/// <devdoc>
/// <para>Inserts a <see cref='System.CodeDom.CodeCatchClause'/> into the <see cref='System.CodeDom.CodeCatchClauseCollection'/> at the specified index.</para>
/// </devdoc>
public void Insert(int index, CodeCatchClause value) {
List.Insert(index, value);
}
开发者ID:uQr,项目名称:referencesource,代码行数:6,代码来源:CodeCatchClauseCollection.cs
示例19: Remove
public void Remove ()
{
CodeCatchClause ccc1 = new CodeCatchClause ();
CodeCatchClause ccc2 = new CodeCatchClause ();
CodeCatchClauseCollection coll = new CodeCatchClauseCollection ();
coll.Add (ccc1);
coll.Add (ccc2);
Assert.AreEqual (2, coll.Count, "#1");
Assert.AreEqual (0, coll.IndexOf (ccc1), "#2");
Assert.AreEqual (1, coll.IndexOf (ccc2), "#3");
coll.Remove (ccc1);
Assert.AreEqual (1, coll.Count, "#4");
Assert.AreEqual (-1, coll.IndexOf (ccc1), "#5");
Assert.AreEqual (0, coll.IndexOf (ccc2), "#6");
}
开发者ID:nlhepler,项目名称:mono,代码行数:16,代码来源:CodeCatchClauseCollectionTest.cs
示例20: GetThrowClause
/// <summary>
/// Gets the throw clause.
/// </summary>
/// <returns>return catch...throw statment</returns>
internal static CodeCatchClause[] GetThrowClause()
{
var catchStatmanents = new CodeStatementCollection();
catchStatmanents.Add(new CodeThrowExceptionStatement(new CodeVariableReferenceExpression("ex")));
var catchClause = new CodeCatchClause(
"ex",
new CodeTypeReference(typeof(Exception)),
catchStatmanents.ToArray());
var catchClauses = new[] { catchClause };
return catchClauses;
}
开发者ID:cteiosanu,项目名称:Xsd2Code,代码行数:16,代码来源:CodeDomHelper.cs
注:本文中的System.CodeDom.CodeCatchClause类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论