Merge branch 'master' of https://gitlab.com/Pilzinsel64/pilz-framework
This commit is contained in:
16
Pilz.Cryptography/IUniquieID.cs
Normal file
16
Pilz.Cryptography/IUniquieID.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Pilz.Cryptography
|
||||
{
|
||||
public interface IUniquieID
|
||||
{
|
||||
bool HasID { get; }
|
||||
string ID { get; }
|
||||
|
||||
void GenerateIfNull();
|
||||
void Generate();
|
||||
bool Equals(object obj);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Cryptography
|
||||
{
|
||||
public class UniquieID<TargetType>
|
||||
public class UniquieID<TargetType> : IUniquieID
|
||||
{
|
||||
private static int currentSimpleID = 0;
|
||||
|
||||
@@ -90,9 +90,36 @@ namespace Pilz.Cryptography
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var res = false;
|
||||
var iD = obj as UniquieID<TargetType>;
|
||||
return iD != null &&
|
||||
_iD == iD._iD;
|
||||
|
||||
if (iD is object)
|
||||
{
|
||||
if (ReferenceEquals(res, iD))
|
||||
res = true;
|
||||
else
|
||||
{
|
||||
var leftHasID = iD.HasID;
|
||||
var rightHasID = HasID;
|
||||
|
||||
if (!leftHasID && iD.GenerateOnGet)
|
||||
{
|
||||
iD.Generate();
|
||||
leftHasID = iD.HasID;
|
||||
}
|
||||
|
||||
if (!rightHasID && GenerateOnGet)
|
||||
{
|
||||
Generate();
|
||||
rightHasID = HasID;
|
||||
}
|
||||
|
||||
if (leftHasID && rightHasID)
|
||||
res = _iD.Equals(iD._iD);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
@@ -104,7 +131,7 @@ namespace Pilz.Cryptography
|
||||
public static implicit operator UniquieID<TargetType>(string id) => new UniquieID<TargetType>() { ID = id };
|
||||
public static implicit operator UniquieID<TargetType>(int id) => new UniquieID<TargetType>() { ID = Convert.ToString(id) };
|
||||
|
||||
public static bool operator ==(UniquieID<TargetType> left, UniquieID<TargetType> right) => left.ID == right.ID;
|
||||
public static bool operator !=(UniquieID<TargetType> left, UniquieID<TargetType> right) => left.ID != right.ID;
|
||||
public static bool operator ==(UniquieID<TargetType> left, UniquieID<TargetType> right) => left.ID.Equals(right.ID);
|
||||
public static bool operator !=(UniquieID<TargetType> left, UniquieID<TargetType> right) => !left.ID.Equals(right.ID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Imports System.Runtime.CompilerServices
|
||||
Imports System.Runtime.CompilerServices
|
||||
Imports System.Windows.Forms
|
||||
|
||||
Namespace Utils
|
||||
@@ -6,10 +6,19 @@ Namespace Utils
|
||||
Public Module DrawingControl
|
||||
|
||||
Private Const WM_SETREDRAW = 11
|
||||
Private ReadOnly dicSuspendCount As New Dictionary(Of IntPtr, Integer)
|
||||
|
||||
<Extension>
|
||||
Public Sub SuspendDrawing(control As Control)
|
||||
SendMessage(control.Handle, WM_SETREDRAW, False, 0)
|
||||
If Not dicSuspendCount.ContainsKey(control.Handle) Then
|
||||
dicSuspendCount.Add(control.Handle, 1)
|
||||
Else
|
||||
dicSuspendCount(control.Handle) += 1
|
||||
End If
|
||||
|
||||
If dicSuspendCount(control.Handle) = 1 Then
|
||||
SendMessage(control.Handle, WM_SETREDRAW, False, 0)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
<Extension>
|
||||
@@ -19,8 +28,19 @@ Namespace Utils
|
||||
|
||||
<Extension>
|
||||
Public Sub ResumeDrawing(control As Control, redraw As Boolean)
|
||||
SendMessage(control.Handle, WM_SETREDRAW, True, 0)
|
||||
If redraw Then control.Refresh()
|
||||
Dim doRedraw As Boolean = True
|
||||
|
||||
If dicSuspendCount.ContainsKey(control.Handle) Then
|
||||
dicSuspendCount(control.Handle) -= 1
|
||||
If dicSuspendCount(control.Handle) >= 1 Then
|
||||
doRedraw = False
|
||||
End If
|
||||
End If
|
||||
|
||||
If doRedraw Then
|
||||
SendMessage(control.Handle, WM_SETREDRAW, True, 0)
|
||||
If redraw Then control.Refresh()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
|
||||
Reference in New Issue
Block a user