EmitterSharp 1.1.1.1

C# implementation of Emitter in JavaScript module. See https://github.com/component/emitter for details.

Requires NuGet 2.12 or higher.

Install-Package EmitterSharp -Version 1.1.1.1
dotnet add package EmitterSharp --version 1.1.1.1
<PackageReference Include="EmitterSharp" Version="1.1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EmitterSharp --version 1.1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

EmitterSharp

C# implementation of Emitter in JavaScript module.

Installation

  • Nuget gallery

  • Command Install-Package EmitterSharp in nuget package manager console.

Usage

Namespace

using EmitterSharp;

Inheritance

class ExampleEmitter : Emitter<ExampleEmitter, string, object>
{
  ...
}

Emitter<TChildClass, TEvent, TArgument>

public abstract class Emitter<TChildClass, TEvent, TArgument>
  • The first generic type is a type of class that inherits Emitter. This is used for chaining.
  • The second generic type is a type of event.
  • The third generic type is a type of argument in callback.

Listener

void ExampleCallback() 
{
  Console.WriteLine("This is callback.");
}

void ExampleCallbackWithArgument(object value) 
{
  if (value != null) 
  {
    Console.WriteLine("This is callback : " + value);
  }
  else
  {
    Console.WriteLine("This is callback... Wait, what?");
  }
}

ExampleEmitter emitter = new ExampleEmitter();

emitter.On("custom event", () => Console.WriteLine("Hello world!")); // Callback can be lambda without argument.
emitter.On("custom event", (value) => // Callback can be lambda with argument.
{
  if (value != null)
  {
    Console.WriteLine(value);
  }
  else 
  {
    Console.WriteLine("Excuse me?");
  }
});

emitter.On("custom event", ExampleCallback); // Callback can be method without argument.
emitter.On("custom event", ExampleCallbackWithArgument); // Callback can be method with argument.

emitter.Emit("custom event"); // Emit without argument.
// Console will print "Hello world!", "Excuse me?", "This is callback." and "This is callback... Wait, what?"

emitter.Emit("custom event", 30); // Emit with argument.
// Console will print "Hello world!", 30, "This is callback." and "This is callback : 30"

Emit without argument

  • When Emitter.Emit is called only with event, default value of argument is always 0.
  • If TArgument is bool, default value of argument is false since it's defined as 0.
  • If TArgument is string, default value of argument is null since it's a reference to address 0.
  • If TArgument is IntPtr, default value of argument is IntPtr.Zero that is defined as null reference.

Maintenance

Welcome to report issue or create pull request. I will check it happily.

Dependencies

License

EmitterSharp is under The MIT License.

EmitterSharp

C# implementation of Emitter in JavaScript module.

Installation

  • Nuget gallery

  • Command Install-Package EmitterSharp in nuget package manager console.

Usage

Namespace

using EmitterSharp;

Inheritance

class ExampleEmitter : Emitter<ExampleEmitter, string, object>
{
  ...
}

Emitter<TChildClass, TEvent, TArgument>

public abstract class Emitter<TChildClass, TEvent, TArgument>
  • The first generic type is a type of class that inherits Emitter. This is used for chaining.
  • The second generic type is a type of event.
  • The third generic type is a type of argument in callback.

Listener

void ExampleCallback() 
{
  Console.WriteLine("This is callback.");
}

void ExampleCallbackWithArgument(object value) 
{
  if (value != null) 
  {
    Console.WriteLine("This is callback : " + value);
  }
  else
  {
    Console.WriteLine("This is callback... Wait, what?");
  }
}

ExampleEmitter emitter = new ExampleEmitter();

emitter.On("custom event", () => Console.WriteLine("Hello world!")); // Callback can be lambda without argument.
emitter.On("custom event", (value) => // Callback can be lambda with argument.
{
  if (value != null)
  {
    Console.WriteLine(value);
  }
  else 
  {
    Console.WriteLine("Excuse me?");
  }
});

emitter.On("custom event", ExampleCallback); // Callback can be method without argument.
emitter.On("custom event", ExampleCallbackWithArgument); // Callback can be method with argument.

emitter.Emit("custom event"); // Emit without argument.
// Console will print "Hello world!", "Excuse me?", "This is callback." and "This is callback... Wait, what?"

emitter.Emit("custom event", 30); // Emit with argument.
// Console will print "Hello world!", 30, "This is callback." and "This is callback : 30"

Emit without argument

  • When Emitter.Emit is called only with event, default value of argument is always 0.
  • If TArgument is bool, default value of argument is false since it's defined as 0.
  • If TArgument is string, default value of argument is null since it's a reference to address 0.
  • If TArgument is IntPtr, default value of argument is IntPtr.Zero that is defined as null reference.

Maintenance

Welcome to report issue or create pull request. I will check it happily.

Dependencies

License

EmitterSharp is under The MIT License.

Release Notes

Add .Net core 2.0, 3.0 support.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on EmitterSharp:

Package Downloads
EngineIOSharp
C# implementation of Engine.IO protocol revision 3 client and server.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.1.1 223 5/11/2020