Пример #1
0
    /// <summary>
    ///     Makes the generic method.
    ///     not run in Editor mode, only runtime.
    /// </summary>
    /// <param name="type">The type.</param>
    /// <param name="methodID">The method identifier.</param>
    /// <param name="TCount">The t count.</param>
    /// <returns></returns>
    public static MethodInfo makeGenericMethod(Type type, MethodID methodID, int TCount)
    {
        var methodT = GenericTypeCache.getMethod(type, methodID);

        if (methodT == null)
        {
            return(null);
        }

        var genericTypes = new Type[TCount];

        for (int i = 0; i < TCount; i++)
        {
            string typeName = JSApi.getStringS((int)JSApi.GetType.Arg);
            var    t        = GetTypeByName(typeName, typeof(CSRepresentedObject));
            genericTypes[i] = GetGenericTypeBaseType(t);
            if (t == null)
            {
                return(null);
            }
        }

        var method = methodT.MakeGenericMethod(genericTypes);

        return(method);
    }
Пример #2
0
    static bool DictionaryA2_TryGetValue__TKey__TValue(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID8);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 2)
        {
            object   arg0   = (object)JSMgr.datax.getWhatever((int)JSApi.GetType.Arg);
            int      r_arg1 = JSApi.incArgIndex();
            object   arg1   = null;
            object[] arr_t  = new object[] { arg0, arg1 };
            JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(method.Invoke(vc.csObj, arr_t)));
            arg1 = arr_t[1];
            JSApi.setArgIndex(r_arg1);
            JSMgr.datax.setWhatever((int)JSApi.SetType.ArgRef, arg1);
        }

        return(true);
    }
    static bool HashSetA1_CopyTo__T_Array(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID5);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 1)
        {
            object arg0 = JSDataExchangeMgr.GetJSArg <object[]>(() =>
            {
                int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg);
                int length  = JSApi.getArrayLength(jsObjID);
                var ret     = new object[length];
                for (var i = 0; i < length; i++)
                {
                    JSApi.getElement(jsObjID, i);
                    ret[i] = (object)JSMgr.datax.getWhatever((int)JSApi.GetType.SaveAndRemove);
                }
                return(ret);
            });
            object[] arr_t = new object[] { arg0 };
            method.Invoke(vc.csObj, arr_t);
        }

        return(true);
    }
    static bool HashSetA1_RemoveWhere__PredicateT1_T(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID17);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 1)
        {
            object arg0 = JSDataExchangeMgr.GetJSArg <object>(() => {
                if (JSApi.isFunctionS((int)JSApi.GetType.Arg))
                {
                    var getDelegateFun0 = typeof(JSB_System_Collections_Generic_HashSet_1).GetMethod("HashSetA1_RemoveWhere_GetDelegate_member17_arg0").MakeGenericMethod
                                              (method.GetParameters()[0].ParameterType.GetGenericArguments());
                    return(getDelegateFun0.Invoke(null, new object[] { JSApi.getFunctionS((int)JSApi.GetType.Arg) }));
                }
                else
                {
                    return(JSMgr.datax.getObject((int)JSApi.GetType.Arg));
                }
            });
            object[] arr_t = new object[] { arg0 };
            JSApi.setInt32((int)JSApi.SetType.Rval, (System.Int32)(method.Invoke(vc.csObj, arr_t)));
        }

        return(true);
    }
    static bool TweenerCoreA3_ChangeStartValue__Object__Single(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID2);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 1)
        {
            System.Object arg0  = (System.Object)JSMgr.datax.getWhatever((int)JSApi.GetType.Arg);
            object[]      arr_t = new object[] { arg0 };
            JSMgr.datax.setObject((int)JSApi.SetType.Rval, method.Invoke(vc.csObj, arr_t));
        }
        else if (len == 2)
        {
            System.Object arg0  = (System.Object)JSMgr.datax.getWhatever((int)JSApi.GetType.Arg);
            System.Single arg1  = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
            object[]      arr_t = new object[] { arg0, arg1 };
            JSMgr.datax.setObject((int)JSApi.SetType.Rval, method.Invoke(vc.csObj, arr_t));
        }

        return(true);
    }
    /// <summary>
    /// Makes the generic method.
    /// not run in Editor mode, only runtime.
    /// </summary>
    /// <param name="type">The type.</param>
    /// <param name="methodID">The method identifier.</param>
    /// <param name="TCount">The t count.</param>
    /// <returns></returns>
    public static MethodInfo makeGenericMethod(Type type, MethodID methodID, int TCount)
    {
        MethodInfo methodT = GenericTypeCache.getMethod(type, methodID);

        if (methodT == null)
        {
            return(null);
        }

        Type[] genericTypes = new Type[TCount];
        for (int i = 0; i < TCount; i++)
        {
            string      typeName = JSApi.getStringS((int)JSApi.GetType.Arg);
            System.Type t        = JSDataExchangeMgr.GetTypeByName(typeName, typeof(CSRepresentedObject));
            genericTypes[i] = t;
            if (t == null)
            {
                return(null);
            }
        }

        MethodInfo method = methodT.MakeGenericMethod(genericTypes);

        return(method);
    }
