本文整理汇总了C#中ThrowStatement类的典型用法代码示例。如果您正苦于以下问题:C# ThrowStatement类的具体用法?C# ThrowStatement怎么用?C# ThrowStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThrowStatement类属于命名空间,在下文中一共展示了ThrowStatement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Complete
public override void Complete(CompletionContext context)
{
var invokeSignature = delegateType.GetMethods(m => m.Name == "Invoke").Single();
var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None);
var builder = refactoringContext.CreateTypeSystemAstBuilder();
var handlerName = eventDefinition.Name;
var throwStatement = new ThrowStatement();
var decl = new MethodDeclaration {
ReturnType = refactoringContext.CreateShortType(invokeSignature.ReturnType),
Name = handlerName,
Body = new BlockStatement {
throwStatement
}
};
decl.Parameters.AddRange(invokeSignature.Parameters.Select(builder.ConvertParameter));
if (eventDefinition.IsStatic)
decl.Modifiers |= Modifiers.Static;
throwStatement.Expression = new ObjectCreateExpression(refactoringContext.CreateShortType("System", "NotImplementedException"));
// begin insertion
using (context.Editor.Document.OpenUndoGroup()) {
context.Editor.Document.Replace(context.StartOffset, context.Length, handlerName);
context.EndOffset = context.StartOffset + handlerName.Length;
using (var script = refactoringContext.StartScript()) {
script.InsertWithCursor(this.DisplayText, Script.InsertPosition.Before, decl)
// TODO : replace with Link, once that is implemented
.ContinueScript(() => script.Select(throwStatement));
}
}
}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:35,代码来源:EventCreationCompletionData.cs
示例2: ThrowStatementHasProperties
public void ThrowStatementHasProperties()
{
var statement = new ThrowStatement(null);
statement.Expression = 1;
Assert.AreEqual(JS.Number(1), statement.Expression);
Assert.AreEqual("throw 1;", statement.ToString());
}
开发者ID:DaveVdE,项目名称:adamjsgenerator,代码行数:9,代码来源:ThrowStatementTests.cs
示例3: VisitThrowStatement
public override void VisitThrowStatement(ThrowStatement throwStatement)
{
var result = ctx.Resolve(throwStatement.Expression);
if (result.Type.Equals(ctx.Compilation.FindType(typeof(System.NotImplementedException)))) {
AddIssue(throwStatement, ctx.TranslateString("NotImplemented exception thrown"));
}
base.VisitThrowStatement(throwStatement);
}
开发者ID:kaagati,项目名称:NRefactory,代码行数:9,代码来源:NotImplementedExceptionIssue.cs
示例4: VisitThrowStatement
public override object VisitThrowStatement(ThrowStatement throwStatement, object data)
{
if (throwStatement.Expression is ObjectCreateExpression)
{
var expr = (ObjectCreateExpression)throwStatement.Expression;
var typeRef = expr.Type as SimpleType;
if (typeRef != null && typeRef.Identifier == "NotImplementedException")
{
UnlockWith(throwStatement.Expression);
}
}
return base.VisitThrowStatement(throwStatement, data);
}
开发者ID:clausjoergensen,项目名称:strokes,代码行数:14,代码来源:ThrownNotImplementedAchievement.cs
示例5: Complete
public override void Complete(CompletionContext context)
{
var invokeSignature = delegateType.GetMethods(m => m.Name == "Invoke").Single();
var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None);
var builder = refactoringContext.CreateTypeSystemAstBuilder();
string handlerName;
bool isStatic;
if (eventDefinition != null) {
handlerName = eventDefinition.Name;
isStatic = eventDefinition.IsStatic;
} else {
handlerName = varName;
isStatic = callingMember.IsStatic;
}
var throwStatement = new ThrowStatement();
var decl = new MethodDeclaration {
ReturnType = refactoringContext.CreateShortType(invokeSignature.ReturnType),
Name = handlerName,
Body = new BlockStatement {
throwStatement
}
};
decl.Parameters.AddRange(invokeSignature.Parameters.Select(builder.ConvertParameter));
if (isStatic)
decl.Modifiers |= Modifiers.Static;
throwStatement.Expression = new ObjectCreateExpression(refactoringContext.CreateShortType("System", "NotImplementedException"));
// begin insertion
using (context.Editor.Document.OpenUndoGroup()) {
context.Editor.Document.Replace(context.StartOffset, context.Length, handlerName + ";");
context.EndOffset = context.StartOffset + handlerName.Length;
var loc = context.Editor.Document.GetLocation(context.StartOffset + handlerName.Length / 2 + 1);
var parseInfo = SD.ParserService.Parse(context.Editor.FileName, context.Editor.Document) as CSharpFullParseInformation;
if (parseInfo == null) return;
using (var script = refactoringContext.StartScript()) {
var node = parseInfo.SyntaxTree.GetNodeAt(loc, n => n is Identifier || n is IdentifierExpression);
if (node == null) return;
script.InsertWithCursor(this.DisplayText, Script.InsertPosition.Before, decl)
.ContinueScript(() => script.Link(decl.NameToken, node).ContinueScript(() => script.Select(throwStatement)));
}
}
}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:48,代码来源:EventCreationCompletionData.cs
示例6: InsertEventHandler
public override void InsertEventHandler(ITypeDefinition target, string name, IEvent eventDefinition, bool jumpTo)
{
IUnresolvedTypeDefinition match = null;
foreach (var part in target.Parts) {
if (match == null || EntityModelContextUtils.IsBetterPart(part, match, ".cs"))
match = part;
}
if (match == null) return;
var view = SD.FileService.OpenFile(new FileName(match.Region.FileName), jumpTo);
var editor = view.GetRequiredService<ITextEditor>();
var last = match.Members.LastOrDefault() ?? (IUnresolvedEntity)match;
editor.Caret.Location = last.BodyRegion.End;
var context = SDRefactoringContext.Create(editor, CancellationToken.None);
var node = context.RootNode.GetNodeAt<EntityDeclaration>(last.Region.Begin);
var resolver = context.GetResolverStateAfter(node);
var builder = new TypeSystemAstBuilder(resolver);
var delegateDecl = builder.ConvertEntity(eventDefinition.ReturnType.GetDefinition()) as DelegateDeclaration;
if (delegateDecl == null) return;
var throwStmt = new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException")));
var decl = new MethodDeclaration() {
ReturnType = delegateDecl.ReturnType.Clone(),
Name = name,
Body = new BlockStatement() {
throwStmt
}
};
var param = delegateDecl.Parameters.Select(p => p.Clone()).OfType<ParameterDeclaration>().ToArray();
decl.Parameters.AddRange(param);
using (Script script = context.StartScript()) {
// FIXME : will not work properly if there are no members.
if (last == match) {
throw new NotImplementedException();
// TODO InsertWithCursor not implemented!
//script.InsertWithCursor("Insert event handler", Script.InsertPosition.End, decl).RunSynchronously();
} else {
// TODO does not jump correctly...
script.InsertAfter(node, decl);
editor.JumpTo(throwStmt.StartLocation.Line, throwStmt.StartLocation.Column);
}
}
}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:46,代码来源:CSharpCodeGenerator.cs
示例7: AcceptThrow
public void AcceptThrow(ThrowStatement stmt)
{
Check(stmt);
}
开发者ID:venusdharan,项目名称:systemsharp,代码行数:4,代码来源:HierarchyAnalysis.cs
示例8: VisitThrowStatement
public virtual void VisitThrowStatement (ThrowStatement throwStatement)
{
VisitChildren (throwStatement);
}
开发者ID:modulexcite,项目名称:ICSharpCode.Decompiler-retired,代码行数:4,代码来源:DepthFirstAstVisitor.cs
示例9: PostWalk
protected internal virtual void PostWalk(ThrowStatement node) { }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:1,代码来源:Walker.Generated.cs
示例10: Enter
public override bool Enter(ThrowStatement node)
{
Print("ThrowStatement");
level++;
return true;
}
开发者ID:buunguyen,项目名称:bike,代码行数:6,代码来源:PrintNodeWalker.cs
示例11: Exit
public virtual void Exit(ThrowStatement node)
{
}
开发者ID:buunguyen,项目名称:bike,代码行数:3,代码来源:EnterForWalkerGenerator.cs
示例12: Statement
//.........这里部分代码省略.........
catchVar.NameHash = DTokens.IncompleteIdHash;
catchVar.EndLocation = t.EndLocation;
c.CatchParameter = catchVar;
}
}
if(!IsEOF)
c.ScopedStatement = Statement(Scope: Scope, Parent: c);
c.EndLocation = t.EndLocation;
catches.Add(c);
}
if (catches.Count > 0)
ts.Catches = catches.ToArray();
if (laKind == (Finally))
{
Step();
var f = new TryStatement.FinallyStatement() { Location = t.Location, Parent = Parent };
f.ScopedStatement = Statement();
f.EndLocation = t.EndLocation;
ts.FinallyStmt = f;
}
ts.EndLocation = t.EndLocation;
return ts;
case Throw:
Step();
var ths = new ThrowStatement() { Location = t.Location, Parent = Parent };
ths.ThrowExpression = Expression(Scope);
Expect(Semicolon);
ths.EndLocation = t.EndLocation;
return ths;
case DTokens.Scope:
Step();
if (laKind == OpenParenthesis)
{
var s = new ScopeGuardStatement() {
Location = t.Location,
Parent = Parent
};
Step();
if (Expect(Identifier) && t.Value != null) // exit, failure, success
s.GuardedScope = t.Value.ToLower();
else if (IsEOF)
s.GuardedScope = DTokens.IncompleteId;
Expect(CloseParenthesis);
s.ScopedStatement = Statement(Scope: Scope, Parent: s);
s.EndLocation = t.EndLocation;
return s;
}
else
PushAttribute(new Modifier(DTokens.Scope), false);
开发者ID:rainers,项目名称:D_Parser,代码行数:67,代码来源:Parser_Impl.cs
示例13: VisitThrowStatement
public override void VisitThrowStatement(ThrowStatement throwStatement)
{
if (throwStatement.Expression.IsNull) {
_result.Add(new JsThrowStatement(JsExpression.Identifier(_variables[_currentVariableForRethrow].Name)));
}
else {
var compiledExpr = CompileExpression(throwStatement.Expression, true);
_result.AddRange(compiledExpr.AdditionalStatements);
_result.Add(new JsThrowStatement(compiledExpr.Expression));
}
}
开发者ID:jack128,项目名称:SaltarelleCompiler,代码行数:11,代码来源:StatementCompiler.cs
示例14: InsertEventHandler
public override void InsertEventHandler(ITypeDefinition target, string name, IEvent eventDefinition, bool jumpTo, InsertEventHandlerBodyKind bodyKind = InsertEventHandlerBodyKind.ThrowNotImplementedException)
{
IUnresolvedTypeDefinition match = null;
foreach (var part in target.Parts) {
if (match == null || EntityModelContextUtils.IsBetterPart(part, match, ".cs"))
match = part;
}
if (match == null) return;
var view = SD.FileService.OpenFile(new FileName(match.Region.FileName), jumpTo);
var editor = view.GetRequiredService<ITextEditor>();
var last = match.Members.LastOrDefault() ?? (IUnresolvedEntity)match;
editor.Caret.Location = last.BodyRegion.End;
var context = SDRefactoringContext.Create(editor, CancellationToken.None);
var node = context.RootNode.GetNodeAt<EntityDeclaration>(last.Region.Begin);
var resolver = context.GetResolverStateAfter(node);
var builder = new TypeSystemAstBuilder(resolver);
var invokeMethod = eventDefinition.ReturnType.GetDelegateInvokeMethod();
if (invokeMethod == null) return;
var importedMethod = resolver.Compilation.Import(invokeMethod);
var delegateDecl = builder.ConvertEntity(importedMethod) as MethodDeclaration;
if (delegateDecl == null) return;
var throwStmt = new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException")));
var decl = new MethodDeclaration() {
ReturnType = delegateDecl.ReturnType.Clone(),
Name = name,
Body = new BlockStatement() {
throwStmt
}
};
var param = delegateDecl.Parameters.Select(p => p.Clone()).ToArray();
decl.Parameters.AddRange(param);
using (Script script = context.StartScript()) {
int eolLen = 0;
if (last == match) {
eolLen = 2;
script.AddTo((TypeDeclaration)node, decl);
} else {
script.InsertAfter(node, decl);
}
switch (bodyKind) {
case InsertEventHandlerBodyKind.TodoComment:
Comment comment = new Comment(" TODO: Implement " + name);
script.Replace(throwStmt, comment);
script.Select(comment);
break;
case InsertEventHandlerBodyKind.Nothing:
var segment = script.GetSegment(throwStmt);
if (script is DocumentScript && eolLen > 0) {
eolLen = ((DocumentScript)script).CurrentDocument.GetLineByOffset(segment.Offset).DelimiterLength;
}
script.RemoveText(segment.Offset, segment.Length - eolLen);
script.Select(segment.Offset, segment.Offset);
break;
case InsertEventHandlerBodyKind.ThrowNotImplementedException:
script.Select(throwStmt);
break;
}
}
}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:64,代码来源:CSharpCodeGenerator.cs
示例15: Visit
public override void Visit(ThrowStatement node) { this.action(node); }
开发者ID:yaakoviyun,项目名称:sqlskim,代码行数:1,代码来源:AllNodesVisitor.cs
示例16: VisitThrowStatement
public virtual void VisitThrowStatement(ThrowStatement throwStatement)
{
if (this.ThrowException)
{
throw (Exception)this.CreateException(throwStatement);
}
}
开发者ID:fabriciomurta,项目名称:BridgeUnified,代码行数:7,代码来源:Visitor.Exception.cs
示例17: Enter
public virtual bool Enter(ThrowStatement node)
{
return true;
}
开发者ID:buunguyen,项目名称:bike,代码行数:4,代码来源:EnterForWalkerGenerator.cs
示例18: VisitThrowStatement
public void VisitThrowStatement(ThrowStatement throwStatement)
{
VisitExpression(throwStatement.Expression);
if (CurrentFunction != null && ReturnValue is string) {
ArrayProxy<TypeSummary> p = (ArrayProxy<TypeSummary>)CurrentFunction[NodeNames.Exception];
if (p == null) {
CurrentFunction[NodeNames.Exception] = p = new ArrayProxy<TypeSummary>();
}
p.Add(new TypeSummary { Summary = (string)ReturnValue, Type = "String" });
}
}
开发者ID:xuld,项目名称:DocPlus,代码行数:16,代码来源:DocAstVistor.cs
示例19: VisitThrowStatement
public override void VisitThrowStatement(ThrowStatement throwStatement) {
if (throwStatement.Expression.IsNull) {
_result.Add(JsStatement.Throw(JsExpression.Identifier(_variables[_currentVariableForRethrow].Name)));
}
else {
var compiledExpr = CompileExpression(throwStatement.Expression, CompileExpressionFlags.ReturnValueIsImportant);
_result.AddRange(compiledExpr.AdditionalStatements);
_result.Add(JsStatement.Throw(compiledExpr.Expression));
}
}
开发者ID:chenxustu1,项目名称:SaltarelleCompiler,代码行数:10,代码来源:StatementCompiler.cs
示例20: AcceptThrow
public void AcceptThrow(ThrowStatement stmt)
{
}
开发者ID:venusdharan,项目名称:systemsharp,代码行数:3,代码来源:StatementRemoval.cs
注:本文中的ThrowStatement类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论