本文整理汇总了C#中System.CodeDom.CodeBinaryOperatorExpression类的典型用法代码示例。如果您正苦于以下问题:C# CodeBinaryOperatorExpression类的具体用法?C# CodeBinaryOperatorExpression怎么用?C# CodeBinaryOperatorExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodeBinaryOperatorExpression类属于System.CodeDom命名空间,在下文中一共展示了CodeBinaryOperatorExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateInstanceForType
private static BinaryOperatorType CreateInstanceForType (Type l, CodeBinaryOperatorExpression code, object right, object left)
{
if (l == typeof (Int32))
return new BinaryOperatorTypeInt32 (code, right, left);
if (l == typeof (Int16))
return new BinaryOperatorTypeInt16 (code, right, left);
if (l == typeof (Int64))
return new BinaryOperatorTypeInt64 (code, right, left);
if (l == typeof (sbyte))
return new BinaryOperatorTypeSbyte (code, right, left);
if (l == typeof (float))
return new BinaryOperatorTypeFloat (code, right, left);
if (l == typeof (char))
return new BinaryOperatorTypeChar (code, right, left);
if (l == typeof (byte))
return new BinaryOperatorTypeByte (code, right, left);
throw new InvalidOperationException ("Type not suported as binary operator");
}
示例2: 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]));
}
示例3: GenerateSetMappedPropertyCode
protected CodeStatementCollection GenerateSetMappedPropertyCode(CodeExpression targetObj, CodeExpression value)
{
CodeStatementCollection statements = new CodeStatementCollection();
CodePropertyReferenceExpression property = new CodePropertyReferenceExpression(targetObj, MappedProperty.Name);
if (_mappedProperty.PropertyType.IsArray)
{
statements.Add(new CodeAssignStatement(
new CodeIndexerExpression(property, new CodePrimitiveExpression(_index)), value));
return statements;
}
if (IsCollection(_mappedProperty.PropertyType))
{
CodeBinaryOperatorExpression isNull =
new CodeBinaryOperatorExpression(property, CodeBinaryOperatorType.ValueEquality, new CodeSnippetExpression("null"));
CodeAssignStatement create = new CodeAssignStatement(property, new CodeObjectCreateExpression(_mappedProperty.PropertyType));
statements.Add(new CodeConditionStatement(isNull, create));
statements.Add(new CodeMethodInvokeExpression(property, "Add", value));
return statements;
}
statements.Add(new CodeAssignStatement(property, value));
return statements;
}
示例4: 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;
}
示例5: TypeReferenceExpressionTest
public void TypeReferenceExpressionTest ()
{
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter (sb)) {
CodeThisReferenceExpression thisRef = new CodeThisReferenceExpression();
CodeFieldReferenceExpression parentField = new CodeFieldReferenceExpression();
parentField.TargetObject = thisRef;
parentField.FieldName = "Parent";
CodeBinaryOperatorExpression expression = new CodeBinaryOperatorExpression(
parentField,
CodeBinaryOperatorType.IdentityInequality,
new CodePrimitiveExpression(null));
Assert.AreEqual ("(Not (Me.Parent) Is Nothing)", Generate (expression, sw), "#1");
sw.Close ();
}
sb = new StringBuilder();
using (StringWriter sw = new StringWriter (sb)) {
CodeThisReferenceExpression thisRef = new CodeThisReferenceExpression();
CodeFieldReferenceExpression parentField = new CodeFieldReferenceExpression();
parentField.TargetObject = thisRef;
parentField.FieldName = "Parent";
CodeBinaryOperatorExpression expression = new CodeBinaryOperatorExpression(
new CodePrimitiveExpression(null),
CodeBinaryOperatorType.IdentityInequality,
parentField);
Assert.AreEqual ("(Not (Me.Parent) Is Nothing)", Generate (expression, sw), "#2");
sw.Close ();
}
}
示例6: GenerateBinaryOperatorExpression
protected virtual void GenerateBinaryOperatorExpression(CodeBinaryOperatorExpression e)
{
bool flag = false;
this.Output.Write("(");
this.GenerateExpression(e.Left);
this.Output.Write(" ");
if ((e.Left is CodeBinaryOperatorExpression) || (e.Right is CodeBinaryOperatorExpression))
{
if (!this.inNestedBinary)
{
flag = true;
this.inNestedBinary = true;
this.Indent += 3;
}
this.ContinueOnNewLine("");
}
this.OutputOperator(e.Operator);
this.Output.Write(" ");
this.GenerateExpression(e.Right);
this.Output.Write(")");
if (flag)
{
this.Indent -= 3;
this.inNestedBinary = false;
}
}
示例7: Serialize
public override object Serialize (IDesignerSerializationManager manager, object value)
{
if (manager == null)
throw new ArgumentNullException ("manager");
if (value == null)
throw new ArgumentNullException ("value");
Enum[] enums = null;
TypeConverter converter = TypeDescriptor.GetConverter (value);
if (converter.CanConvertTo (typeof (Enum[])))
enums = (Enum[]) converter.ConvertTo (value, typeof (Enum[]));
else
enums = new Enum[] { (Enum) value };
CodeExpression left = null;
CodeExpression right = null;
foreach (Enum e in enums) {
right = GetEnumExpression (e);
if (left == null) // just the first time
left = right;
else
left = new CodeBinaryOperatorExpression (left, CodeBinaryOperatorType.BitwiseOr, right);
}
return left;
}
示例8: CreateWithApiKey
/// <summary>
/// if (string.IsNullOrEmpty(APIKey) == false)
/// request = request.WithAPIKey(APIKey)
/// </summary>
/// <returns></returns>
internal CodeConditionStatement CreateWithApiKey()
{
// !string.IsNullOrEmpty(Key)
var condition = new CodeBinaryOperatorExpression(
new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(string)), "IsNullOrEmpty",
new CodeVariableReferenceExpression(ApiKeyServiceDecorator.PropertyName)),
CodeBinaryOperatorType.ValueEquality,
new CodePrimitiveExpression(false));
//var condition =
//new CodeSnippetExpression("!string.IsNullOrEmpty(" + ApiKeyServiceDecorator.PropertyName + ")");
// if (...) {
var block = new CodeConditionStatement(condition);
// request = request.WithKey(APIKey)
var getProperty = new CodePropertyReferenceExpression(
new CodeThisReferenceExpression(), ApiKeyServiceDecorator.PropertyName);
var request = new CodeMethodInvokeExpression(
new CodeVariableReferenceExpression("request"), "WithKey", getProperty);
var trueCase = new CodeAssignStatement(new CodeVariableReferenceExpression("request"), request);
// }
block.TrueStatements.Add(trueCase);
return block;
}
示例9: BuildConditionalExpression
protected virtual CodeExpression BuildConditionalExpression(
conditionalContainer container, ItemsChoiceType choiceType)
{
//grab the children
List<CodeExpression> children = new List<CodeExpression>();
for (int i = 0; i < container.Items.Length; i++)
{
if (container.Items[i] is conditionalContainer)
{
children.Add(BuildConditionalExpression((conditionalContainer)container.Items[i],
container.ItemsElementName[i]));
}
else if (container.Items[i] is actionEquals)
{
children.Add(BuildConditionalExpression((actionEquals)container.Items[i]));
}
else if (container.Items[i] is valueEquals)
{
children.Add(BuildConditionalExpression((valueEquals)container.Items[i],
container.ItemsElementName[i]));
}
else
{
throw new GatException("Unrecognized conditional item type: " +
container.Items[i].GetType());
}
}
//get the full expression
CodeExpression expr = null;
if (choiceType == ItemsChoiceType.none)
{
expr = new CodeBinaryOperatorExpression(children[0],
CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(false));
for (int i = 1; i < children.Count; i++)
{
expr = new CodeBinaryOperatorExpression(expr,
CodeBinaryOperatorType.BooleanAnd,
new CodeBinaryOperatorExpression(children[i],
CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(false)));
}
}
else if (choiceType == ItemsChoiceType.all ||
choiceType == ItemsChoiceType.any)
{
CodeBinaryOperatorType opType = choiceType == ItemsChoiceType.all ?
CodeBinaryOperatorType.BooleanAnd : CodeBinaryOperatorType.BooleanOr;
expr = children[0];
for (int i = 1; i < children.Count; i++)
{
expr = new CodeBinaryOperatorExpression(expr,
CodeBinaryOperatorType.BooleanOr, children[i]);
}
}
else
{
throw new GatException("Unrecognized choice type: " + choiceType);
}
return expr;
}
示例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: BasePlusN
static CodeExpression BasePlusN (int n)
{
CodeBinaryOperatorExpression idexpr = new CodeBinaryOperatorExpression ();
idexpr.Left = new CodeVariableReferenceExpression ("base_total");
idexpr.Operator = CodeBinaryOperatorType.Add;
idexpr.Right = new CodePrimitiveExpression (n);
return idexpr;
}
示例12: BeginLoop
public void BeginLoop()
{
var cond = new CodeBinaryOperatorExpression(_expr_memory_pointer, CodeBinaryOperatorType.IdentityInequality, _expr_value_zero);
var loop = new CodeIterationStatement(new CodeSnippetStatement(), cond, new CodeSnippetStatement());
_nest.Peek().Add(loop);
_nest.Push(loop.Statements);
IncrementInstructionPointer();
}
示例13: Clone
public static CodeBinaryOperatorExpression Clone(this CodeBinaryOperatorExpression expression)
{
if (expression == null) return null;
CodeBinaryOperatorExpression e = new CodeBinaryOperatorExpression();
e.Left = expression.Left.Clone();
e.Operator = expression.Operator;
e.Right = expression.Right.Clone();
e.UserData.AddRange(expression.UserData);
return e;
}
示例14: Constructor0_Deny_Unrestricted
public void Constructor0_Deny_Unrestricted ()
{
CodeBinaryOperatorExpression cboe = new CodeBinaryOperatorExpression ();
Assert.IsNull (cboe.Left, "Left");
cboe.Left = new CodeExpression ();
Assert.IsNull (cboe.Right, "Right");
cboe.Right = new CodeExpression ();
Assert.AreEqual (CodeBinaryOperatorType.Add, cboe.Operator, "Operator");
cboe.Operator = CodeBinaryOperatorType.Divide;
}
示例15: ThrowWhenArgumentMatchesExpression
public static void ThrowWhenArgumentMatchesExpression(this CodeStatementCollection self, string argument, CodeBinaryOperatorExpression expression)
{
self.Add (
new CodeConditionStatement (
expression,
new CodeThrowExceptionStatement (
new CodeObjectCreateExpression (
new CodeTypeReference ("System.ArgumentNullException"),
new CodePrimitiveExpression (argument)))));
}