Type GetTypeFromJs(IntPtr isolate, IntPtr info, IntPtr self, int paramLen) { Type type = null; var value = PuertsDLL.GetArgumentValue(info, 0); if (PuertsDLL.GetJsValueType(isolate, value, false) == JsValueType.String) { string classFullName = PuertsDLL.GetStringFromValue(isolate, value, false); var maybeType = TypeRegister.GetType(classFullName); if (paramLen == 1) { type = maybeType; } else if (maybeType != null && maybeType.IsGenericTypeDefinition && maybeType.GetGenericArguments().Length == (paramLen - 1)) //泛型 { var genericArguments = new Type[paramLen - 1]; for (int i = 1; i < paramLen; i++) { value = PuertsDLL.GetArgumentValue(info, i); if (PuertsDLL.GetJsValueType(isolate, value, false) != JsValueType.Function) { return(null); } var argTypeId = PuertsDLL.GetTypeIdFromValue(isolate, value, false); if (argTypeId == -1) { return(null); } genericArguments[i - 1] = TypeRegister.GetType(argTypeId); } type = maybeType.MakeGenericType(genericArguments); } } else if (PuertsDLL.GetJsValueType(isolate, value, false) == JsValueType.NativeObject) { type = StaticTranslate <Type> .Get(Index, isolate, NativeValueApi.GetValueFromArgument, value, false); } return(type); }
internal object AnyTranslator(IntPtr isolate, IGetValueFromJs getValueApi, IntPtr value, bool isByRef) { var type = getValueApi.GetJsValueType(isolate, value, isByRef); switch (type) { case JsValueType.BigInt: return(getValueApi.GetBigInt(isolate, value, isByRef)); case JsValueType.Boolean: return(getValueApi.GetBoolean(isolate, value, isByRef)); case JsValueType.Date: return(DateTranslator(isolate, getValueApi, value, isByRef)); case JsValueType.ArrayBuffer: return(getValueApi.GetArrayBuffer(isolate, value, isByRef)); //case JsValueType.Function: //case JsValueType.JsObject: case JsValueType.NativeObject: var typeId = getValueApi.GetTypeId(isolate, value, isByRef); if (!typeRegister.IsArray(typeId)) { var objType = typeRegister.GetType(typeId); if (objType != typeof(object) && generalGetterMap.ContainsKey(objType)) { return(generalGetterMap[objType](isolate, getValueApi, value, isByRef)); } } var objPtr = getValueApi.GetObject(isolate, value, isByRef); var result = objectPool.Get(objPtr.ToInt32()); var typedValueResult = result as TypedValue; if (typedValueResult != null) { return(typedValueResult.Target); } return(result); case JsValueType.Number: return(getValueApi.GetNumber(isolate, value, isByRef)); case JsValueType.String: return(getValueApi.GetString(isolate, value, isByRef)); default: return(null); } }