本文整理汇总了C#中System.CodeDom.CodeStatementCollection.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# CodeStatementCollection.RemoveAt方法的具体用法?C# CodeStatementCollection.RemoveAt怎么用?C# CodeStatementCollection.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.CodeDom.CodeStatementCollection
的用法示例。
在下文中一共展示了CodeStatementCollection.RemoveAt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CorrectStatements
private void CorrectStatements(string name, CodeStatementCollection stmts, CodeTypeReference returnType)
{
_name = name;
_referenceCount = 0;
new CodeDomWalker(stmts).Walk(RenameReturnValue);
_name = null;
CodeObjectSource source = Utils.GetTypeReferenceSource(returnType);
Type type = (source == null ? null : source.Target as Type);
CodeExpression defaultExpr = (type != null && type.IsPrimitive
? (CodeExpression) new CodeDefaultValueExpression(returnType)
: new CodePrimitiveExpression(null));
CodeExpression returnExpr = null;
if (_referenceCount > 0)
{
bool requiresDeclaration = true;
CodeAssignStatement assignStmt = stmts[stmts.Count - 1] as CodeAssignStatement;
if (assignStmt != null)
{
CodeVariableReferenceExpression variableStmt = assignStmt.Left as CodeVariableReferenceExpression;
if (variableStmt != null && StringUtils.CaseInsensitiveEquals(variableStmt.VariableName, _returnVariableName))
{
stmts.RemoveAt(stmts.Count - 1);
returnExpr = assignStmt.Right;
requiresDeclaration = (_referenceCount > 1);
}
}
if (requiresDeclaration)
{
CodeExpression initExpression = null;
assignStmt = stmts[0] as CodeAssignStatement;
if (assignStmt != null)
{
CodeVariableReferenceExpression variableStmt = assignStmt.Left as CodeVariableReferenceExpression;
if (variableStmt != null && StringUtils.CaseInsensitiveEquals(variableStmt.VariableName, _returnVariableName))
{
stmts.RemoveAt(0);
initExpression = assignStmt.Right;
}
}
if (initExpression == null)
{
initExpression = defaultExpr;
}
stmts.Insert(
0,
new CodeVariableDeclarationStatement(
returnType,
_returnVariableName,
initExpression));
}
if (returnExpr == null)
{
returnExpr = new CodeVariableReferenceExpression(_returnVariableName);
}
}
else
{
returnExpr = defaultExpr;
}
stmts.Add(new CodeMethodReturnStatement(returnExpr));
}
示例2: ExtractCtorStatement
private CodeStatement ExtractCtorStatement (CodeStatementCollection statements)
{
CodeStatement result = null;
CodeAssignStatement assignment = null;
int toRemove = -1;
for (int i=0; i < statements.Count; i++) {
assignment = statements[i] as CodeAssignStatement;
if (assignment != null && assignment.Right is CodeObjectCreateExpression) {
result = assignment;
toRemove = i;
}
}
if (toRemove != -1)
statements.RemoveAt (toRemove);
return result;
}
示例3: ExtractCtorStatement
// Used to remove the ctor from the statement colletion in order for the ctor statement to be moved.
//
private CodeStatement ExtractCtorStatement (IDesignerSerializationManager manager, CodeStatementCollection statements,
object component)
{
CodeStatement result = null;
CodeAssignStatement assignment = null;
CodeObjectCreateExpression ctor = null;
int toRemove = -1;
for (int i=0; i < statements.Count; i++) {
assignment = statements[i] as CodeAssignStatement;
if (assignment != null) {
ctor = assignment.Right as CodeObjectCreateExpression;
if (ctor != null && manager.GetType (ctor.CreateType.BaseType) == component.GetType ()) {
result = assignment;
toRemove = i;
}
}
}
if (toRemove != -1)
statements.RemoveAt (toRemove);
return result;
}