feat: Add extensions to raise events for common event args

This commit is contained in:
Drew Tingen
2020-08-03 16:48:16 -04:00
committed by Chris Cameron
parent 00a75c6d72
commit c8edac0f14
11 changed files with 175 additions and 6 deletions

View File

@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added Get and Set extensions to PropertyInfo in SIMPLSHARP to mimic overloads avaliable in NETSTANDARD
- Added Collection extensions for setting and adding ranges of items
- Added a method for getting the total number of seconds in a date
- Added extensions to raise events with common event args using the data directly
### Changed
- Repeater changed to use configured callbacks instead of a dumb event

View File

@@ -1,4 +1,8 @@
namespace ICD.Common.Utils.EventArguments
using System;
using ICD.Common.Properties;
using ICD.Common.Utils.Extensions;
namespace ICD.Common.Utils.EventArguments
{
public sealed class BoolEventArgs : GenericEventArgs<bool>
{
@@ -20,4 +24,18 @@
{
}
}
public static class BoolEventArgsExtensions
{
/// <summary>
/// Raises the event safely. Simply skips if the handler is null.
/// </summary>
/// <param name="extends"></param>
/// <param name="sender"></param>
/// <param name="data"></param>
public static void Raise([CanBeNull]this EventHandler<BoolEventArgs> extends, object sender, bool data)
{
extends.Raise(sender, new BoolEventArgs(data));
}
}
}

View File

@@ -1,4 +1,6 @@
using ICD.Common.Properties;
using System;
using ICD.Common.Properties;
using ICD.Common.Utils.Extensions;
namespace ICD.Common.Utils.EventArguments
{
@@ -9,4 +11,18 @@ namespace ICD.Common.Utils.EventArguments
{
}
}
public static class CharEventArgsExtensions
{
/// <summary>
/// Raises the event safely. Simply skips if the handler is null.
/// </summary>
/// <param name="extends"></param>
/// <param name="sender"></param>
/// <param name="data"></param>
public static void Raise([CanBeNull]this EventHandler<CharEventArgs> extends, object sender, char data)
{
extends.Raise(sender, new CharEventArgs(data));
}
}
}

View File

@@ -1,4 +1,6 @@
using System;
using ICD.Common.Properties;
using ICD.Common.Utils.Extensions;
namespace ICD.Common.Utils.EventArguments
{
@@ -13,4 +15,18 @@ namespace ICD.Common.Utils.EventArguments
{
}
}
public static class DateTimeEventArgsExtensions
{
/// <summary>
/// Raises the event safely. Simply skips if the handler is null.
/// </summary>
/// <param name="extends"></param>
/// <param name="sender"></param>
/// <param name="data"></param>
public static void Raise([CanBeNull]this EventHandler<DateTimeEventArgs> extends, object sender, DateTime data)
{
extends.Raise(sender, new DateTimeEventArgs(data));
}
}
}

View File

@@ -1,4 +1,6 @@
using System;
using ICD.Common.Properties;
using ICD.Common.Utils.Extensions;
namespace ICD.Common.Utils.EventArguments
{
@@ -12,4 +14,18 @@ namespace ICD.Common.Utils.EventArguments
{
}
}
public static class DateTimeNullableEventArgsExtensions
{
/// <summary>
/// Raises the event safely. Simply skips if the handler is null.
/// </summary>
/// <param name="extends"></param>
/// <param name="sender"></param>
/// <param name="data"></param>
public static void Raise([CanBeNull]this EventHandler<DateTimeNullableEventArgs> extends, object sender, DateTime? data)
{
extends.Raise(sender, new DateTimeNullableEventArgs(data));
}
}
}

View File

@@ -1,4 +1,8 @@
namespace ICD.Common.Utils.EventArguments
using System;
using ICD.Common.Properties;
using ICD.Common.Utils.Extensions;
namespace ICD.Common.Utils.EventArguments
{
public sealed class FloatEventArgs : GenericEventArgs<float>
{
@@ -11,4 +15,18 @@
{
}
}
public static class FloatEventArgsExtensions
{
/// <summary>
/// Raises the event safely. Simply skips if the handler is null.
/// </summary>
/// <param name="extends"></param>
/// <param name="sender"></param>
/// <param name="data"></param>
public static void Raise([CanBeNull]this EventHandler<FloatEventArgs> extends, object sender, float data)
{
extends.Raise(sender, new FloatEventArgs(data));
}
}
}

