public EvaluateObject ( |
||
context | ||
return |
TargetObject DoCast(ScriptingContext context, Expression expr, TargetType target_type) { TargetObject source = expr.EvaluateObject (context); if (source == null) return null; if (target_type is TargetObjectType) { if (((source is TargetClassObject) && !source.Type.IsByRef) || (source is TargetFundamentalObject)) return target_type.Language.CreateBoxedObject (context.CurrentThread, source); if (source is TargetObjectObject) return source; throw new ScriptingException ( "Cannot box object `{0}': not a value-type", expr.Name); } if (target_type is TargetPointerType) { TargetAddress address; PointerExpression pexpr = expr as PointerExpression; if (pexpr != null) address = pexpr.EvaluateAddress (context); else { TargetPointerType ptype = expr.EvaluateType (context) as TargetPointerType; if ((ptype == null) || ptype.IsTypesafe) return null; pexpr = new AddressOfExpression (expr); pexpr.Resolve (context); address = pexpr.EvaluateAddress (context); } return ((TargetPointerType) target_type).GetObject (address); } if (target_type is TargetFundamentalType) { TargetFundamentalObject fobj = expr.EvaluateObject (context) as TargetFundamentalObject; if (fobj == null) return null; TargetFundamentalType ftype = target_type as TargetFundamentalType; return Convert.ExplicitFundamentalConversion (context, fobj, ftype); } TargetClassType ctype = Convert.ToClassType (target_type); TargetClassObject source_cobj = Convert.ToClassObject (context.CurrentThread, source); if (source_cobj == null) throw new ScriptingException ( "Variable {0} is not a class type.", expr.Name); return TryCast (context, source_cobj, ctype); }
public static MethodGroupExpression ResolveDelegate(ScriptingContext context, Expression expr) { TargetClassType ctype = Convert.ToClassType (expr.EvaluateType (context)); if (ctype == null) return null; TargetClassObject cobj; try { cobj = Convert.ToClassObject ( context.CurrentThread, expr.EvaluateObject (context)); } catch { cobj = null; } TargetClassType delegate_type = ctype.Language.DelegateType; if (!CastExpression.TryCast (context, ctype, delegate_type)) return null; TargetFunctionType invoke = null; foreach (TargetMethodInfo method in ctype.Methods) { if (method.Name == "Invoke") { invoke = method.Type; break; } } if (invoke == null) return null; TargetFunctionType[] methods = new TargetFunctionType[] { invoke }; MethodGroupExpression mg = new MethodGroupExpression ( ctype, cobj, "Invoke", methods, true, false); return mg; }