diff --git a/MBS.Framework/ConsoleExtensions.cs b/MBS.Framework/ConsoleExtensions.cs new file mode 100644 index 0000000..652a753 --- /dev/null +++ b/MBS.Framework/ConsoleExtensions.cs @@ -0,0 +1,77 @@ +// +// ConsoleExtensions.cs +// +// Author: +// Michael Becker +// +// 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 . +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)); + } + } + + + } +} diff --git a/MBS.Framework/MBS.Framework.csproj b/MBS.Framework/MBS.Framework.csproj index 6061ed8..e05ea9c 100644 --- a/MBS.Framework/MBS.Framework.csproj +++ b/MBS.Framework/MBS.Framework.csproj @@ -131,6 +131,9 @@ + + + diff --git a/MBS.Framework/MessageSeverity.cs b/MBS.Framework/MessageSeverity.cs new file mode 100644 index 0000000..fa28913 --- /dev/null +++ b/MBS.Framework/MessageSeverity.cs @@ -0,0 +1,31 @@ +// +// MessageSeverity.cs +// +// Author: +// Michael Becker +// +// 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 . +using System; +namespace MBS.Framework +{ + public enum MessageSeverity + { + None = 0, + Message = 1, + Warning = 2, + Error = 3 + } +} diff --git a/MBS.Framework/ObjectExtensions.cs b/MBS.Framework/ObjectExtensions.cs new file mode 100644 index 0000000..4dfaeab --- /dev/null +++ b/MBS.Framework/ObjectExtensions.cs @@ -0,0 +1,60 @@ +// +// ObjectExtensions.cs +// +// Author: +// Michael Becker +// +// 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 . +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); + } + } +}