EventGenerator.Generator
0.13.1
dotnet add package EventGenerator.Generator --version 0.13.1
NuGet\Install-Package EventGenerator.Generator -Version 0.13.1
<PackageReference Include="EventGenerator.Generator" Version="0.13.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add EventGenerator.Generator --version 0.13.1
#r "nuget: EventGenerator.Generator, 0.13.1"
// Install EventGenerator.Generator as a Cake Addin #addin nuget:?package=EventGenerator.Generator&version=0.13.1 // Install EventGenerator.Generator as a Cake Tool #tool nuget:?package=EventGenerator.Generator&version=0.13.1
EventGenerator
Generates events, OnEvent()
and IDisposable SubscribeToEventName(handler)
methods. Can generate complex EventArgs from multi-type attributes.
Install
Install-Package EventGenerator.Generator
<PackageReference Include="EventGenerator.Generator" Version="0.3.3" PrivateAssets="all" ExcludeAssets="runtime" />
Usage
[Event<string, string>("DataChanged", PropertyNames = new [] { "Title", "Namespace" })]
public partial class MyClass
{
}
will generate:
//HintName: MyClass.Events.DataChanged.generated.cs
#nullable enable
namespace H.Generators.IntegrationTests
{
public partial class MyClass
{
/// <summary>
/// </summary>
public event global::System.EventHandler<global::H.Generators.IntegrationTests.MyClass.DataChangedEventArgs>? DataChanged;
/// <summary>
/// A helper method to subscribe to the DataChanged event.
/// </summary>
public global::System.IDisposable SubscribeToDataChanged(global::System.EventHandler<global::H.Generators.IntegrationTests.MyClass.DataChangedEventArgs> handler)
{
DataChanged += handler;
return new global::EventGenerator.Disposable(() => DataChanged -= handler);
}
/// <summary>
/// A helper method to raise the DataChanged event.
/// </summary>
protected virtual global::H.Generators.IntegrationTests.MyClass.DataChangedEventArgs OnDataChanged(global::H.Generators.IntegrationTests.MyClass.DataChangedEventArgs args)
{
DataChanged?.Invoke(this, args);
return args;
}
/// <summary>
/// A helper method to raise the DataChanged event.
/// </summary>
protected virtual global::H.Generators.IntegrationTests.MyClass.DataChangedEventArgs OnDataChanged(
string title,
string @namespace)
{
var args = new global::H.Generators.IntegrationTests.MyClass.DataChangedEventArgs(title, @namespace);
DataChanged?.Invoke(this, args);
return args;
}
}
}
//HintName: MyClass.EventArgs.DataChangedEventArgs.generated.cs
#nullable enable
namespace H.Generators.IntegrationTests
{
public partial class MyClass
{
/// <summary>
///
/// </summary>
public class DataChangedEventArgs : global::System.EventArgs
{
/// <summary>
///
/// </summary>
public string Title { get; }
/// <summary>
///
/// </summary>
public string Namespace { get; }
/// <summary>
///
/// </summary>
public DataChangedEventArgs(string title, string @namespace)
{
Title = title;
Namespace = @namespace;
}
/// <summary>
///
/// </summary>
public void Deconstruct(out string title, out string @namespace)
{
title = Title;
@namespace = Namespace;
}
/// <summary>
///
/// </summary>
public override string ToString()
{
return $"(Title={Title}, Namespace={Namespace})";
}
}
}
}
Open questions
- Should we use EventArgs for the single type case? This is useful, for example, if the type of the Cancel property is bool, which allows you to tell the calling code to cancel something.
- Should we always generate EventArgs or allow Action delegates to be used for these cases?
Notes
To use generic attributes, you need to set up LangVersion
in your .csproj:
<LangVersion>latest</LangVersion>
There are also non-Generic attributes here.
Support
Priority place for bugs: https://github.com/HavenDV/EventGenerator/issues
Priority place for ideas and general questions: https://github.com/HavenDV/EventGenerator/discussions
I also have a Discord support channel:
https://discord.gg/g8u2t9dKgE
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. |
.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 was computed. |
.NET Framework | net451 is compatible. net452 was computed. net46 was computed. 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.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on EventGenerator.Generator:
Repository | Stars |
---|---|
HavenDV/H.NotifyIcon
TrayIcon for WPF/WinUI/Uno/MAUI
|
|
HavenDV/H.Pipes
A simple, easy to use, strongly-typed, async wrapper around .NET named pipes.
|
|
HavenDV/H.Socket.IO
This is the Socket.IO client for .NET, which is based on ClientWebSocket, provide a simple way to connect to the Socket.IO server. The target framework is .NET Standard 2.0
|
Version | Downloads | Last updated |
---|---|---|
0.13.1 | 1,939 | 9/2/2024 |
0.13.0 | 2,753 | 3/30/2023 |
0.12.0 | 217 | 3/30/2023 |
0.11.0 | 644 | 3/9/2023 |
0.10.0 | 546 | 1/19/2023 |
0.9.0 | 472 | 1/4/2023 |
0.8.2 | 322 | 1/4/2023 |
0.8.1 | 299 | 1/4/2023 |
0.8.0 | 307 | 1/4/2023 |
0.6.0 | 324 | 11/22/2022 |
0.4.2 | 572 | 10/9/2022 |
0.4.1 | 739 | 7/25/2022 |
0.4.0 | 387 | 7/25/2022 |
0.3.3 | 406 | 7/25/2022 |
0.3.2 | 419 | 7/24/2022 |
0.3.1 | 446 | 7/24/2022 |
0.2.5 | 482 | 7/19/2022 |
0.2.4 | 462 | 7/19/2022 |
0.2.3 | 444 | 7/19/2022 |
0.2.2 | 497 | 7/19/2022 |
⭐ Last 10 features:
Added SubscribeToEventName generated methods.
Added limited support for generic EventArgs types.
To steps.
Added support for static events.
Added ToString override for EventArgs classes.
Added ability to specify property names.
Updated NuGet packages.
Added one simple type EventArgs generation.
Added complex EventArgs generation from multi-type attributes.
Added possibility of embedding attributes.
🐞 Last 10 fixes:
Fixed project.
Fixed bug when PropertyName is keyword.
Fixed missing empty EventArgs classes xml doc.
Fixed bug with class accessibility.
Fixed nullable emdedding.
Fixed net4.5.1 attributes dll.
Fixed problems with wildcards.
Fixed latest commit.
Simplified attributes.
Added virtual to protected methods.