-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Based on commit 19eefed Created by CircleCI job Build #897 https://circleci.com/gh/jilleJr/Newtonsoft.Json-for-Unity.Converters/897
- Loading branch information
Showing
11 changed files
with
116 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("Newtonsoft.Json.UnityConverters.Editor")] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Newtonsoft.Json.UnityConverters.Utility | ||
{ | ||
internal static class TypeCache | ||
{ | ||
private static readonly Dictionary<string, Type> _typeByName | ||
= new Dictionary<string, Type>(); | ||
|
||
private static readonly Assembly[] _assemblies | ||
= AppDomain.CurrentDomain.GetAssemblies() | ||
// Reversing so we get last imported assembly first. | ||
// When searching for types we want to look in mscorlib last | ||
// and Newtonsoft.Json up as the first ones | ||
.Reverse() | ||
.ToArray(); | ||
|
||
public static Type FindType(string name) | ||
{ | ||
if (_typeByName.TryGetValue(name, out var type)) | ||
{ | ||
return type; | ||
} | ||
else | ||
{ | ||
// Check this assembly, or if it has AssemblyQualifiedName | ||
type = Type.GetType(name); | ||
if (type != null) | ||
{ | ||
_typeByName[name] = type; | ||
return type; | ||
} | ||
|
||
// Check all the other assemblies, from last imported to first | ||
foreach (var assembly in _assemblies) | ||
{ | ||
type = assembly.GetType(name); | ||
if (type != null) | ||
{ | ||
_typeByName[name] = type; | ||
return type; | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters