public static IFromJson CreateObjectFromScriptType(string scriptType, ClientRuntimeContext context) { ScriptTypeMap.EnsureInited(); foreach (IScriptTypeFactory current in ScriptTypeMap.s_scriptTypeFactories) { IFromJson fromJson = current.CreateObjectFromScriptType(scriptType, context); if (fromJson != null) { IFromJson result = fromJson; return(result); } } ScriptTypeMap.ScriptTypeInfo scriptTypeInfo = null; if (ScriptTypeMap.s_clientProxies.TryGetValue(scriptType, out scriptTypeInfo)) { IFromJson result2; if (scriptTypeInfo.ValueObject) { result2 = (Activator.CreateInstance(scriptTypeInfo.Type) as IFromJson); } else { Type arg_86_0 = scriptTypeInfo.Type; object[] array = new object[2]; array[0] = context; result2 = (Activator.CreateInstance(arg_86_0, array) as IFromJson); } return(result2); } return(null); }
public static Type GetTypeFromScriptType(string scriptType) { ScriptTypeMap.EnsureInited(); ScriptTypeMap.ScriptTypeInfo scriptTypeInfo = null; if (ScriptTypeMap.s_clientProxies.TryGetValue(scriptType, out scriptTypeInfo)) { return(scriptTypeInfo.Type); } return(null); }
internal static void AddClientProxyAssembly(Assembly assembly) { lock (ScriptTypeMap.s_lock) { if (!ScriptTypeMap.s_loadedAssemblies.ContainsKey(assembly.FullName)) { Type[] types = assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { Type type = types[i]; //Edited for .NET Core //if (type.IsClass) if (type.GetTypeInfo().IsClass) { //Edited for .NET Core //object[] customAttributes = type.GetCustomAttributes(typeof(ScriptTypeAttribute), false); object[] customAttributes = type.GetTypeInfo().GetCustomAttributes <ScriptTypeAttribute>().ToArray(); if (customAttributes.Length > 0) { ScriptTypeAttribute scriptTypeAttribute = (ScriptTypeAttribute)customAttributes[0]; //Edited for .NET Core //if (!string.IsNullOrEmpty(scriptTypeAttribute.ScriptType) && typeof(IFromJson).IsAssignableFrom(type)) if (!string.IsNullOrEmpty(scriptTypeAttribute.ScriptType) && typeof(IFromJson).GetTypeInfo().IsAssignableFrom(type)) { ScriptTypeMap.ScriptTypeInfo value = new ScriptTypeMap.ScriptTypeInfo(type, scriptTypeAttribute.ValueObject); ScriptTypeMap.s_clientProxies[scriptTypeAttribute.ScriptType] = value; if (!string.IsNullOrEmpty(scriptTypeAttribute.TypeAlias)) { ScriptTypeMap.s_clientProxies[scriptTypeAttribute.TypeAlias] = value; } ScriptTypeMap.s_typeToScriptTypeMap[type] = value; } } } } //Edited for .NET Core //object[] customAttributes2 = assembly.GetCustomAttributes(typeof(ClientTypeAssemblyAttribute), false); object[] customAttributes2 = assembly.GetCustomAttributes <ClientTypeAssemblyAttribute>().ToArray(); if (customAttributes2 != null || customAttributes2.Length != 0) { ClientTypeAssemblyAttribute clientTypeAssemblyAttribute = (ClientTypeAssemblyAttribute)customAttributes2[0]; if (clientTypeAssemblyAttribute.ScriptTypeFactory != null) { IScriptTypeFactory scriptTypeFactory = Activator.CreateInstance(clientTypeAssemblyAttribute.ScriptTypeFactory) as IScriptTypeFactory; if (scriptTypeFactory != null) { ScriptTypeMap.s_scriptTypeFactories.Add(scriptTypeFactory); } } } ScriptTypeMap.s_loadedAssemblies[assembly.FullName] = null; } } }
public static IFromJson CreateObjectFromFallbackScriptType(Type fallbackType, ClientRuntimeContext context) { ScriptTypeMap.EnsureInited(); ScriptTypeMap.ScriptTypeInfo scriptTypeInfo = null; if (ScriptTypeMap.s_typeToScriptTypeMap.TryGetValue(fallbackType, out scriptTypeInfo)) { IFromJson result; if (scriptTypeInfo.ValueObject) { result = (Activator.CreateInstance(fallbackType) as IFromJson); } else { object[] array = new object[2]; array[0] = context; result = (Activator.CreateInstance(fallbackType, array) as IFromJson); } return(result); } return(null); }