Пример #1
0
        /// <summary>
        /// serialization this typedefinition to binary format and
        /// send to native side
        /// </summary>
        /// <param name="writer"></param>
        internal void WriteDefinitionToStream(BinaryWriter writer)
        {
            //----------------------
            //this is our custom protocol/convention with the MiniJsBridge
            //we may change this in the future
            //eg. use json serialization/deserialization
            //----------------------

            //1. kind/flags
            writer.Write((short)this.MemberId);
            //2. member id
            writer.Write((short)0);
            //3. typename
            WriteUtf16String(this.MemberName, writer);

            //4. num of field
            int j = fields.Count;

            writer.Write((short)j);
            for (int i = 0; i < j; ++i)
            {
                JsFieldDefinition fielddef = fields[i];
                //field flags
                writer.Write((short)0);

                //*** field id -- unique field id within one type
                writer.Write((short)fielddef.MemberId);

                //field name
                WriteUtf16String(fielddef.MemberName, writer);
            }
            //------------------
            j = methods.Count;
            writer.Write((short)j);
            for (int i = 0; i < j; ++i)
            {
                JsMethodDefinition methoddef = methods[i];
                //method flags
                writer.Write((short)0);
                //id
                writer.Write((short)methoddef.MemberId);
                //method name
                WriteUtf16String(methoddef.MemberName, writer);
            }

            //property
            j = props.Count;
            writer.Write((short)j);
            for (int i = 0; i < j; ++i)
            {
                JsPropertyDefinition property = this.props[i];
                //flags
                writer.Write((short)0);
                //id
                writer.Write((short)property.MemberId);
                //name
                WriteUtf16String(property.MemberName, writer);
            }
        }
Пример #2
0
        void EngineListener_MethodCall(int mIndex, int methodKind, IntPtr metArgs)
        {
            switch (methodKind)
            {
            case 1:
            {
                //property get
                if (mIndex == 0)
                {
                    return;
                }
                //------------------------------------------
                JsMethodDefinition getterMethod = registerProperties[mIndex].GetterMethod;

                if (getterMethod != null)
                {
                    getterMethod.InvokeMethod(new ManagedMethodArgs(this, metArgs));
                }
            }
            break;

            case 2:
            {
                //property set
                if (mIndex == 0)
                {
                    return;
                }
                //------------------------------------------
                JsMethodDefinition setterMethod = registerProperties[mIndex].SetterMethod;
                if (setterMethod != null)
                {
                    setterMethod.InvokeMethod(new ManagedMethodArgs(this, metArgs));
                }
            }
            break;

            default:
            {
                if (mIndex == 0)
                {
                    return;
                }
                JsMethodDefinition foundMet = registerMethods[mIndex];
                if (foundMet != null)
                {
                    foundMet.InvokeMethod(new ManagedMethodArgs(this, metArgs));
                }
            }
            break;
            }
        }
Пример #3
0
        internal void CollectionTypeMembers(JsTypeDefinition jsTypeDefinition)
        {
            List <JsMethodDefinition> methods = jsTypeDefinition.GetMethods();
            int j = methods.Count;

            for (int i = 0; i < j; ++i)
            {
                JsMethodDefinition met = methods[i];
                met.SetMemberId(registerMethods.Count);
                registerMethods.Add(met);
            }

            List <JsPropertyDefinition> properties = jsTypeDefinition.GetProperties();

            j = properties.Count;
            for (int i = 0; i < j; ++i)
            {
                var p = properties[i];
                p.SetMemberId(registerProperties.Count);
                registerProperties.Add(p);
            }
        }
Пример #4
0
 public void AddMember(JsMethodDefinition methodDef)
 {
     methodDef.SetOwner(this);
     methods.Add(methodDef);
 }