TG.Common
3.0.0-preview.0.33
dotnet add package TG.Common --version 3.0.0-preview.0.33
NuGet\Install-Package TG.Common -Version 3.0.0-preview.0.33
<PackageReference Include="TG.Common" Version="3.0.0-preview.0.33" />
<PackageVersion Include="TG.Common" Version="3.0.0-preview.0.33" />
<PackageReference Include="TG.Common" />
paket add TG.Common --version 3.0.0-preview.0.33
#r "nuget: TG.Common, 3.0.0-preview.0.33"
#:package TG.Common@3.0.0-preview.0.33
#addin nuget:?package=TG.Common&version=3.0.0-preview.0.33&prerelease
#tool nuget:?package=TG.Common&version=3.0.0-preview.0.33&prerelease
TG.Common
This library provides utilities for logging to file, object cloning, delayed method invocation, task helpers, and other small helpers. It targets .NET Standard 2.0 and 2.1 and has nullable reference types enabled.
Note on WinForms helpers: InputBox/ExMessageBox/WaitForm have moved to a separate repository (TG.Common.WinForms) and are no longer part of this package.
AssemblyInfo
This class helps to get various Assembly information, such as the Version, InformationVersion, Title or Company. The default assembly referenced is Assembly.GetEntryAssembly() (with a safe fallback to the executing assembly).
Basic AssemblyInfo Usage
Console.WriteLine(AssemblyInfo.Title);
Console.WriteLine(AssemblyInfo.InformationalVersion);
Changing the referenced assembly
AssemblyInfo.ReferenceAssembly = Assembly.GetCallingAssembly();
Any subsequent calls on the AssemblyInfo properties will pull from the new ReferenceAssembly.
AppData
The AppData class is a helper for generating a folder in the user's AppData folder. If the folder doesn't exist, it will automatically be created. There are several schemes to choose from for the subfolder structure. For Windows, that would be at C:\Users\<user>\Roaming. In Linux, that would be at ~/.config.
Schemes
- CompanyTitle
- Generates %AppData%\AssemblyInfo.Company\AssemblyInfo.Title
- CompanyProduct
- Generates %AppData%\AssemblyInfo.Company\AssemblyInfo.Product
- Company
- Generates %AppData%\AssemblyInfo.Company
- Title
- Generates %AppData%\AssemblyInfo.Title
- Product
- Generates %AppData%\AssemblyInfo.Product
You can also call AppData.GetAppDataPath(AppDataSchemes) for better control or setting the property AppData.DefaultScheme.
LogManager
The LogManager class is a simple file logger were you only need something small to log to a file. It is suitable if you only need a small library to write error to a log. It doesn't currently have any mechanism for writing for only certain log levels but that could be added if there is interest.
Log Example
// Sets up logging folder using AppData.AppDataPath/Logging.
// Setting AppData.DefaultScheme can control the folder structure.
LogManager.InitializeDefaultLog();
try
{
throw new Exception("Something bad happened!");
}
catch (Exception ex)
{
LogManager.WriteExceptionToLog(ex);
}
Crypto
Modern symmetric encryption with AES-CBC and a random IV per message.
- New encryptions: payload is IV || CIPHERTEXT (IV is 16 bytes)
- Decryption first attempts the new AES format, then falls back to legacy Rijndael with the historical fixed IV for backward compatibility
- Keys: input key bytes are normalized to 32 bytes (SHA-like padding behavior preserved from prior version)
Examples
var crypto = new TG.Common.Crypto("my-secret-key");
string cipher = crypto.EncryptBase64("Hello, world");
string plain = crypto.DecryptBase64(cipher); // "Hello, world"
DelayedMethodInvoker
This class provides a way to invoke a method after a set amount of time. Once initialized, call Invoke and the internal timer is started. You can also call the RestartTimer method and the timer will start/restart. That can be useful for "debouncing" a button click.
WinForms (moved)
The WinForms helpers (InputBox, ExMessageBox, WaitForm) were split into a separate package to keep TG.Common cross-platform. See the TG.Common.WinForms repository/package.
Miscellaneous
This class has one-off helpers. The only notable one would be CloneObject; which can do a deep clone of an object.
Task helpers
Includes helpers like SafeFireAndForget for safely ignoring tasks while still catching exceptions.
// Attach a global exception handler if desired
TG.Common.TaskHelpers.DefaultSafeFireAndForgetExceptionHandler = ex => TG.Common.LogManager.WriteExceptionToLog(ex);
// Fire and forget safely
SomeAsyncCall().SafeFireAndForget(onException: ex => Console.WriteLine(ex));
Target frameworks and nullability
- Target frameworks: netstandard2.0; netstandard2.1
- Nullable reference types: enabled
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TG.Common:
Package | Downloads |
---|---|
TG.Common.WinForms
Windows Forms utilities split from TG.Common. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
3.0.0-preview.0.33 | 125 | 8/11/2025 |
2.0.1-preview.0.27 | 114 | 8/11/2025 |
2.0.1-preview.0.24 | 192 | 11/6/2022 |
2.0.1-preview.0.23 | 172 | 11/6/2022 |
2.0.0 | 723 | 11/6/2022 |
1.2.2 | 416 | 11/3/2022 |
1.2.1 | 415 | 5/5/2021 |
1.2.0 | 471 | 1/5/2021 |
1.1.22 | 704 | 3/17/2019 |