コード例 #1
0
        private DynamicMetaObject TryBindGetMember(string name)
        {
            if (_lib.HasMember(name))
            {
                BindingRestrictions restrictions =
                    BindingRestrictions.GetTypeRestriction(
                        Expression, typeof(ComTypeLibDesc)
                        ).Merge(
                        BindingRestrictions.GetExpressionRestriction(
                            Expression.Equal(
                                Expression.Property(
                                    AstUtils.Convert(
                                        Expression, typeof(ComTypeLibDesc)
                                        ),
                                    typeof(ComTypeLibDesc).GetProperty("Guid")
                                    ),
                                AstUtils.Constant(_lib.Guid)
                                )
                            )
                        );

                return(new DynamicMetaObject(
                           AstUtils.Constant(
                               ((ComTypeLibDesc)Value).GetTypeLibObjectDesc(name)
                               ),
                           restrictions
                           ));
            }

            return(null);
        }
コード例 #2
0
 private BindingRestrictions EnumRestrictions()
 {
     return(BindingRestrictions.GetTypeRestriction(
                Expression, typeof(ComTypeEnumDesc)
                ).Merge(
                // ((ComTypeEnumDesc)<arg>).TypeLib.Guid == <guid>
                BindingRestrictions.GetExpressionRestriction(
                    Expression.Equal(
                        Expression.Property(
                            Expression.Property(
                                AstUtils.Convert(Expression, typeof(ComTypeEnumDesc)),
                                typeof(ComTypeDesc).GetProperty("TypeLib")),
                            typeof(ComTypeLibDesc).GetProperty("Guid")),
                        AstUtils.Constant(_desc.TypeLib.Guid)
                        )
                    )
                ).Merge(
                BindingRestrictions.GetExpressionRestriction(
                    Expression.Equal(
                        Expression.Property(
                            AstUtils.Convert(Expression, typeof(ComTypeEnumDesc)),
                            typeof(ComTypeEnumDesc).GetProperty("TypeName")
                            ),
                        AstUtils.Constant(_desc.TypeName)
                        )
                    )
                ));
 }
コード例 #3
0
 public DynamicMetaObject GetMetaObject(Expression parameter, int index)
 {
     return(DynamicMetaObject.Create(
                GetArgument(index),
                Expression.Call(
                    s_getArgMethod,
                    AstUtils.Convert(parameter, typeof(ArgumentArray)),
                    AstUtils.Constant(index)
                    )
                ));
 }
コード例 #4
0
        protected override Expression VisitRuntimeVariables(RuntimeVariablesExpression node)
        {
            int count   = node.Variables.Count;
            var boxes   = new List <Expression>();
            var vars    = new List <ParameterExpression>();
            var indexes = new int[count];

            for (int i = 0; i < count; i++)
            {
                Expression box = GetClosureItem(node.Variables[i], false);
                if (box is null)
                {
                    indexes[i] = vars.Count;
                    vars.Add(node.Variables[i]);
                }
                else
                {
                    indexes[i] = -1 - boxes.Count;
                    boxes.Add(box);
                }
            }

            // No variables were rewritten. Just return the original node.
            if (boxes.Count == 0)
            {
                return(node);
            }

            var boxesArray = Expression.NewArrayInit(typeof(IStrongBox), boxes);

            // All of them were rewritten. Just return the array, wrapped in a
            // read-only collection.
            if (vars.Count == 0)
            {
                return(Expression.Invoke(
                           Expression.Constant((Func <IStrongBox[], IRuntimeVariables>)RuntimeVariables.Create),
                           boxesArray
                           ));
            }

            // Otherwise, we need to return an object that merges them
            Func <IRuntimeVariables, IRuntimeVariables, int[], IRuntimeVariables> helper = MergedRuntimeVariables.Create;

            return(Expression.Invoke(AstUtils.Constant(helper), Expression.RuntimeVariables(vars), boxesArray, AstUtils.Constant(indexes)));
        }
コード例 #5
0
        //TODO enable sharing of these custom delegates
        private Delegate CreateCustomDelegate(Type delegateType)
        {
            //PerfTrack.NoteEvent(PerfTrack.Categories.Compiler, "Synchronously compiling a custom delegate");

            var method             = delegateType.GetMethod("Invoke");
            var paramInfos         = method.GetParameters();
            var parameters         = new ParameterExpression[paramInfos.Length];
            var parametersAsObject = new Expression[paramInfos.Length];

            for (int i = 0; i < paramInfos.Length; i++)
            {
                ParameterExpression parameter = Expression.Parameter(paramInfos[i].ParameterType, paramInfos[i].Name);
                parameters[i]         = parameter;
                parametersAsObject[i] = Expression.Convert(parameter, typeof(object));
            }

            var data      = Expression.NewArrayInit(typeof(object), parametersAsObject);
            var self      = AstUtils.Constant(this);
            var runMethod = typeof(LightLambda).GetMethod("Run");
            var body      = Expression.Convert(Expression.Call(self, runMethod, data), method.ReturnType);
            var lambda    = Expression.Lambda(delegateType, body, parameters);

            return(lambda.Compile());
        }