Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor ResolveReaderType #1553

Merged
merged 9 commits into from
May 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 21 additions & 29 deletions src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

private static readonly string _contentAssemblyName;
private static readonly string _contentGraphicsAssemblyName;
private static readonly string _contentVideoAssemblyName;
private static readonly string _contentAudioAssemblyName;
private static readonly string _contentMediaAssemblyName;

private static readonly bool _isRunningOnNetCore;

Expand All @@ -32,7 +33,8 @@
_contentReadersCache = new Dictionary<Type, ContentTypeReader>(255);
_contentAssemblyName = ReflectionHelpers.GetAssembly(typeof(ContentTypeReaderManager)).FullName;
_contentGraphicsAssemblyName = "Xna.Framework.Graphics";
_contentVideoAssemblyName = "Xna.Framework.Media";
_contentAudioAssemblyName = "Xna.Framework.Audio";
_contentMediaAssemblyName = "Xna.Framework.Media";

_isRunningOnNetCore = ReflectionHelpers.GetAssembly(typeof(System.Object)).GetName().Name == "System.Private.CoreLib";

Expand Down Expand Up @@ -203,18 +205,16 @@
// map net.framework (.net4) to core.net (.net5 or later)
if (readerTypeName.Contains(", mscorlib") && _isRunningOnNetCore)
{
resolvedReaderTypeName = readerTypeName;
resolvedReaderTypeName = readerTypeName.Replace(", mscorlib", ", System.Private.CoreLib");
readerType = Type.GetType(resolvedReaderTypeName);

Check warning on line 209 in src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs

View workflow job for this annotation

GitHub Actions / build

Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.
if (readerType != null)
return readerType;
}
// map core.net (.net5 or later) to net.framework (.net4)
if (readerTypeName.Contains(", System.Private.CoreLib") && !_isRunningOnNetCore)
{
resolvedReaderTypeName = readerTypeName;
resolvedReaderTypeName = resolvedReaderTypeName.Replace(", System.Private.CoreLib", ", mscorlib");
resolvedReaderTypeName = readerTypeName.Replace(", System.Private.CoreLib", ", mscorlib");
readerType = Type.GetType(resolvedReaderTypeName);

Check warning on line 217 in src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs

View workflow job for this annotation

GitHub Actions / build

Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.
if (readerType != null)
return readerType;
}
Expand All @@ -222,58 +222,50 @@
// map XNA build-in TypeReaders
resolvedReaderTypeName = readerTypeName;
resolvedReaderTypeName = resolvedReaderTypeName.Replace(", Microsoft.Xna.Framework.Graphics", string.Format(", {0}", _contentGraphicsAssemblyName));
resolvedReaderTypeName = resolvedReaderTypeName.Replace(", Microsoft.Xna.Framework.Video", string.Format(", {0}", _contentVideoAssemblyName));
resolvedReaderTypeName = resolvedReaderTypeName.Replace(", Microsoft.Xna.Framework", string.Format(", {0}", _contentAssemblyName));
resolvedReaderTypeName = resolvedReaderTypeName.Replace(", Microsoft.Xna.Framework.Video", string.Format(", {0}", _contentMediaAssemblyName));
resolvedReaderTypeName = resolvedReaderTypeName.Replace(", Microsoft.Xna.Framework", string.Format(", {0}", _contentAssemblyName));
readerType = Type.GetType(resolvedReaderTypeName);

Check warning on line 227 in src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs

View workflow job for this annotation

GitHub Actions / build

Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.
if (readerType != null)
return readerType;

// map XNA & MonoGame build-in TypeReaders
resolvedReaderTypeName = readerTypeName;
resolvedReaderTypeName = resolvedReaderTypeName.Replace(", Microsoft.Xna.Framework", string.Format(", {0}", "Xna.Framework"));
resolvedReaderTypeName = resolvedReaderTypeName.Replace(", MonoGame.Framework", string.Format(", {0}", "Xna.Framework"));
// map XNA build-in TypeReaders
resolvedReaderTypeName = readerTypeName.Replace(", Microsoft.Xna.Framework", string.Format(", {0}", "Xna.Framework"));
readerType = Type.GetType(resolvedReaderTypeName);

