Skip to content

MariBotOfficial/MariGlobals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MariGlobals

Global things for all Mari's projects

Usage

MariGlobals is an agreggate of global things of all other Mari's projects.

AsyncEvent

You can simply creates an async event with all things already handled (lock, multiples handlers, etc).
Unfortunatelly if you want 2 or more parameters in your event you'll need to create your own EventArgs or something like.
Obs: You can use an AsyncEvent without any args too.

Creating an AsyncEvent with args.

using MariGlobals.Class.Event;
using System;
using System.Threading.Tasks;

namespace Example
{
    public class Example
    {
        public Example()
            => _myEvent = new AsyncEvent<ExampleEventArgs>();

        public event AsyncEventHandler<ExampleEventArgs> MyEvent
        {
            add => _myEvent.Register(value);
            remove => _myEvent.Unregister(value);
        }

        private readonly AsyncEvent<ExampleEventArgs> _myEvent;

        internal Task InvokeEventAsync(ExampleEventArgs args)
            => _myEvent.InvokeAsync(args);
    }

    public class ExampleEventArgs : EventArgs
    {
    }
}

Creating an AsyncEvent without args

using MariGlobals.Class.Event;
using System;
using System.Threading.Tasks;

namespace Example
{
    public class Example
    {
        public Example()
            => _myEvent = new AsyncEvent();

        public event AsyncEventHandler MyEvent
        {
            add => _myEvent.Register(value);
            remove => _myEvent.Unregister(value);
        }

        private readonly AsyncEvent _myEvent;

        internal Task InvokeEventAsync()
            => _myEvent.InvokeAsync();
    }
}

License

MariGlobals is provided under The MIT License.