本文整理汇总了C#中System.CodeDom.CodeStatement类的典型用法代码示例。如果您正苦于以下问题:C# CodeStatement类的具体用法?C# CodeStatement怎么用?C# CodeStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeStatement类属于System.CodeDom命名空间,在下文中一共展示了CodeStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddCallbackImplementation
internal static void AddCallbackImplementation(CodeTypeDeclaration codeClass, string callbackName, string handlerName, string handlerArgs, bool methodHasOutParameters)
{
CodeFlags[] parameterFlags = new CodeFlags[1];
CodeMemberMethod method = AddMethod(codeClass, callbackName, parameterFlags, new string[] { typeof(object).FullName }, new string[] { "arg" }, typeof(void).FullName, null, (CodeFlags) 0);
CodeEventReferenceExpression left = new CodeEventReferenceExpression(new CodeThisReferenceExpression(), handlerName);
CodeBinaryOperatorExpression condition = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
CodeStatement[] trueStatements = new CodeStatement[2];
trueStatements[0] = new CodeVariableDeclarationStatement(typeof(InvokeCompletedEventArgs), "invokeArgs", new CodeCastExpression(typeof(InvokeCompletedEventArgs), new CodeArgumentReferenceExpression("arg")));
CodeVariableReferenceExpression targetObject = new CodeVariableReferenceExpression("invokeArgs");
CodeObjectCreateExpression expression4 = new CodeObjectCreateExpression();
if (methodHasOutParameters)
{
expression4.CreateType = new CodeTypeReference(handlerArgs);
expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "Results"));
}
else
{
expression4.CreateType = new CodeTypeReference(typeof(AsyncCompletedEventArgs));
}
expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "Error"));
expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "Cancelled"));
expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "UserState"));
trueStatements[1] = new CodeExpressionStatement(new CodeDelegateInvokeExpression(new CodeEventReferenceExpression(new CodeThisReferenceExpression(), handlerName), new CodeExpression[] { new CodeThisReferenceExpression(), expression4 }));
method.Statements.Add(new CodeConditionStatement(condition, trueStatements, new CodeStatement[0]));
}
示例2: CreateProperty
/// <summary>
/// Creation method.
/// </summary>
/// <param name="className">Class name</param>
/// <param name="isGet">isGet flag</param>
/// <param name="member">Member</param>
/// <param name="statement">Statement</param>
/// <returns></returns>
/// <remarks>For properties.</remarks>
public static MethodInfo CreateProperty(string className,
bool isGet,
CodeTypeMember member,
CodeStatement statement)
{
return new MethodInfo(member, className, true, isGet, statement);
}
示例3: AddAsyncMethod
internal static CodeMemberMethod AddAsyncMethod(CodeTypeDeclaration codeClass, string methodName, string[] parameterTypeNames, string[] parameterNames, string callbackMember, string callbackName, string userState)
{
CodeMemberMethod method = AddMethod(codeClass, methodName, new CodeFlags[parameterNames.Length], parameterTypeNames, parameterNames, typeof(void).FullName, null, CodeFlags.IsPublic);
method.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true));
CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), methodName, new CodeExpression[0]);
for (int i = 0; i < parameterNames.Length; i++)
{
expression.Parameters.Add(new CodeArgumentReferenceExpression(parameterNames[i]));
}
expression.Parameters.Add(new CodePrimitiveExpression(null));
method.Statements.Add(expression);
method = AddMethod(codeClass, methodName, new CodeFlags[parameterNames.Length], parameterTypeNames, parameterNames, typeof(void).FullName, null, CodeFlags.IsPublic);
method.Comments.Add(new CodeCommentStatement(Res.GetString("CodeRemarks"), true));
method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), userState));
CodeFieldReferenceExpression left = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), callbackMember);
CodeBinaryOperatorExpression condition = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null));
CodeDelegateCreateExpression right = new CodeDelegateCreateExpression {
DelegateType = new CodeTypeReference(typeof(SendOrPostCallback)),
TargetObject = new CodeThisReferenceExpression(),
MethodName = callbackName
};
CodeStatement[] trueStatements = new CodeStatement[] { new CodeAssignStatement(left, right) };
method.Statements.Add(new CodeConditionStatement(condition, trueStatements, new CodeStatement[0]));
return method;
}
示例4: NotifyChanged
private void NotifyChanged(CollectionChangeAction action, CodeStatement option, int index)
{
if (_changed != null)
{
_changed(action, option, index);
}
}
示例5: EmitPragma
private static void EmitPragma(bool emitPragmas, CodeStatement statement, string fileName, int line)
{
if (emitPragmas)
{
statement.LinePragma = new CodeLinePragma(fileName, line);
}
}
示例6: DeserializeStatementToInstance
protected object DeserializeStatementToInstance(IDesignerSerializationManager manager, CodeStatement statement)
{
object obj2 = null;
CodeVariableDeclarationStatement statement3;
CodeAssignStatement statement2 = statement as CodeAssignStatement;
if (statement2 != null)
{
CodeFieldReferenceExpression left = statement2.Left as CodeFieldReferenceExpression;
if (left != null)
{
return base.DeserializeExpression(manager, left.FieldName, statement2.Right);
}
CodeVariableReferenceExpression expression2 = statement2.Left as CodeVariableReferenceExpression;
if (expression2 != null)
{
return base.DeserializeExpression(manager, expression2.VariableName, statement2.Right);
}
base.DeserializeStatement(manager, statement2);
return obj2;
}
if (((statement3 = statement as CodeVariableDeclarationStatement) != null) && (statement3.InitExpression != null))
{
return base.DeserializeExpression(manager, statement3.Name, statement3.InitExpression);
}
base.DeserializeStatement(manager, statement);
return obj2;
}
示例7: GenerateCodeFromStatement
public override void GenerateCodeFromStatement(CodeStatement statement,
TextWriter writer,
CodeGeneratorOptions options)
{
var codeExpressionStatement = statement as CodeExpressionStatement;
if (codeExpressionStatement != null)
{
var methodInvokeExpression =
codeExpressionStatement.Expression as CodeMethodInvokeExpression;
if (methodInvokeExpression != null)
{
if (methodInvokeExpression.Method.MethodName == "Write"
&& methodInvokeExpression.Parameters.Count == 1)
{
var parameter = methodInvokeExpression.Parameters[0] as CodeSnippetExpression;
if ((parameter != null) && (!string.IsNullOrEmpty(parameter.Value)))
{
// Appears to be a candidate for rewriting
string originalValue = parameter.Value;
var processor =
SnippetModifiers.OfType<ICodeSnippetTextModifier>()
.FirstOrDefault(m => m.CanProcessString(originalValue));
if (processor != null)
originalValue = processor.ProcessString(originalValue);
parameter.Value =
"global::" + GetType().FullName + ".PreProcessObject(this, "
+ originalValue + ")";
}
}
}
}
base.GenerateCodeFromStatement(statement, writer, options);
}
示例8: AddRange
public void AddRange(CodeStatement[] value)
{
foreach(CodeStatement e in value)
{
List.Add(e);
}
}
示例9: 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
示例10: CodeTryCatchFinallyStatement
public CodeTryCatchFinallyStatement (CodeStatement [] tryStatements,
CodeCatchClause [] catchClauses,
CodeStatement [] finallyStatements)
{
TryStatements.AddRange( tryStatements );
CatchClauses.AddRange( catchClauses );
FinallyStatements.AddRange( finallyStatements );
}
示例11: Constructor0_Deny_Unrestricted
public void Constructor0_Deny_Unrestricted ()
{
CodeStatement cs = new CodeStatement ();
Assert.IsNull (cs.LinePragma, "LinePragma");
cs.LinePragma = new CodeLinePragma (String.Empty, Int16.MinValue);
Assert.AreEqual (0, cs.StartDirectives.Count, "StartDirectives");
Assert.AreEqual (0, cs.EndDirectives.Count, "EndDirectives");
}
示例12: Clone
internal static CodeStatement Clone(CodeStatement statement)
{
if (statement == null)
{
return null;
}
return GetStatement(statement).Clone();
}
示例13: AddRange
/// <devdoc>
/// <para>Copies the elements of an array to the end of the <see cref='System.CodeDom.CodeStatementCollection'/>.</para>
/// </devdoc>
public void AddRange(CodeStatement[] value) {
if (value == null) {
throw new ArgumentNullException("value");
}
for (int i = 0; ((i) < (value.Length)); i = ((i) + (1))) {
this.Add(value[i]);
}
}
示例14: Constructor1_NullItem
public void Constructor1_NullItem ()
{
CodeStatement[] statements = new CodeStatement[] {
new CodeStatement (), null };
CodeStatementCollection coll = new CodeStatementCollection (
statements);
}
示例15: CodeConditionStatement
public CodeConditionStatement(CodeExpression condition,
CodeStatement[] trueStatements,
CodeStatement[] falseStatements)
{
this.condition = condition;
TrueStatements.AddRange(trueStatements);
FalseStatements.AddRange(falseStatements);
}