本文整理汇总了C#中System.CodeDom.CodeExpression类的典型用法代码示例。如果您正苦于以下问题:C# CodeExpression类的具体用法?C# CodeExpression怎么用?C# CodeExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeExpression类属于System.CodeDom命名空间,在下文中一共展示了CodeExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CodeVariableDeclarationStatement
public CodeVariableDeclarationStatement(Type type, String name,
CodeExpression initExpression)
{
this.type = new CodeTypeReference(type);
this.name = name;
this.initExpression = initExpression;
}
示例2: SerializeCell
object SerializeCell(IDesignerSerializationManager manager, CodeExpression target, Cell cell)
{
object codeObject = null;
ExpressionContext context = null;
ExpressionContext context2 = manager.Context[typeof(ExpressionContext)] as ExpressionContext;
if (context2 != null)
{
CodeMethodInvokeExpression codeIndexer = new CodeMethodInvokeExpression(target, "GetAt", new CodePrimitiveExpression(cell.Column.Index));
context = new ExpressionContext(codeIndexer, typeof(RowCollection), context2.PresetValue, cell);
manager.Context.Push(context);
}
try
{
CodeDomSerializer rowSerialzier = (CodeDomSerializer)manager.GetSerializer(cell.GetType(), typeof(CodeDomSerializer));
//codeObject = rowSerialzier.Serialize(manager, row);
codeObject = rowSerialzier.SerializeAbsolute(manager, cell);
}
finally
{
if (context != null)
{
manager.Context.Pop();
}
}
return codeObject;
}
示例3: Analyze
internal override void Analyze(RuleAnalysis analysis, MemberInfo member, CodeExpression targetExpression, RulePathQualifier targetQualifier, CodeExpressionCollection argumentExpressions, ParameterInfo[] parameters, List<CodeExpression> attributedExpressions)
{
if (!analysis.ForWrites)
{
base.AnalyzeReadWrite(analysis, targetExpression, targetQualifier, argumentExpressions, parameters, attributedExpressions);
}
}
示例4: CodeMethodReferenceExpression
public CodeMethodReferenceExpression(CodeExpression targetObject, string methodName, params CodeTypeReference[] typeParameters) {
TargetObject = targetObject;
MethodName = methodName;
if( typeParameters != null && typeParameters.Length > 0) {
TypeArguments.AddRange(typeParameters);
}
}
示例5: MakeEqual
/// <summary>
/// Generates a test to determine if the given expressions are equal.
/// </summary>
/// <param name="clrType">The Type of the values being compared.</param>
/// <param name="left">The left side of the test.</param>
/// <param name="right">The right side of the test.</param>
/// <param name="isCSharp">Indicates whether or not the output should be C# specific.</param>
/// <returns>A new <see cref="CodeExpression"/>.</returns>
public static CodeExpression MakeEqual(Type clrType, CodeExpression left, CodeExpression right, bool isCSharp)
{
if (isCSharp)
{
return new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityEquality, right);
}
else
{
CodeExpression eq;
if (clrType != null && clrType.IsGenericType && clrType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
eq = new CodeMethodInvokeExpression(left, "Equals", right);
}
else if (clrType != null && clrType.IsValueType)
{
eq = new CodeBinaryOperatorExpression(
left,
CodeBinaryOperatorType.ValueEquality,
right);
}
else if (clrType == typeof(string))
{
eq = new CodeMethodInvokeExpression(null, "String.Equals", left, right);
}
else
{
eq = new CodeMethodInvokeExpression(null, typeof(object).Name + ".Equals", left, right);
}
return eq;
}
}
示例6: GeneratePropertySet
protected override void GeneratePropertySet (GeneratorContext ctx, CodeExpression var, PropertyDescriptor prop)
{
if (prop.Name == "Alpha" && Alpha == -1)
return;
else
base.GeneratePropertySet (ctx, var, prop);
}
示例7: Decompile
internal override void Decompile(CodeExpression expression, StringBuilder stringBuilder, CodeExpression parentExpression)
{
CodeCastExpression childExpr = (CodeCastExpression) expression;
CodeExpression expression3 = childExpr.Expression;
if (expression3 == null)
{
RuleEvaluationException exception = new RuleEvaluationException(Messages.NullCastExpr);
exception.Data["ErrorObject"] = childExpr;
throw exception;
}
if (childExpr.TargetType == null)
{
RuleEvaluationException exception2 = new RuleEvaluationException(Messages.NullCastType);
exception2.Data["ErrorObject"] = childExpr;
throw exception2;
}
bool flag = RuleDecompiler.MustParenthesize(childExpr, parentExpression);
if (flag)
{
stringBuilder.Append("(");
}
stringBuilder.Append("(");
RuleDecompiler.DecompileType(stringBuilder, childExpr.TargetType);
stringBuilder.Append(")");
RuleExpressionWalker.Decompile(stringBuilder, expression3, childExpr);
if (flag)
{
stringBuilder.Append(")");
}
}
示例8: AnalyzeUsage
internal override void AnalyzeUsage(CodeExpression expression, RuleAnalysis analysis, bool isRead, bool isWritten, RulePathQualifier qualifier)
{
CodeDirectionExpression expression2 = (CodeDirectionExpression) expression;
CodeExpression expression3 = expression2.Expression;
bool flag = false;
bool flag2 = true;
RulePathQualifier qualifier2 = null;
switch (expression2.Direction)
{
case FieldDirection.In:
flag = false;
flag2 = true;
qualifier2 = new RulePathQualifier("*", null);
break;
case FieldDirection.Out:
flag = true;
flag2 = false;
qualifier2 = null;
break;
case FieldDirection.Ref:
flag = true;
flag2 = true;
qualifier2 = analysis.ForWrites ? null : new RulePathQualifier("*", null);
break;
}
RuleExpressionWalker.AnalyzeUsage(analysis, expression3, flag2, flag, qualifier2);
}
示例9: Validate
internal override RuleExpressionInfo Validate(CodeExpression expression, RuleValidation validation, bool isWritten)
{
RuleExpressionInfo info;
bool flag;
CodeDirectionExpression expression2 = (CodeDirectionExpression) expression;
if (isWritten)
{
ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, new object[] { typeof(CodeDirectionExpression).ToString() }), 0x17a);
item.UserData["ErrorObject"] = expression2;
validation.Errors.Add(item);
return null;
}
if (expression2.Expression == null)
{
ValidationError error2 = new ValidationError(Messages.NullDirectionTarget, 0x53d);
error2.UserData["ErrorObject"] = expression2;
validation.Errors.Add(error2);
return null;
}
if (expression2.Expression is CodeTypeReferenceExpression)
{
ValidationError error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.CodeExpressionNotHandled, new object[] { expression2.Expression.GetType().FullName }), 0x548);
error.UserData["ErrorObject"] = expression2.Expression;
validation.AddError(error);
return null;
}
if (expression2.Direction == FieldDirection.Ref)
{
flag = true;
if (RuleExpressionWalker.Validate(validation, expression2.Expression, false) == null)
{
return null;
}
info = RuleExpressionWalker.Validate(validation, expression2.Expression, true);
}
else if (expression2.Direction == FieldDirection.Out)
{
flag = true;
info = RuleExpressionWalker.Validate(validation, expression2.Expression, true);
}
else
{
flag = false;
info = RuleExpressionWalker.Validate(validation, expression2.Expression, false);
}
if (info == null)
{
return null;
}
Type expressionType = info.ExpressionType;
if (expressionType == null)
{
return null;
}
if (((expressionType != typeof(NullLiteral)) && flag) && !expressionType.IsByRef)
{
expressionType = expressionType.MakeByRefType();
}
return new RuleExpressionInfo(expressionType);
}
示例10: CodeMethodInvokeExpression
public CodeMethodInvokeExpression (CodeExpression targetObject,
string methodName,
params CodeExpression [] parameters)
{
this.method = new CodeMethodReferenceExpression( targetObject, methodName );
this.Parameters.AddRange (parameters);
}
示例11: GetCodeExpression
public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
{
if (!entry.Expression.Contains(","))
{
throw new ArgumentException("Must include two numbers separated by a comma.");
}
else
{
// get two numbers
string[] numbers = entry.Expression.Split(',');
if (numbers.Length != 2)
{
throw new ArgumentException("Only include two numbers");
}
else
{
int lowerLimit, upperLimit;
if (Int32.TryParse(numbers[0], out lowerLimit) && Int32.TryParse(numbers[1], out upperLimit))
{
CodeTypeReferenceExpression typeRef = new CodeTypeReferenceExpression(this.GetType());
CodeExpression[] methodParameters = new CodeExpression[2];
methodParameters[0] = new CodePrimitiveExpression(lowerLimit);
methodParameters[1] = new CodePrimitiveExpression(upperLimit);
return new CodeMethodInvokeExpression(typeRef, "GetRandomNumber", methodParameters);
}
else
{
throw new ArgumentException("Use valid Integers");
}
}
}
}
示例12: Constructor1_Deny_Unrestricted
public void Constructor1_Deny_Unrestricted ()
{
CodeExpression expression = new CodeExpression ();
CodeMethodReturnStatement cmrs = new CodeMethodReturnStatement (expression);
Assert.AreSame (expression, cmrs.Expression, "Expression");
cmrs.Expression = new CodeExpression ();
}
示例13: Constructor1
public void Constructor1 ()
{
CodeEventReferenceExpression eventref = new CodeEventReferenceExpression ();
CodeExpression listener = new CodeExpression ();
CodeRemoveEventStatement caes = new CodeRemoveEventStatement (eventref, listener);
Assert.AreSame (eventref, caes.Event, "#1");
Assert.AreEqual (string.Empty, caes.Event.EventName, "#2");
Assert.IsNull (caes.Event.TargetObject, "#3");
Assert.AreSame (listener, caes.Listener, "#4");
caes.Event = null;
Assert.IsNotNull (caes.Event, "#5");
Assert.AreEqual (string.Empty, caes.Event.EventName, "#6");
Assert.IsNull (caes.Event.TargetObject, "#7");
Assert.AreSame (listener, caes.Listener, "#8");
caes.Listener = null;
Assert.IsNull (caes.Listener, "#9");
caes.Event = eventref;
Assert.AreSame (eventref, caes.Event, "#10");
caes.Listener = listener;
Assert.AreSame (listener, caes.Listener, "#11");
caes = new CodeRemoveEventStatement ((CodeEventReferenceExpression) null, (CodeExpression) null);
Assert.IsNotNull (caes.Event, "#12");
Assert.IsNull (caes.Listener, "#13");
Assert.AreEqual (string.Empty, caes.Event.EventName, "#14");
Assert.IsNull (caes.Event.TargetObject, "#15");
}
示例14: EmitExpression
void EmitExpression(CodeExpression expr)
{
if (expr is CodeMethodInvokeExpression)
EmitInvoke((CodeMethodInvokeExpression)expr);
else if (expr is CodeArrayCreateExpression)
EmitArray((CodeArrayCreateExpression)expr);
else if (expr is CodePrimitiveExpression)
EmitPrimitive((CodePrimitiveExpression)expr);
else if (expr is CodeBinaryOperatorExpression)
EmitBinary((CodeBinaryOperatorExpression)expr);
else if (expr is CodeTernaryOperatorExpression)
EmitTernary((CodeTernaryOperatorExpression)expr);
else if (expr is CodeVariableReferenceExpression)
EmitVariableReference((CodeVariableReferenceExpression)expr);
else if (expr is CodeArgumentReferenceExpression)
EmitArgumentReference((CodeArgumentReferenceExpression)expr);
else if (expr is CodeFieldReferenceExpression)
EmitFieldReference((CodeFieldReferenceExpression)expr);
else if (expr is CodeTypeReferenceExpression)
EmitTypeReference((CodeTypeReferenceExpression)expr);
else if (expr is CodeArrayIndexerExpression)
EmitArrayIndexer((CodeArrayIndexerExpression)expr);
else if (expr is CodePropertyReferenceExpression)
EmitPropertyReference((CodePropertyReferenceExpression)expr);
else
throw new ArgumentException("Unrecognised expression: " + expr.GetType());
}
示例15: OptimiseExpression
CodeExpression OptimiseExpression(CodeExpression expr)
{
if (!IsOptimisableExpression(expr))
return expr;
var invoke = (CodeMethodInvokeExpression)expr;
for (int i = 1; i < 3; i++)
invoke.Parameters[i] = OptimiseExpression(invoke.Parameters[i]);
if (invoke.Parameters[1] is CodePrimitiveExpression && invoke.Parameters[2] is CodePrimitiveExpression)
{
object result = null;
try
{
result = Script.Operate((Script.Operator)invoke.Parameters[0].UserData[RawData],
((CodePrimitiveExpression)invoke.Parameters[1]).Value,
((CodePrimitiveExpression)invoke.Parameters[2]).Value);
}
catch (Exception) { }
return new CodePrimitiveExpression(result);
}
return invoke;
}