protected override JsTypeDefinition OnBuildRequest(Type t)
        {
            JsTypeDefinition typedefinition = new JsTypeDefinition(t.Name);

            //only instance /public method /prop***
            //MethodInfo[] methods = t.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
            var methods = t.GetRuntimeMethods();

            foreach (var met in methods)
            {
                if (!met.IsStatic && met.IsPublic)
                {
                    typedefinition.AddMember(new JsMethodDefinition(met.Name, met));
                }
            }

            //var properties = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
            var properties = t.GetRuntimeProperties();

            //TODO finding GetProperties with BindingFlags
            foreach (var property in properties)
            {
                typedefinition.AddMember(new JsPropertyDefinition(property.Name, property));
            }

            return(typedefinition);
        }
Esempio n. 2
0
        protected override JsTypeDefinition OnBuildRequest(Type t)
        {
            //find member that has JsPropertyAttribute or JsMethodAttribute
            JsTypeDefinition typedefinition = new JsTypeDefinition(t.Name);

            //only instance /public method /prop***
            var methods = t.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            foreach (var met in methods)
            {
                var customAttrs = met.GetCustomAttributes(typeOfJsMethodAttr, false);
                if (customAttrs != null && customAttrs.Length > 0)
                {
                    var attr = customAttrs[0] as JsMethodAttribute;
                    typedefinition.AddMember(new JsMethodDefinition(attr.Name ?? met.Name, met));
                }
            }

            var properties = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            foreach (var property in properties)
            {
                var customAttrs = property.GetCustomAttributes(typeOfJsPropertyAttr, false);
                if (customAttrs != null && customAttrs.Length > 0)
                {
                    var attr = customAttrs[0] as JsPropertyAttribute;
                    typedefinition.AddMember(new JsPropertyDefinition(attr.Name ?? property.Name, property));
                }
            }

            return(typedefinition);
        }
Esempio n. 3
0
        public static void Run(NodeJsExecSessionSetup nodeExecSession)
        {
            //------------
            NodeJsEngine.Run((eng, ctx) =>
            {
                //-------------
                //this LibEspressoClass object is need,
                //so node can talk with us,
                //-------------

                JsTypeDefinition jstypedef          = new JsTypeDefinition(LIB_ESPRESSO_CLASS);
                NodeJsExecSession nodeJsExecSession = new NodeJsExecSession(eng, ctx);
                string mainSrc = nodeExecSession(nodeJsExecSession);

                jstypedef.AddMember(new JsMethodDefinition(LOAD_MAIN_SRC_FILE, args =>
                {
                    args.SetResult(mainSrc);
                }));
                if (!jstypedef.IsRegisterd)
                {
                    ctx.RegisterTypeDefinition(jstypedef);
                }
                //----------
                //then register this as x***
                //this object is just an instance for reference
                ctx.SetVariableFromAny(LIB_ESPRESSO, ctx.CreateWrapper(new object(), jstypedef));
            });
        }
        protected override JsTypeDefinition OnBuildRequest(Type t)
        {
            JsTypeDefinition typedefinition = new JsTypeDefinition(t.Name);

            //only instance /public method /prop***
            var methods = t.GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            foreach (var met in methods)
            {
                typedefinition.AddMember(new JsMethodDefinition(met.Name, met));
            }

            var properties = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            foreach (var property in properties)
            {
                typedefinition.AddMember(new JsPropertyDefinition(property.Name, property));
            }

            return(typedefinition);
        }
        protected override JsTypeDefinition OnBuildRequest(Type t)
        {
            JsTypeDefinition typedefinition = new JsTypeDefinition(t.Name);
            //-------
            //only instance /public method /prop***
            Dictionary <string, JsMethodGroup> methodGroups = new Dictionary <string, JsMethodGroup>();

            foreach (MethodInfo met in GetMehodIter(t, BindingFlags.Instance | BindingFlags.Public))
            {
                var           jsMethodDef = new JsMethodDefinition(met.Name, met);
                JsMethodGroup existingGroup;
                if (!methodGroups.TryGetValue(met.Name, out existingGroup))
                {
                    //create new one
                    existingGroup = new JsMethodGroup(met.Name, jsMethodDef);
                    methodGroups.Add(met.Name, existingGroup);
                }
                else
                {
                    existingGroup.AddMoreMember(jsMethodDef);
                }
            }
            //-----------------
            foreach (JsMethodGroup metGroup in methodGroups.Values)
            {
                JsMethodDefinition selectedMethod = metGroup.GetJsMethod();
                if (selectedMethod != null)
                {
                    typedefinition.AddMember(metGroup.GetJsMethod());
                }
            }
            //-----------------
            foreach (var property in GetPropertyIter(t, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public))
            {
                typedefinition.AddMember(new JsPropertyDefinition(property.Name, property));
            }

            return(typedefinition);
        }