Optimize C# types searching with typename

This commit is contained in:
Wojtek Figat
2022-04-13 19:48:39 +02:00
parent 738e7d2516
commit 017492dbfa
2 changed files with 18 additions and 51 deletions

View File

@@ -233,18 +233,7 @@ namespace FlaxEditor.Scripting
{
if (string.IsNullOrEmpty(typeName))
return null;
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
for (int i = 0; i < assemblies.Length; i++)
{
var assembly = assemblies[i];
if (assembly != null)
{
var type = assembly.GetType(typeName);
if (type != null)
return type;
}
}
return null;
return Type.GetType(typeName);
}
/// <summary>
@@ -258,18 +247,10 @@ namespace FlaxEditor.Scripting
return ScriptType.Null;
// C#/C++ types
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
for (int i = 0; i < assemblies.Length; i++)
{
var assembly = assemblies[i];
if (assembly != null)
{
var type = assembly.GetType(typeName);
if (type != null)
{
return new ScriptType(type);
}
}
var type = Type.GetType(typeName);
if (type != null)
return new ScriptType(type);
}
// Custom types
@@ -277,9 +258,7 @@ namespace FlaxEditor.Scripting
{
var type = customTypesInfo.GetType(typeName);
if (type)
{
return type;
}
}
return ScriptType.Null;

View File

@@ -25,38 +25,26 @@ namespace FlaxEngine
if (WaitForLoaded())
return null;
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
object obj = null;
var dataTypeName = DataTypeName;
for (int i = 0; i < assemblies.Length; i++)
var type = Type.GetType(dataTypeName);
if (type != null)
{
var assembly = assemblies[i];
if (assembly != null)
try
{
var type = assembly.GetType(dataTypeName);
if (type != null)
{
object obj = null;
try
{
// Create instance
obj = Activator.CreateInstance(type);
// Create instance
obj = Activator.CreateInstance(type);
// Deserialize object
var data = Data;
JsonSerializer.Deserialize(obj, data);
}
catch (Exception ex)
{
Debug.LogException(ex);
}
return obj;
}
// Deserialize object
var data = Data;
JsonSerializer.Deserialize(obj, data);
}
catch (Exception ex)
{
Debug.LogException(ex);
}
}
return null;
return obj;
}
}
}