Check warning on line 233 in src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs

View workflow job for this annotation

GitHub Actions / build

Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.
if (readerType != null)
return readerType;

resolvedReaderTypeName = readerTypeName;
resolvedReaderTypeName = resolvedReaderTypeName.Replace(", MonoGame.Framework", string.Format(", {0}", "Xna.Framework.Audio"));
resolvedReaderTypeName = readerTypeName + string.Format(", {0}", "MonoGame.Framework");
readerType = Type.GetType(resolvedReaderTypeName);
if (readerType != null)
return readerType;

resolvedReaderTypeName = readerTypeName;
resolvedReaderTypeName = resolvedReaderTypeName.Replace(", MonoGame.Framework", string.Format(", {0}", "Xna.Framework.Media"));
resolvedReaderTypeName = readerTypeName + string.Format(", {0}", _contentGraphicsAssemblyName);
readerType = Type.GetType(resolvedReaderTypeName);
if (readerType != null)
return readerType;

resolvedReaderTypeName = readerTypeName;
resolvedReaderTypeName = resolvedReaderTypeName.Replace(", MonoGame.Framework", string.Format(", {0}", "Xna.Framework.Graphics"));
resolvedReaderTypeName = readerTypeName + string.Format(", {0}", _contentAudioAssemblyName);
readerType = Type.GetType(resolvedReaderTypeName);
if (readerType != null)
return readerType;

resolvedReaderTypeName = readerTypeName;
resolvedReaderTypeName = readerTypeName + ", MonoGame.Framework";
resolvedReaderTypeName = readerTypeName + string.Format(", {0}", _contentMediaAssemblyName);
readerType = Type.GetType(resolvedReaderTypeName);
if (readerType != null)
return readerType;

resolvedReaderTypeName = readerTypeName;
resolvedReaderTypeName = readerTypeName + ", Xna.Framework.Audio";
// map MonoGame build-in TypeReaders
resolvedReaderTypeName = readerTypeName.Replace(", MonoGame.Framework", string.Format(", {0}", "Xna.Framework"));
readerType = Type.GetType(resolvedReaderTypeName);

Check warning on line 257 in src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs

View workflow job for this annotation

GitHub Actions / build

Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.
if (readerType != null)
return readerType;

resolvedReaderTypeName = readerTypeName;
resolvedReaderTypeName = readerTypeName + ", Xna.Framework.Media";
resolvedReaderTypeName = readerTypeName.Replace(", MonoGame.Framework", string.Format(", {0}", _contentGraphicsAssemblyName));
readerType = Type.GetType(resolvedReaderTypeName);

Check warning on line 261 in src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs

View workflow job for this annotation

GitHub Actions / build

Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.
if (readerType != null)
return readerType;

resolvedReaderTypeName = readerTypeName;
resolvedReaderTypeName = readerTypeName + ", Xna.Framework.Graphics";
resolvedReaderTypeName = readerTypeName.Replace(", MonoGame.Framework", string.Format(", {0}", _contentAudioAssemblyName));
readerType = Type.GetType(resolvedReaderTypeName);

Check warning on line 265 in src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs

View workflow job for this annotation

GitHub Actions / build

Unrecognized value passed to the parameter 'typeName' of method 'System.Type.GetType(String)'. It's not possible to guarantee the availability of the target type.
if (readerType != null)
return readerType;
resolvedReaderTypeName = readerTypeName.Replace(", MonoGame.Framework", string.Format(", {0}", _contentMediaAssemblyName));
readerType = Type.GetType(resolvedReaderTypeName);
if (readerType != null)
return readerType;
Expand Down
Loading