Created
November 20, 2019 10:05
-
-
Save mr5z/dd13deb16bb323434f963f7be291fc26 to your computer and use it in GitHub Desktop.
too long
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISourceEventArgs<out T> | |
{ | |
string EventName { get; } | |
EventSourceStatus Status { get; set; } | |
PreferredSourceType Type { get; set; } | |
DateTimeOffset Timestamp { get; } | |
T Data { get; } | |
bool IsSuccess { get; } | |
} | |
public class SourceEventArgs<T> : EventArgs, ISourceEventArgs<T> | |
{ | |
public SourceEventArgs(string eventName, EventSourceStatus status, T data, PreferredSourceType type) | |
{ | |
EventName = eventName; | |
Status = status; | |
Data = data; | |
Type = type; | |
Timestamp = DateTimeOffset.Now; | |
} | |
public SourceEventArgs(string eventName, EventSourceStatus status, T data, PreferredSourceType type, DateTimeOffset timestamp) | |
{ | |
EventName = eventName; | |
Status = status; | |
Data = data; | |
Type = type; | |
Timestamp = timestamp; | |
} | |
public override bool Equals(object obj) | |
{ | |
return obj is SourceEventArgs<T> other && other.GetHashCode() == GetHashCode(); | |
} | |
public override int GetHashCode() | |
{ | |
// taken from: https://stackoverflow.com/a/263416/2304737 | |
unchecked // Overflow is fine, just wrap | |
{ | |
int hash = (int)2166136261; | |
// Suitable nullity checks etc, of course :) | |
hash = (hash * 16777619) ^ EventName.GetHashCode(); | |
hash = (hash * 16777619) ^ Status.GetHashCode(); | |
hash = (hash * 16777619) ^ Data.GetHashCode(); | |
hash = (hash * 16777619) ^ Type.GetHashCode(); | |
return hash; | |
} | |
} | |
public string EventName { get; } | |
public EventSourceStatus Status { get; set; } | |
public PreferredSourceType Type { get; set; } | |
public DateTimeOffset Timestamp { get; } | |
public T Data { get; } | |
public bool IsSuccess => Status == EventSourceStatus.Success; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment