fix merge conflict

This commit is contained in:
Michael Becker 2024-07-22 23:38:36 -04:00
commit 399a5c8e34
4 changed files with 69 additions and 16 deletions

View File

@ -240,9 +240,21 @@ public class Application
*/
}
public event EventHandler<CancelEventArgs> BeforeStartInternal;
protected virtual void OnBeforeStartInternal(CancelEventArgs e)
{
BeforeStartInternal?.Invoke(this, e);
}
public int Start()
{
Instance = this;
CancelEventArgs e = new CancelEventArgs();
OnBeforeStartInternal(e);
if (e.Cancel)
return 2;
int exitCode = StartInternal();
Instance = null;

View File

@ -163,7 +163,10 @@ namespace MBS.Core
public const string DefaultAlphabet = "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const string DefaultAlphabetNoSpecialChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const string CapitalAlphabetNoSpecialChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const string CapitalAlphanumeric = "_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public const string CapitalAlphanumericNoSpecialChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static readonly CryptoRandom Random = new CryptoRandom();

View File

@ -0,0 +1,32 @@
namespace MBS.Core.Reflection;
public static class TypeExtensions
{
public static bool IsSubclassOfGeneric(this Type toCheck, Type generic)
{
// thanks https://stackoverflow.com/a/457708
while (toCheck != null && toCheck != typeof(object))
{
var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
if (generic == cur)
{
return true;
}
Type[] intfs = toCheck.GetInterfaces();
foreach (Type intf in intfs)
{
// !!! HACK HACK HACK !!!
bool hack = intf.Namespace.Equals(generic.Namespace) && intf.Name.Equals(generic.Name);
if (hack)
{
return true;
}
}
toCheck = toCheck.BaseType;
}
return false;
}
}

View File

@ -99,26 +99,32 @@ public static class StreamExtensions
_streamPositions[st].Push(st.Position);
}
private const long BUFFER_SIZE=4096;
public static byte[] ReadToEnd(this Stream st)
{
byte[] retval = new byte[0];
byte[] buffer = new byte[4096];
long j = 0;
bool remaining = true;
while (remaining)
byte[] buffer = new byte[BUFFER_SIZE];
byte[] output = new byte[0];
int i = 0;
bool done = false;
while (!done)
{
int count = st.Read(buffer, 0, buffer.Length);
if (count < buffer.Length)
int length = st.Read(buffer, 0, buffer.Length);
if (length == 0)
{
Array.Resize<byte>(ref buffer, count);
remaining = false;
done = true;
break;
}
Array.Resize<byte>(ref retval, retval.Length + buffer.Length);
Array.Copy(buffer, 0, retval, j, buffer.Length);
j += buffer.Length;
if (length < BUFFER_SIZE)
{
Array.Resize<byte>(ref buffer, length);
done = true;
}
Array.Resize<byte>(ref output, output.Length + buffer.Length);
Array.Copy(buffer, 0, output, i, buffer.Length);
i += buffer.Length;
}
return retval;
return output;
}
}