internal static DynamicMetaObject/*!*/ ConvertComArgument(DynamicMetaObject/*!*/ arg) { Expression expr = arg.Expression; BindingRestrictions restrictions; if (arg.Value != null) { Type type = arg.Value.GetType(); if (type == typeof(BigInteger)) { expr = Ast.Convert(AstUtils.Convert(arg.Expression, typeof(BigInteger)), typeof(double)); } else if (type == typeof(MutableString)) { // TODO: encoding? expr = Ast.Convert(AstUtils.Convert(arg.Expression, typeof(MutableString)), typeof(string)); } else if (type == typeof(RubySymbol)) { // TODO: encoding? expr = Ast.Convert(AstUtils.Convert(arg.Expression, typeof(RubySymbol)), typeof(string)); } restrictions = BindingRestrictions.GetTypeRestriction(arg.Expression, type); } else { restrictions = BindingRestrictions.GetExpressionRestriction(Ast.Equal(arg.Expression, AstUtils.Constant(null))); } return arg.Clone(expr, restrictions); }
/// <summary> if a member-injector is defined-on or registered-for this type call it </summary> private bool MakeOperatorSetMemberBody(SetOrDeleteMemberInfo memInfo, DynamicMetaObject self, DynamicMetaObject target, Type type, string name) { if (self != null) { MethodInfo setMem = GetMethod(type, name); if (setMem != null) { ParameterExpression tmp = Ast.Variable(target.Expression.Type, "setValue"); memInfo.Body.AddVariable(tmp); var callMo = MakeCallExpression( memInfo.ResolutionFactory, setMem, self.Clone(AstUtils.Convert(self.Expression, type)), new DynamicMetaObject(AstUtils.Constant(memInfo.Name), BindingRestrictions.Empty, memInfo.Name), target.Clone(tmp) ); var call = Ast.Block(Ast.Assign(tmp, target.Expression), callMo.Expression); if (setMem.ReturnType == typeof(bool)) { memInfo.Body.AddCondition( call, tmp ); } else { memInfo.Body.FinishCondition(Ast.Block(call, AstUtils.Convert(tmp, typeof(object)))); } return setMem.ReturnType != typeof(bool); } } return false; }
public override DynamicMetaObject/*!*/ FallbackConvert(DynamicMetaObject/*!*/ target, DynamicMetaObject errorSuggestion) { #if !SILVERLIGHT DynamicMetaObject result; if (Microsoft.Scripting.ComInterop.ComBinder.TryConvert(this, target, out result)) { return result; } #endif return target.Clone(Ast.NewArrayInit(typeof(object), target.Expression)); }