public override MSAst TransformCore(ScriptGenerator generator) { var arguments = Arguments.Transform(generator); var propertyExpression = Target as PropertyExpression; if (propertyExpression != null) { MSAst instance = null; if (propertyExpression.InstanceExpression != null) { instance = propertyExpression.InstanceExpression.TransformCore(generator); } // ReSharper disable AssignNullToNotNullAttribute return(MSAst.MakeIndex( instance, propertyExpression.PropertyInfo, arguments)); // ReSharper restore AssignNullToNotNullAttribute } return(MSAst.ArrayIndex( Target.Transform(generator), arguments)); }
protected override LExpression GetExpressionTreeIfPossible(LExpression contextExpression, LExpression evalContext) { var node = getFirstChild(); var arguments = new List <LExpression>(); var argumentsTypes = new List <Type>(); while (node != null) { //if (node.getFirstChild() is LambdaExpressionNode) //{ // argList.Add((BaseNode)node.getFirstChild()); //} //else if (node is NamedArgumentNode) //{ // namedArgs.Add(node.getText(), node); //} //else var arg = GetExpressionTreeIfPossible((BaseNode)node, contextExpression, evalContext); if (arg == null) { return(null); } arguments.Add(arg); argumentsTypes.Add(arg.Type); node = node.getNextSibling(); } // TODO: mo¿e pobranie arraya? tylko trzeba przetestowaæ, czy nie stracimy typu!.. .bo jak przez object, to syf! if (contextExpression.Type.IsArray) { return(LExpression.ArrayIndex( contextExpression, arguments)); } var indexerPropertyName = GetIndexerPropertyName(contextExpression.Type); var methodName = "get_" + indexerPropertyName; var methodInfo = contextExpression.Type.GetMethod( methodName, BINDING_FLAGS | BindingFlags.FlattenHierarchy, null, argumentsTypes.ToArray(), null); if (methodInfo == null) { return(null); } return(LExpression.Call(contextExpression, methodInfo, arguments)); }
public static System.Linq.Expressions.Expression <Func <object[], object> > CreateComplexExpression() { var stateParamExpr = SysExpr.Parameter(typeof(object[])); var funcExpr = SysExpr.Lambda <Func <object[], object> >( SysExpr.MemberInit( SysExpr.New(_ctorOfA, SysExpr.New(_ctorOfB), SysExpr.Convert(SysExpr.ArrayIndex(stateParamExpr, SysExpr.Constant(11)), typeof(string)), SysExpr.NewArrayInit(typeof(ID), SysExpr.New(_ctorOfD1), SysExpr.New(_ctorOfD2))), SysExpr.Bind(_propAProp, SysExpr.New(_ctorOfP, SysExpr.New(_ctorOfB))), SysExpr.Bind(_fieldABop, SysExpr.New(_ctorOfB))), stateParamExpr); return(funcExpr); }