Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benjaminabt/assemblymetadata
Small sample how to use Source Code Generators in .NET
https://github.com/benjaminabt/assemblymetadata
Last synced: 22 days ago
JSON representation
Small sample how to use Source Code Generators in .NET
- Host: GitHub
- URL: https://github.com/benjaminabt/assemblymetadata
- Owner: BenjaminAbt
- License: mit
- Created: 2021-08-08T18:41:38.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-27T16:59:30.000Z (almost 2 years ago)
- Last Synced: 2024-12-02T19:51:50.391Z (24 days ago)
- Language: C#
- Homepage:
- Size: 34.2 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# AssemblyMetadata
Hi,
I'm AssemblyMetadata by Benjamin Abt. I'm a small sample how to use Source Code Generators with .NET.
In this case, this example just adds the local timestamp on build into a static class. You can use it to show your users when your application was built.## NuGet
| NuGet |
|-|
| [![AssemblyMetadata](https://img.shields.io/nuget/v/AssemblyMetadata.svg?logo=nuget&label=AssemblyMetadata)](https://www.nuget.org/packages/AssemblyMetadata) |```xml
```## Usage
Right now, only one sub class is offered.
### Build Time
The build time is provided as ISO 8601 string.
```csharp
string timeIso8601 = AssemblyMetadataInfo.BuildInfo.BuildTimestamp;
```You can use the format "o" to parse the string into DateTimeOffset.
```csharp
DateTimeOffset buildOn = DateTimeOffset.ParseExact(AssemblyMetadataInfo.BuildInfo.BuildTimestamp, "o", null);
```Also, the Source Code Generator adds the the build time as digits, so you can just concat the values instead to parse the string.
```csharp
int day = AssemblyMetadataInfo.BuildInfo.BuildTimeDay;
int month = AssemblyMetadataInfo.BuildInfo.BuildTimeMonth;
int hour = AssemblyMetadataInfo.BuildInfo.BuildTimeYear;
```Have fun!
## Thank you
Please donate - if possible - to necessary institutions of your choice such as child cancer aid, children's hospices etc. Thanks!