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(nameof(ComTypeLibDesc.Guid))
                                    ),
                                Expression.Constant(_lib.Guid)
                                )
                            )
                        );

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

            return(null);
        }
Esempio n. 2
0
        public override DynamicMetaObject BindGetMember(GetMemberBinder binder)
        {
            string name = binder.Name;

            if (name == _info.Name)
            {
                name = "TypeLibDesc";
            }
            else if (name != "Guid" &&
                     name != "Name" &&
                     name != "VersionMajor" &&
                     name != "VersionMinor")
            {
                return(binder.FallbackGetMember(this));
            }

            return(new DynamicMetaObject(
                       Expression.Convert(
                           Expression.Property(
                               AstUtils.Convert(Expression, typeof(ComTypeLibInfo)),
                               typeof(ComTypeLibInfo).GetProperty(name)
                               ),
                           typeof(object)
                           ),
                       ComTypeLibInfoRestrictions(this)
                       ));
        }
 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)
                        )
                    )
                ));
 }
        protected override Expression VisitParameter(ParameterExpression node)
        {
            Expression closureItem = GetClosureItem(node, true);

            if (closureItem is null)
            {
                return(node);
            }
            // Convert can go away if we switch to strongly typed StrongBox
            return(AstUtils.Convert(closureItem, node.Type));
        }
Esempio n. 5
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)
                    )
                ));
 }
 public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
 {
     return(new DynamicMetaObject(
                Expression.Call(
                    AstUtils.Convert(Expression, typeof(ComTypeClassDesc)),
                    typeof(ComTypeClassDesc).GetMethod("CreateInstance")
                    ),
                BindingRestrictions.Combine(args).Merge(
                    BindingRestrictions.GetTypeRestriction(Expression, typeof(ComTypeClassDesc))
                    )
                ));
 }
 protected override Expression VisitBinary(BinaryExpression node)
 {
     if (node.NodeType == ExpressionType.Assign &&
         node.Left.NodeType == ExpressionType.Parameter)
     {
         var        variable    = (ParameterExpression)node.Left;
         Expression closureItem = GetClosureItem(variable, true);
         if (closureItem != null)
         {
             // We need to convert to object to store the value in the box.
             return(Expression.Block(
                        new[] { variable },
                        Expression.Assign(variable, Visit(node.Right)),
                        Expression.Assign(closureItem, AstUtils.Convert(variable, typeof(object))),
                        variable
                        ));
         }
     }
     return(base.VisitBinary(node));
 }