mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-14 04:35:41 +00:00
parent
5e021b703b
commit
1ee5b8ef64
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
#if NET5_0
|
#if NET5_0
|
||||||
using System.Buffers.Binary;
|
using System.Buffers.Binary;
|
||||||
@ -38,15 +39,20 @@ namespace X10D
|
|||||||
throw new ArgumentNullException(nameof(stream));
|
throw new ArgumentNullException(nameof(stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
var type = typeof(T);
|
if (!stream.CanRead)
|
||||||
var create = type.GetMethod("Create", Array.Empty<Type>());
|
{
|
||||||
if (create is null)
|
throw new IOException(ExceptionMessages.StreamDoesNotSupportReading);
|
||||||
|
}
|
||||||
|
|
||||||
|
Type type = typeof(T);
|
||||||
|
MethodInfo? createMethod = type.GetMethod("Create", BindingFlags.Public | BindingFlags.Static);
|
||||||
|
if (createMethod is null)
|
||||||
{
|
{
|
||||||
throw new TypeInitializationException(type.FullName,
|
throw new TypeInitializationException(type.FullName,
|
||||||
new ArgumentException(ExceptionMessages.HashAlgorithmNoCreateMethod));
|
new ArgumentException(ExceptionMessages.HashAlgorithmNoCreateMethod));
|
||||||
}
|
}
|
||||||
|
|
||||||
using var crypt = create.Invoke(null, null) as T;
|
using var crypt = createMethod.Invoke(null, null) as T;
|
||||||
if (crypt is null)
|
if (crypt is null)
|
||||||
{
|
{
|
||||||
throw new TypeInitializationException(type.FullName,
|
throw new TypeInitializationException(type.FullName,
|
||||||
|
Loading…
Reference in New Issue
Block a user