Пример #7
0
 public void RegisterGenericClosure(IGenericType targetType, ILockedTypeCollection typeParameters)
 {
     lock (this.SyncObject)
     {
         if (this.genericCache == null)
         {
             this.genericCache = new GenericTypeCache();
         }
         this.genericCache.RegisterGenericType(targetType, typeParameters);
     }
 }
Пример #8
0
    static void DictionaryA2_Count(JSVCall vc)
    {
        PropertyInfo member = GenericTypeCache.getProperty(vc.csObj.GetType(), propertyID0);

        if (member == null)
        {
            return;
        }

        var result = member.GetValue(vc.csObj, new object[] {});

        JSApi.setInt32((int)JSApi.SetType.Rval, (System.Int32)(result));
    }
Пример #9
0
    static void DictionaryA2_Values(JSVCall vc)
    {
        PropertyInfo member = GenericTypeCache.getProperty(vc.csObj.GetType(), propertyID4);

        if (member == null)
        {
            return;
        }

        var result = member.GetValue(vc.csObj, new object[] {});

        JSMgr.datax.setObject((int)JSApi.SetType.Rval, result);
    }
    static void KeyValuePairA2_Value(JSVCall vc)
    {
        PropertyInfo member = GenericTypeCache.getProperty(vc.csObj.GetType(), propertyID1);

        if (member == null)
        {
            return;
        }

        var result = member.GetValue(vc.csObj, new object[] {});

        JSMgr.datax.setWhatever((int)JSApi.SetType.Rval, result);
    }
    static bool HashSetA1_CreateSetComparer(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(typeof(System.Collections.Generic.HashSet <>), methodID22);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 0)
        {
            object[] arr_t = null;
            JSMgr.datax.setObject((int)JSApi.SetType.Rval, method.Invoke(null, arr_t));
        }

        return(true);
    }
Пример #12
0
    static bool DictionaryA2_GetEnumerator(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID4);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 0)
        {
            object[] arr_t = null;
            JSMgr.datax.setObject((int)JSApi.SetType.Rval, method.Invoke(vc.csObj, arr_t));
        }

        return(true);
    }
    static bool KeyValuePairA2_ToString(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID0);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 0)
        {
            object[] arr_t = null;
            JSApi.setStringS((int)JSApi.SetType.Rval, method.Invoke(vc.csObj, arr_t));
        }

        return(true);
    }
Пример #14
0
    static bool DictionaryA2_Clear(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID1);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 0)
        {
            object[] arr_t = null;
            method.Invoke(vc.csObj, arr_t);
        }

        return(true);
    }
    static bool HashSetA1_TrimExcess(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID20);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 0)
        {
            object[] arr_t = null;
            method.Invoke(vc.csObj, arr_t);
        }

        return(true);
    }
    static bool HashSetA1_SetEquals__IEnumerableT1_T(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID18);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 1)
        {
            object   arg0  = (object)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            object[] arr_t = new object[] { arg0 };
            JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(method.Invoke(vc.csObj, arr_t)));
        }

        return(true);
    }
    static bool HashSetA1_UnionWith__IEnumerableT1_T(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID21);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 1)
        {
            object   arg0  = (object)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            object[] arr_t = new object[] { arg0 };
            method.Invoke(vc.csObj, arr_t);
        }

        return(true);
    }
