Skip to content

Commit

Permalink
Remove remnants of support for older .NET Standards
Browse files Browse the repository at this point in the history
  • Loading branch information
Saalvage committed Nov 25, 2024
1 parent defaa95 commit b41e3bf
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 119 deletions.
7 changes: 2 additions & 5 deletions AssimpNet/MemoryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Generic;
using Assimp.Unmanaged;
using System.Reflection;
using System.Runtime.CompilerServices;

namespace Assimp
Expand Down Expand Up @@ -1034,10 +1034,7 @@ private static bool HasNativeCustomMarshaler(Type type, out INativeCustomMarshal
{
if(!s_customMarshalers.TryGetValue(type, out marshaler))
{
object[] customAttributes = PlatformHelper.GetCustomAttributes(type, typeof(NativeCustomMarshalerAttribute), false);
if(customAttributes.Length != 0)
marshaler = (customAttributes[0] as NativeCustomMarshalerAttribute).Marshaler;

marshaler = type.GetCustomAttribute<NativeCustomMarshalerAttribute>(false)?.Marshaler;
s_customMarshalers.Add(type, marshaler);
}
}
Expand Down
5 changes: 2 additions & 3 deletions AssimpNet/NativeMarshalerAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

using System;
using Assimp.Unmanaged;

namespace Assimp
{
Expand All @@ -47,9 +46,9 @@ public sealed class NativeCustomMarshalerAttribute : Attribute
public NativeCustomMarshalerAttribute(Type type)
{
if (type == null)
throw new NullReferenceException("type");
throw new NullReferenceException(nameof(type));

if (!PlatformHelper.IsAssignable(typeof(INativeCustomMarshaler), type))
if (!typeof(INativeCustomMarshaler).IsAssignableFrom(type))
throw new ArgumentException($"{type.FullName} does not implement INativeCustomMarshaler.");

m_marshaler = Activator.CreateInstance(type) as INativeCustomMarshaler;
Expand Down
2 changes: 1 addition & 1 deletion AssimpNet/Unmanaged/AssimpLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private AssimpLibrary(string defaultLibName, Type[] unmanagedFunctionDelegateTyp

private static AssimpLibrary CreateInstance()
{
return new AssimpLibrary(DefaultLibName, PlatformHelper.GetNestedTypes(typeof(Functions)));
return new AssimpLibrary(DefaultLibName, typeof(Functions).GetNestedTypes());
}

#region Import Methods
Expand Down
97 changes: 0 additions & 97 deletions AssimpNet/Unmanaged/PlatformHelper.cs

This file was deleted.

13 changes: 4 additions & 9 deletions AssimpNet/Unmanaged/UnmanagedLibraryImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

namespace Assimp.Unmanaged
{
Expand Down Expand Up @@ -139,22 +141,15 @@ private void LoadFunctions()
Delegate function;
if(!m_nameToUnmanagedFunction.TryGetValue(funcName, out function))
{
function = PlatformHelper.GetDelegateForFunctionPointer(procAddr, funcType);
function = Marshal.GetDelegateForFunctionPointer(procAddr, funcType);
m_nameToUnmanagedFunction.Add(funcName, function);
}
}
}

private string GetUnmanagedName(Type funcType)
{
object[] attributes = PlatformHelper.GetCustomAttributes(funcType, typeof(UnmanagedFunctionNameAttribute), false);
foreach(object attr in attributes)
{
if(attr is UnmanagedFunctionNameAttribute)
return (attr as UnmanagedFunctionNameAttribute).UnmanagedFunctionName;
}

return null;
return funcType.GetCustomAttribute<UnmanagedFunctionNameAttribute>(false)?.UnmanagedFunctionName;
}

protected abstract IntPtr NativeLoadLibrary(string path);
Expand Down
10 changes: 6 additions & 4 deletions AssimpNet/Unmanaged/UnmanagedLibraryResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

namespace Assimp.Unmanaged
Expand Down Expand Up @@ -206,7 +207,7 @@ private string ResolveLibraryPathInternal(string libName, string rid, string[] f
}

//Check runtimes folder based on RID
string runtimeFolder = Path.Combine(PlatformHelper.GetAppBaseDirectory(), Path.Combine("runtimes", Path.Combine(rid, "native")));
string runtimeFolder = Path.Combine(AppContext.BaseDirectory, Path.Combine("runtimes", Path.Combine(rid, "native")));
if(Directory.Exists(runtimeFolder))
{
string potentialPath = TryGetExistingFile(runtimeFolder, libName, fallbackNames);
Expand All @@ -215,7 +216,7 @@ private string ResolveLibraryPathInternal(string libName, string rid, string[] f
}

//Check base directory
string pathInAppFolder = TryGetExistingFile(PlatformHelper.GetAppBaseDirectory(), libName, fallbackNames);
string pathInAppFolder = TryGetExistingFile(AppContext.BaseDirectory, libName, fallbackNames);
if(!string.IsNullOrEmpty(pathInAppFolder))
return pathInAppFolder;

Expand All @@ -240,8 +241,9 @@ private string GetPackageRuntimeFolder(string packagePath, string rid)
private string GetNugetPackagePath()
{
//Resolve packageId based on assembly informational version
string packageId = PlatformHelper.GetAssemblyName().ToLowerInvariant();
string packageVersion = PlatformHelper.GetInformationalVersion();
Assembly assembly = Assembly.GetExecutingAssembly();
string packageId = assembly.GetName().Name.ToLowerInvariant();
string packageVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
if(string.IsNullOrEmpty(packageId) || string.IsNullOrEmpty(packageVersion))
return null;

Expand Down

0 comments on commit b41e3bf

Please sign in to comment.