本文整理汇总了C#中System.CodeDom.CodeExpressionStatement类的典型用法代码示例。如果您正苦于以下问题:C# CodeExpressionStatement类的具体用法?C# CodeExpressionStatement怎么用?C# CodeExpressionStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeExpressionStatement类属于System.CodeDom命名空间,在下文中一共展示了CodeExpressionStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildAddContentPlaceHolderNames
private void BuildAddContentPlaceHolderNames(CodeMemberMethod method, string placeHolderID) {
CodePropertyReferenceExpression propertyExpr = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "ContentPlaceHolders");
CodeExpressionStatement stmt = new CodeExpressionStatement();
stmt.Expression = new CodeMethodInvokeExpression(propertyExpr, "Add", new CodePrimitiveExpression(placeHolderID.ToLower(CultureInfo.InvariantCulture)));
method.Statements.Add(stmt);
}
示例2: Process
/// <summary>
/// Generates code in the class area of the transformation class created by the T4 engine.
/// </summary>
/// <param name="arguments">The arguments for the directive.</param>
protected override void Process(IDictionary<string, string> arguments)
{
// Don't generate the same code more then once if T4Toolbox.tt happens to be included multiple times
if (this.directiveProcessed)
{
this.Warning("Multiple <#@ include file=\"T4Toolbox.tt\" #> directives were found in the template.");
return;
}
this.References.Add(typeof(TransformationContext).Assembly.Location);
// Add the following method call to the Initialize method of the generated text template.
// T4Toolbox.TransformationContext.Initialize(this, this.GenerationEnvironment);
var initialize = new CodeExpressionStatement(
new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(typeof(TransformationContext).FullName),
"Initialize",
new CodeThisReferenceExpression(),
new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "GenerationEnvironment")));
this.LanguageProvider.GenerateCodeFromStatement(initialize, this.PreInitializationCode, null);
// Add the following method call to the Dispose(bool) method of the generated text template.
// T4Toolbox.TransformationContext.Cleanup();
var cleanup = new CodeExpressionStatement(
new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(typeof(TransformationContext).FullName),
"Cleanup"));
this.LanguageProvider.GenerateCodeFromStatement(cleanup, this.DisposeCode, null);
this.directiveProcessed = true;
}
示例3: GenerateCallStatementC2J
private CodeStatement GenerateCallStatementC2J(GMethod method, CodeExpression invokeExpression)
{
CodeStatement call;
if (method.IsConstructor || method.IsVoid)
{
call = new CodeExpressionStatement(invokeExpression);
}
else
{
if (method.ReturnType.IsPrimitive)
{
if (method.ReturnType.JVMSubst != null)
{
invokeExpression = new CodeCastExpression(method.ReturnType.CLRReference, invokeExpression);
}
call = new CodeMethodReturnStatement(invokeExpression);
}
else
{
CodeMethodInvokeExpression conversionExpression = CreateConversionExpressionJ2CParam(method.ReturnType,
invokeExpression);
call = new CodeMethodReturnStatement(conversionExpression);
}
}
return call;
}
示例4: CreateMethod
CodeMemberMethod CreateMethod()
{
CodeMemberMethod method = new CodeMemberMethod();
// BeginInit method call.
CodeExpressionStatement statement = new CodeExpressionStatement();
CodeMethodInvokeExpression methodInvoke = new CodeMethodInvokeExpression();
statement.Expression = methodInvoke;
CodeMethodReferenceExpression methodRef = new CodeMethodReferenceExpression();
methodRef.MethodName = "BeginInit";
CodeCastExpression cast = new CodeCastExpression();
cast.TargetType = new CodeTypeReference();
cast.TargetType.BaseType = "System.ComponentModel.ISupportInitialize";
CodeFieldReferenceExpression fieldRef = new CodeFieldReferenceExpression();
fieldRef.FieldName = "pictureBox1";
fieldRef.TargetObject = new CodeThisReferenceExpression();
cast.Expression = fieldRef;
methodRef.TargetObject = cast;
methodInvoke.Method = methodRef;
method.Statements.Add(statement);
return method;
}
示例5: Serialize
public override object Serialize (IDesignerSerializationManager manager, object value)
{
if (value == null)
throw new ArgumentNullException ("value");
if (manager == null)
throw new ArgumentNullException ("manager");
if (!(value is Control))
throw new InvalidOperationException ("value is not a Control");
object serialized = base.Serialize (manager, value);
CodeStatementCollection statements = serialized as CodeStatementCollection;
if (statements != null) { // the root control is serialized to CodeExpression
ICollection childControls = TypeDescriptor.GetProperties (value)["Controls"].GetValue (value) as ICollection;
if (childControls.Count > 0) {
CodeExpression componentRef = base.GetExpression (manager, value);
CodeStatement statement = new CodeExpressionStatement (
new CodeMethodInvokeExpression (componentRef, "SuspendLayout"));
statement.UserData["statement-order"] = "begin";
statements.Add (statement);
statement = new CodeExpressionStatement (
new CodeMethodInvokeExpression (componentRef, "ResumeLayout",
new CodeExpression[] {
new CodePrimitiveExpression (false) }));
statement.UserData["statement-order"] = "end";
statements.Add (statement);
serialized = statements;
}
}
return serialized;
}
示例6: 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]));
}
示例7: getInvokeDetailStatement
private static CodeExpressionStatement getInvokeDetailStatement(RecordStep step, string dataClass)
{
CodeExpressionStatement statement = new CodeExpressionStatement();
CodeExpression[] paras;
if (step.ActionParams != null)
{
paras = new CodeExpression[step.ActionParams.Count];
///判断是否参数化函数代码
if(dataClass == null)
{
for (int i = 0; i < step.ActionParams.Count; i++)
{
paras[i] = new CodePrimitiveExpression(step.ActionParams[i].Value);
}
}
else
{
for (int i = 0; i < step.ActionParams.Count; i++)
{
paras[i] = step.ActionParams[i].GetVariableReference(dataClass);
}
}
}
else
{
paras = new CodeExpression[0];
}
CodeMethodInvokeExpression method = new CodeMethodInvokeExpression(step.CompInfo.FindMethod, step.ActionName, paras);
statement.Expression = method;
return statement;
}
示例8: GetCodeStatement
public static List<CodeStatement> GetCodeStatement(this RecordStep step,string dataClassParameter = null)
{
List<CodeStatement> codes = new List<CodeStatement>();
CodeStatement actionCode = null;
switch (step.Action)
{
case BindingFlags.SetProperty:
actionCode = getAssignDetailStatement(step, dataClassParameter);
break;
case BindingFlags.InvokeMethod:
actionCode = getInvokeDetailStatement(step, dataClassParameter);
break;
default:
break;
}
if (actionCode != null)
codes.Add(actionCode);
if(step.TakeScreenShot)
{
CodeExpressionStatement screenShotCode = new CodeExpressionStatement();
screenShotCode.Expression = new CodeMethodInvokeExpression(
new CodeVariableReferenceExpression("SAPTestHelper.Current"),
"TakeScreenShot",
new CodePrimitiveExpression(step.StepId.ToString() + ".jpg"));
codes.Add(screenShotCode);
}
return codes;
}
示例9: BuildAddContentPlaceHolderNames
private void BuildAddContentPlaceHolderNames(CodeMemberMethod method, string placeHolderID)
{
CodePropertyReferenceExpression targetObject = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "ContentPlaceHolders");
CodeExpressionStatement statement = new CodeExpressionStatement {
Expression = new CodeMethodInvokeExpression(targetObject, "Add", new CodeExpression[] { new CodePrimitiveExpression(placeHolderID.ToLower(CultureInfo.InvariantCulture)) })
};
method.Statements.Add(statement);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:MasterPageCodeDomTreeGenerator.cs
示例10: AddDisposalOfMember
public static void AddDisposalOfMember(CodeMemberMethod disposeMethod, string memberName)
{
CodeBinaryOperatorExpression isnull = new CodeBinaryOperatorExpression(new CodeVariableReferenceExpression(memberName), CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
CodeExpressionStatement callDispose = new CodeExpressionStatement(new CodeMethodInvokeExpression(new CodeVariableReferenceExpression(memberName), "Dispose"));
//add dispose code
disposeMethod.Statements.Add(new CodeConditionStatement(isnull, callDispose));
}
示例11: Clone
public static CodeExpressionStatement Clone(this CodeExpressionStatement statement)
{
if (statement == null) return null;
CodeExpressionStatement s = new CodeExpressionStatement();
s.EndDirectives.AddRange(statement.EndDirectives);
s.Expression = statement.Expression.Clone();
s.LinePragma = statement.LinePragma;
s.StartDirectives.AddRange(statement.StartDirectives);
s.UserData.AddRange(statement.UserData);
return s;
}
示例12: TypescriptExpressionStatement
public TypescriptExpressionStatement(
IStatementFactory statementFactory,
IExpressionFactory expressionFactory,
CodeExpressionStatement statement,
CodeGeneratorOptions options)
{
_statementFactory = statementFactory;
_expressionFactory = expressionFactory;
_statement = statement;
_options = options;
}
示例13: EmitExpressionStatement
Type EmitExpressionStatement(CodeExpressionStatement Expression, bool ForceTypes)
{
Depth++;
Debug("Emitting expression statement");
Type Generated = EmitExpression(Expression.Expression, ForceTypes);
if (Generated != typeof(void))
Generator.Emit(OpCodes.Pop);
Depth--;
return Generated;
}
示例14: GetKeywordFromCodeDom
public void GetKeywordFromCodeDom()
{
CodeStatement st = new CodeExpressionStatement(new CodeArgumentReferenceExpression("foo"));
CodeExpression exp = new CodeArgumentReferenceExpression("foo");
CodeIterationStatement it = new CodeIterationStatement(st, exp, st);
CodeConditionStatement cond = new CodeConditionStatement(exp);
new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromStatement(
it, Console.Out, new System.CodeDom.Compiler.CodeGeneratorOptions());
new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromStatement(
cond, Console.Out, new System.CodeDom.Compiler.CodeGeneratorOptions());
new Microsoft.VisualBasic.VBCodeProvider().GenerateCodeFromStatement(
it, Console.Out, new System.CodeDom.Compiler.CodeGeneratorOptions());
new Microsoft.VisualBasic.VBCodeProvider().GenerateCodeFromStatement(
cond, Console.Out, new System.CodeDom.Compiler.CodeGeneratorOptions());
}
示例15: CreatePropertySetStatements
internal static void CreatePropertySetStatements(CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeExpression target, string targetPropertyName, Type destinationType, CodeExpression value, CodeLinePragma linePragma)
{
bool flag = false;
if (destinationType == null)
{
flag = true;
}
if (flag)
{
CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression();
CodeExpressionStatement statement = new CodeExpressionStatement(expression) {
LinePragma = linePragma
};
expression.Method.TargetObject = new CodeCastExpression(typeof(IAttributeAccessor), target);
expression.Method.MethodName = "SetAttribute";
expression.Parameters.Add(new CodePrimitiveExpression(targetPropertyName));
expression.Parameters.Add(GenerateConvertToString(value));
statements.Add(statement);
}
else if (destinationType.IsValueType)
{
CodeAssignStatement statement2 = new CodeAssignStatement(BuildPropertyReferenceExpression(target, targetPropertyName), new CodeCastExpression(destinationType, value)) {
LinePragma = linePragma
};
statements.Add(statement2);
}
else
{
CodeExpression expression2;
if (destinationType == typeof(string))
{
expression2 = GenerateConvertToString(value);
}
else
{
expression2 = new CodeCastExpression(destinationType, value);
}
CodeAssignStatement statement3 = new CodeAssignStatement(BuildPropertyReferenceExpression(target, targetPropertyName), expression2) {
LinePragma = linePragma
};
statements.Add(statement3);
}
}