random junk

This commit is contained in:
Michael Becker 2022-09-13 09:42:59 -04:00
parent 2c11c39ff0
commit 3fbcb738dd
No known key found for this signature in database
GPG Key ID: DA394832305DA332
4 changed files with 171 additions and 0 deletions

View File

@ -0,0 +1,77 @@
//
// ConsoleExtensions.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2022 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace MBS.Framework
{
public static class ConsoleExtensions
{
public static void LogMSBuildMessage(MessageSeverity severity, string message, string code = null, string filename = null, int? line = null, int? column = null, string subcategory = null)
{
string severityString = "error";
switch (severity)
{
case MessageSeverity.Warning:
{
severityString = "warning";
break;
}
case MessageSeverity.Error:
{
severityString = "error";
break;
}
case MessageSeverity.Message:
{
severityString = "information";
break;
}
}
if (code != null)
{
if (filename != null)
{
if (line != null)
{
if (column == null)
{
column = 1;
}
Console.Error.WriteLine(String.Format("{0}({1},{2}): {6} {3} {4}: {5}", filename, line, column, severityString, code, message, subcategory));
}
else
{
Console.Error.WriteLine(String.Format("{0}: {4} {1} {2}: {3}", filename, severityString, code, message, subcategory));
}
}
else
{
Console.Error.WriteLine(String.Format("{0} {3} {1}: {2}", severityString, code, message, subcategory));
}
}
else
{
Console.Error.WriteLine(String.Format("{2} {0}: {1}", severityString, message, subcategory));
}
}
}
}

View File

@ -131,6 +131,9 @@
<Compile Include="FindFileOptions.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="NanoId.cs" />
<Compile Include="ObjectExtensions.cs" />
<Compile Include="ConsoleExtensions.cs" />
<Compile Include="MessageSeverity.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Logic\" />

View File

@ -0,0 +1,31 @@
//
// MessageSeverity.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2022 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace MBS.Framework
{
public enum MessageSeverity
{
None = 0,
Message = 1,
Warning = 2,
Error = 3
}
}

View File

@ -0,0 +1,60 @@
//
// ObjectExtensions.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2022 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace MBS.Framework
{
public static class ObjectExtensions
{
public static int SizeOf(this object obj)
{
if (obj == null) return 0;
if (obj is byte || obj is sbyte || obj is bool)
{
return 1;
}
else if (obj is ushort || obj is short)
{
return 2;
}
else if (obj is uint || obj is int || obj is float)
{
return 4;
}
else if (obj is ulong || obj is long || obj is double)
{
return 8;
}
else if (obj is decimal)
{
return 8;
}
else if (obj is Guid)
{
return 16;
}
else if (obj is string)
{
return ((string)obj).Length;
}
return System.Runtime.InteropServices.Marshal.SizeOf(obj);
}
}
}