Пример #18
0
        /// <summary>
        /// Returns a <typeparamref name="TType"/> instance that is the
        /// closed generic form of the current <see cref="IntermediateGenericTypeBase{TTypeIdentifier, TType, TIntermediateType}"/>
        /// using the <paramref name="typeParameters"/> provided.
        /// </summary>
        /// <param name="typeParameters">The <see cref="ILockedTypeCollection"/>
        /// used to fill in the type-parameters.</param>
        /// <returns>A new closed <typeparamref name="TType"/> instance with
        /// the <paramref name="typeParameters"/> provided.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// The current <see cref="IntermediateGenericTypeBase{TTypeIdentifier, TType, TIntermediateType}"/>'s
        /// <seealso cref="IsGenericDefinition"/>
        /// is false.</exception>
        public TType MakeGenericClosure(IControlledTypeCollection typeParameters)
        {
            LockedTypeCollection lockedTypeParameters = typeParameters.ToLockedCollection();
            IGenericType         genericResult;

            lock (this.SyncObject)
                if (this.genericCache != null && genericCache.TryObtainGenericClosure(lockedTypeParameters, out genericResult))
                {
                    return((TType)genericResult);
                }
                else
                {
                    if (this.genericCache == null)
                    {
                        this.genericCache = new GenericTypeCache();
                    }
                    var result = this.OnMakeGenericClosure(lockedTypeParameters);
                    this.genericCache.RegisterGenericType(result, lockedTypeParameters);
                    return(result);
                }
        }
Пример #19
0
    static bool DictionaryA2_Remove__TKey(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID7);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 1)
        {
            object   arg0  = (object)JSMgr.datax.getWhatever((int)JSApi.GetType.Arg);
            object[] arr_t = new object[] { arg0 };
            JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(method.Invoke(vc.csObj, arr_t)));
        }

        return(true);
    }
    /*
     * // Runtime Only
     * // type: class type
     * // methodName: method name
     * // TCount: generic parameter count
     * // vc: JSVCall instance
     * public static MethodInfo MakeGenericConstructor(Type type, int TCount, int paramCount, JSVCall vc)
     * {
     *  // Get generic method by name and param count.
     *  ConstructorInfo conT = JSDataExchangeMgr.GetGenericConstructorInfo(type, TCount, paramCount);
     *  if (conT == null)
     *  {
     *      return null;
     *  }
     *
     *  // get T types
     *  Type[] genericTypes = new Type[TCount];
     *  for (int i = 0; i < TCount; i++)
     *  {
     *      // Get generic types from js.
     *      System.Type t = JSDataExchangeMgr.GetTypeByName(JSMgr.datax.getString(JSDataExchangeMgr.eGetType.GetARGV));
     *      genericTypes[i] = t;
     *      if (t == null)
     *      {
     *          return null;
     *      }
     *  }
     *
     *  // Make generic method.
     *  MethodInfo method = methodT.MakeGenericMethod(genericTypes);
     *  return method;
     * }
     * // Runtime Only
     * // called by MakeGenericConstructor
     * // get generic Constructor by matching TCount,paramCount, if more than 1 match, return null.
     * static ConstructorInfo GetGenericConstructorInfo(Type type, int TCount, int paramCount)
     * {
     *  ConstructorInfo[] constructors = type.GetConstructors();
     *  if (constructors == null || constructors.Length == 0)
     *  {
     *      return null;
     *  }
     *
     *  ConstructorInfo con = null;
     *  for (int i = 0; i < constructors.Length; i++)
     *  {
     *      if (constructors[i].IsGenericMethodDefinition &&
     *          constructors[i].GetGenericArguments().Length == TCount &&
     *          constructors[i].GetParameters().Length == paramCount)
     *      {
     *          if (con == null)
     *              con = constructors[i];
     *          else
     *          {
     *              Debug.LogError("More than 1 Generic Constructor found!!! " + GetTypeFullName(type) + "." + name);
     *              return null;
     *          }
     *      }
     *  }
     *  if (con == null)
     *  {
     *      Debug.LogError("No generic constructor found! " + GetTypeFullName(type));
     *  }
     *  return con;
     * }*/
    public static ConstructorInfo makeGenericConstructor(Type type, ConstructorID constructorID)
    {
        int tCount = type.GetGenericArguments().Length;

        Type[] genericTypes = new Type[tCount];
        for (int i = 0; i < tCount; i++)
        {
            string      typeName = JSApi.getStringS((int)JSApi.GetType.Arg);
            System.Type t        = JSDataExchangeMgr.GetTypeByName(typeName, typeof(CSRepresentedObject));
            genericTypes[i] = t;
            if (t == null)
            {
                return(null);
            }
        }

        var exactType        = type.MakeGenericType(genericTypes);
        var exactConstructor = GenericTypeCache.getConstructor(exactType, constructorID);

        return(exactConstructor);
    }
