本文整理汇总了C#中Mono.CodeGeneration.CodeExpression.GetResultType方法的典型用法代码示例。如果您正苦于以下问题:C# CodeExpression.GetResultType方法的具体用法?C# CodeExpression.GetResultType怎么用?C# CodeExpression.GetResultType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CodeGeneration.CodeExpression
的用法示例。
在下文中一共展示了CodeExpression.GetResultType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CodeSubstractOne
public CodeSubstractOne (CodeExpression exp)
{
this.exp = exp;
if (!exp.IsNumber) {
decMet = exp.GetResultType ().GetMethod ("op_Decrement");
if (decMet == null)
throw new InvalidOperationException ("Operator '--' cannot be applied to operand of type '" + exp.GetResultType().FullName + "'");
}
}
示例2: CodeMethodCall
public CodeMethodCall (CodeExpression target, string name, params CodeExpression[] parameters)
{
this.target = target;
this.parameters = parameters;
Type[] types = GetParameterTypes (parameters);
method = target.GetResultType().GetMethod (name, types);
if (method == null) {
throw new InvalidOperationException ("Method " + GetSignature(target.GetResultType(), name, parameters) + " not found");
}
}
示例3: CodeAnd
public CodeAnd (CodeExpression exp1, CodeExpression exp2)
{
this.exp1 = exp1;
this.exp2 = exp2;
if (exp1.GetResultType () != typeof(bool) || exp1.GetResultType () != typeof(bool)) {
if (t1 != t2)
throw new InvalidOperationException ("Can't compare values of different primitive types");
}
}
示例4: GenerateSet
public override void GenerateSet(ILGenerator gen, CodeExpression value)
{
if (type.IsByRef) {
gen.Emit (OpCodes.Ldarg, argNum);
value.Generate (gen);
CodeGenerationHelper.GenerateSafeConversion (gen, type.GetElementType (), value.GetResultType ());
CodeGenerationHelper.SaveToPtr (gen, type.GetElementType ());
}
else {
value.Generate (gen);
CodeGenerationHelper.GenerateSafeConversion (gen, type, value.GetResultType ());
gen.Emit (OpCodes.Starg, argNum);
}
}
示例5: GenerateSet
public override void GenerateSet (ILGenerator gen, CodeExpression value)
{
if (field.IsStatic) {
value.Generate (gen);
CodeGenerationHelper.GenerateSafeConversion (gen, field.FieldType, value.GetResultType ());
gen.Emit (OpCodes.Stsfld, field);
}
else {
target.Generate (gen);
value.Generate (gen);
CodeGenerationHelper.GenerateSafeConversion (gen, field.FieldType, value.GetResultType ());
gen.Emit (OpCodes.Stfld, field);
}
}
示例6: CodeNewArray
public CodeNewArray (Type type, CodeExpression size)
{
this.elemType = type;
this.size = size;
if (size.GetResultType () != typeof(int))
throw new InvalidOperationException ("Array size must be an Int32");
}
示例7: CodeFor
public CodeFor (CodeExpression initExp, CodeExpression conditionExp, CodeExpression nextExp)
{
this.initExp = initExp;
this.conditionExp = conditionExp;
this.nextExp = nextExp;
if (conditionExp.GetResultType () != typeof(bool))
throw new InvalidOperationException ("Condition expression is not boolean");
}
示例8: CodeWhen
public CodeWhen (CodeExpression condition, CodeExpression trueResult, CodeExpression falseResult)
{
this.condition = condition;
if (condition.GetResultType () != typeof(bool))
throw new InvalidOperationException ("Condition expression is not boolean");
if (trueResult.GetResultType() != falseResult.GetResultType())
throw new InvalidOperationException ("The types of the true and false expressions must be the same");
trueBlock = trueResult;
falseBlock = falseResult;
}
示例9: CodeForeach
public CodeForeach (CodeExpression array, Type itemType)
{
this.array = array;
this.itemType = itemType;
Type t = array.GetResultType ();
if (!t.IsArray && t.GetMethod ("GetEnumerator", Type.EmptyTypes) == null)
throw new InvalidOperationException ("foreach statement cannot operate on variables of type `" + t + "' because that class does not provide a GetEnumerator method or it is inaccessible");
itemDec = new CodeVariableDeclaration (itemType, "item");
}
示例10: CodeBinaryOperation
public CodeBinaryOperation(CodeExpression exp1, CodeExpression exp2, string symbol)
{
this.symbol = symbol;
this.exp1 = exp1;
this.exp2 = exp2;
t1 = exp1.GetResultType ();
t2 = exp2.GetResultType ();
if (!t1.IsPrimitive || !t2.IsPrimitive || (t1 != t2)) {
throw new InvalidOperationException ("Operator " + GetType().Name + " cannot be applied to operands of type '" + t1.Name + " and " + t2.Name);
}
}
示例11: CodeNotEquals
public CodeNotEquals (CodeExpression exp1, CodeExpression exp2)
{
this.exp1 = exp1;
this.exp2 = exp2;
t1 = exp1.GetResultType ();
t2 = exp2.GetResultType ();
if (t1.IsValueType && t2.IsValueType) {
if (t1 != t2)
throw new InvalidOperationException ("Can't compare values of different primitive types");
}
}
示例12: CodeAdd
public CodeAdd (CodeExpression exp1, CodeExpression exp2)
{
this.symbol = "+";
this.exp1 = exp1;
this.exp2 = exp2;
t1 = exp1.GetResultType ();
t2 = exp2.GetResultType ();
if ((!t1.IsPrimitive || !t2.IsPrimitive || (t1 != t2)) && (t1 != typeof(string) || t2 != typeof(string))) {
throw new InvalidOperationException ("Operator " + GetType().Name + " cannot be applied to operands of type '" + t1.Name + " and " + t2.Name);
}
}
示例13: GenerateMethodCall
static void GenerateMethodCall (ILGenerator gen, CodeExpression target, MethodBase method, Type[] parameterTypes, params CodeExpression[] parameters)
{
OpCode callOp;
if (parameterTypes.Length != parameters.Length)
throw GetMethodException (method, "Invalid number of parameters, expected " + parameterTypes.Length + ", found " + parameters.Length + ".");
if (!object.ReferenceEquals (target, null))
{
target.Generate (gen);
Type targetType = target.GetResultType();
if (targetType.IsValueType) {
LocalBuilder lb = gen.DeclareLocal (targetType);
gen.Emit (OpCodes.Stloc, lb);
gen.Emit (OpCodes.Ldloca, lb);
callOp = OpCodes.Call;
}
else
callOp = OpCodes.Callvirt;
}
else
callOp = OpCodes.Call;
for (int n=0; n<parameterTypes.Length; n++) {
try {
CodeExpression par = parameters[n];
par.Generate (gen);
GenerateSafeConversion (gen, parameterTypes[n], par.GetResultType());
}
catch (InvalidOperationException ex) {
throw GetMethodException (method, "Parameter " + n + ". " + ex.Message);
}
}
if (method is MethodInfo)
gen.Emit (callOp, (MethodInfo)method);
else if (method is ConstructorInfo)
gen.Emit (callOp, (ConstructorInfo)method);
}
示例14: GenerateSet
public override void GenerateSet(ILGenerator gen, CodeExpression value)
{
value.Generate (gen);
CodeGenerationHelper.GenerateSafeConversion (gen, type, value.GetResultType ());
gen.Emit (OpCodes.Stloc, localBuilder);
}
示例15: CodeIf
public CodeIf (CodeExpression condition)
{
this.condition = condition;
if (condition.GetResultType () != typeof(bool))
throw new InvalidOperationException ("Condition expression is not boolean");
}