View File

@@ -1,4 +1,6 @@
using System;
using ICD.Common.Properties;
using ICD.Common.Utils.Extensions;
namespace ICD.Common.Utils.EventArguments
{
@@ -25,4 +27,18 @@ namespace ICD.Common.Utils.EventArguments
m_Data = data;
}
}
public static class GenericEventArgsExtensions
{
/// <summary>
/// Raises the event safely. Simply skips if the handler is null.
/// </summary>
/// <param name="extends"></param>
/// <param name="sender"></param>
/// <param name="data"></param>
public static void Raise<T>([CanBeNull]this EventHandler<GenericEventArgs<T>> extends, object sender, T data)
{
extends.Raise(sender, new GenericEventArgs<T>(data));
}
}
}

View File

@@ -1,4 +1,8 @@
namespace ICD.Common.Utils.EventArguments
using System;
using ICD.Common.Properties;
using ICD.Common.Utils.Extensions;
namespace ICD.Common.Utils.EventArguments
{
public sealed class IntEventArgs : GenericEventArgs<int>
{
@@ -10,4 +14,18 @@
{
}
}
public static class IntEventArgsExtensions
{
/// <summary>
/// Raises the event safely. Simply skips if the handler is null.
/// </summary>
/// <param name="extends"></param>
/// <param name="sender"></param>
/// <param name="data"></param>
public static void Raise([CanBeNull]this EventHandler<IntEventArgs> extends, object sender, int data)
{
extends.Raise(sender, new IntEventArgs(data));
}
}
}

View File

@@ -1,4 +1,8 @@
namespace ICD.Common.Utils.EventArguments
using System;
using ICD.Common.Properties;
using ICD.Common.Utils.Extensions;
namespace ICD.Common.Utils.EventArguments
{
public sealed class StringEventArgs : GenericEventArgs<string>
{
@@ -19,4 +23,18 @@
{
}
}
public static class StringEventArgsExtensions
{
/// <summary>
/// Raises the event safely. Simply skips if the handler is null.
/// </summary>
/// <param name="extends"></param>
/// <param name="sender"></param>
/// <param name="data"></param>
public static void Raise([CanBeNull]this EventHandler<StringEventArgs> extends, object sender, string data)
{
extends.Raise(sender, new StringEventArgs(data));
}
}
}

View File

@@ -1,4 +1,6 @@
using ICD.Common.Properties;
using System;
using ICD.Common.Properties;
using ICD.Common.Utils.Extensions;
namespace ICD.Common.Utils.EventArguments
{
@@ -13,4 +15,18 @@ namespace ICD.Common.Utils.EventArguments
{
}
}
public static class UShortEventArgsExtensions
{
/// <summary>
/// Raises the event safely. Simply skips if the handler is null.
/// </summary>
/// <param name="extends"></param>
/// <param name="sender"></param>
/// <param name="data"></param>
public static void Raise([CanBeNull]this EventHandler<UShortEventArgs> extends, object sender, ushort data)
{
extends.Raise(sender, new UShortEventArgs(data));
}
}
}

View File

@@ -1,5 +1,6 @@
using System;
using ICD.Common.Properties;
using ICD.Common.Utils.Extensions;
namespace ICD.Common.Utils.EventArguments
{
@@ -26,4 +27,19 @@ namespace ICD.Common.Utils.EventArguments
#endregion
}
public static class XmlRecursionEventArgsExtensions
{
/// <summary>
/// Raises the event safely. Simply skips if the handler is null.
/// </summary>
/// <param name="extends"></param>
/// <param name="sender"></param>
/// <param name="outer"></param>
/// <param name="path"></param>
public static void Raise([CanBeNull]this EventHandler<XmlRecursionEventArgs> extends, object sender, string outer, string[] path)
{
extends.Raise(sender, new XmlRecursionEventArgs(outer, path));
}
}
}