Пример #21
0
    static bool DictionaryA2_OnDeserialization__Object(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID6);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 1)
        {
            System.Object arg0  = (System.Object)JSMgr.datax.getWhatever((int)JSApi.GetType.Arg);
            object[]      arr_t = new object[] { arg0 };
            method.Invoke(vc.csObj, arr_t);
        }

        return(true);
    }
Пример #22
0
    static bool DictionaryA2_Add__TKey__TValue(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID0);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 2)
        {
            object   arg0  = (object)JSMgr.datax.getWhatever((int)JSApi.GetType.Arg);
            object   arg1  = (object)JSMgr.datax.getWhatever((int)JSApi.GetType.Arg);
            object[] arr_t = new object[] { arg0, arg1 };
            method.Invoke(vc.csObj, arr_t);
        }

        return(true);
    }
Пример #23
0
    static void DictionaryA2_Item_TKey(JSVCall vc)
    {
        PropertyInfo member = GenericTypeCache.getProperty(vc.csObj.GetType(), propertyID1);

        if (member == null)
        {
            return;
        }

        object arg0 = (object)JSMgr.datax.getWhatever((int)JSApi.GetType.Arg);

        if (vc.bGet)
        {
            var result = member.GetValue(vc.csObj, new object[] { arg0 });
            JSMgr.datax.setWhatever((int)JSApi.SetType.Rval, result);
        }
        else
        {
            object arg1 = (object)JSMgr.datax.getWhatever((int)JSApi.GetType.Arg);
            member.SetValue(vc.csObj, arg1, new object[] { arg0 });
        }
    }
Пример #24
0
    static bool DictionaryA2_GetObjectData__SerializationInfo__StreamingContext(JSVCall vc, int argc)
    {
        // Get generic method by name and param count.
        MethodInfo method = GenericTypeCache.getMethod(vc.csObj.GetType(), methodID5);

        if (method == null)
        {
            return(true);
        }

        int len = argc;

        if (len == 2)
        {
            System.Runtime.Serialization.SerializationInfo arg0 = (System.Runtime.Serialization.SerializationInfo)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            System.Runtime.Serialization.StreamingContext  arg1 = (System.Runtime.Serialization.StreamingContext)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            object[] arr_t = new object[] { arg0, arg1 };
            method.Invoke(vc.csObj, arr_t);
        }

        return(true);
    }
Пример #25
0
        /// <summary>
        /// Disposes the <see cref="IntermediateGenericTypeBase{TTypeIdentifier, TType, TIntermediateType}"/>.
        /// </summary>
        public override void Dispose()
        {
            const byte DISP_STATE_NONE      = 0;
            const byte DISP_STATE_DISPOSING = 1;
            const byte DISP_STATE_DISPOSED  = 2;

            lock (this.SyncObject)
            {
                if (this.disposeState != DISP_STATE_NONE)
                {
                    return;
                }
                this.disposeState = DISP_STATE_DISPOSING;
                try
                {
                    if (genericCache != null)
                    {
                        this.genericCache.Dispose();
                        this.genericCache = null;
                    }
                    if (this.genericParameters != null)
                    {
                        this.genericParameters.Dispose();
                        this.genericParameters = null;
                    }
                    if (this.typeParameters != null)
                    {
                        this.typeParameters.Dispose();
                        this.typeParameters = null;
                    }
                }
                finally
                {
                    this.disposeState = DISP_STATE_DISPOSED;
                    base.Dispose();
                }
            }
        }
 public CachedWorker(IWorkerInfo worker)
 {
     Worker         = worker;
     MessageWorkers = new GenericTypeCache <IWorkerInfo>(typeof(IWorkerInfo <>),
                                                         type => (IWorkerInfo)FastActivator.Create(typeof(WorkerInfo <>), new Type[] { type }));
 }
Пример #27
0
 InstanceConnectorCache()
 {
     _connectors = new GenericTypeCache <InstanceConnector>(typeof(InstanceConnector <>));
 }
Пример #28
0
 public void Setup()
 {
     _cache = new GenericTypeCache <IGeneric>(typeof(GenericClass <>));
 }
Пример #29
0
 ConsumerConnectorCache()
 {
     _connectors = new GenericTypeCache <IConsumerConnector>(typeof(ConsumerConnector <>));
 }
Пример #30
0
 public static Type MakeGeneric(this Type type, params Type[] arguments)
 {
     return(GenericTypeCache.MakeGeneric(type, arguments));
 }