Beispiel #1
0
        public JSClassWrapper(ExecutionContext GLOBAL, Type t)
        {
            object thisOb = null;

            mThisType = t;
            BindingFlags flags       = BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public;
            string       applyMethod = null;

            object []         attributes = t.GetCustomAttributes(false);
            List <MethodInfo> applying   = new List <MethodInfo>();

            foreach (object attribute in attributes)
            {
                if (attribute is ApplyAttribute)
                {
                    applyMethod = ((ApplyAttribute)attribute).MethodName;
                }
            }

            if (t == typeof(Type))
            {
                thisOb = t;
                flags |= BindingFlags.Instance;
            }
            Dictionary <string, List <MethodInfo> > namedMethods = new Dictionary <string, List <MethodInfo> >();

            foreach (FieldInfo fieldInfo in mThisType.GetFields(flags))
            {
                this.SetItem(GLOBAL, fieldInfo.Name, new JSNativeField(thisOb, fieldInfo));
            }
            foreach (PropertyInfo propInfo in mThisType.GetProperties(flags))
            {
                this.SetItem(GLOBAL, propInfo.Name, new JSNativeProperty(thisOb, propInfo));
            }
            foreach (MethodInfo methodInfo in mThisType.GetMethods(flags))
            {
                List <MethodInfo> ml;
                if (applyMethod != null && methodInfo.Name == applyMethod && methodInfo.IsStatic)
                {
                    applying.Add(methodInfo);
                }
                if (!namedMethods.TryGetValue(methodInfo.Name, out ml))
                {
                    ml = new List <MethodInfo>(new MethodInfo[] { methodInfo });
                    namedMethods[methodInfo.Name] = ml;
                }
                else
                {
                    ml.Add(methodInfo);
                }
            }

            foreach (EventInfo eventInfo in mThisType.GetEvents(flags))
            {
                this.SetItem(GLOBAL, eventInfo.Name, new JSNativeEvent(GLOBAL, thisOb, eventInfo));
            }
            foreach (KeyValuePair <string, List <MethodInfo> > method in namedMethods)
            {
                this.SetItem(GLOBAL, method.Key, new JSNativeMethod(method.Value.ToArray()));
            }
            if (applying.Count > 0)
            {
                mApplyMethod = new JSNativeMethod(applying.ToArray());
            }
        }
Beispiel #2
0
 public JSMethodCall(JSNativeMethod method)
 {
     mMethodProp = method;
 }