Skip to content
This repository was archived by the owner on Dec 18, 2023. It is now read-only.

Commit 154e9aa

Browse files
committed
fixed notify message controls and add some helpers
1 parent 53f2824 commit 154e9aa

26 files changed

+928
-488
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Description:ConfigurationManageHelper
3+
* Author: Chance.Zheng
4+
* Create Time: 2023-02-23 11:23:06
5+
* .Net Version: 4.6
6+
* CLR Version: 4.0.30319.42000
7+
* Copyright (c) CookCSharp 2023 All Rights Reserved.
8+
*/
9+
10+
11+
using System;
12+
using System.Collections.Generic;
13+
using System.Configuration;
14+
using System.Linq;
15+
using System.Text;
16+
using System.Threading.Tasks;
17+
18+
19+
namespace CookPopularCSharpToolkit.Communal
20+
{
21+
public class ConfigurationManageHelper
22+
{
23+
public static void AddItem(string key, string value, string sectionName = "appSettings")
24+
{
25+
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
26+
configuration.AppSettings.Settings.Add(key, value);
27+
configuration.Save(ConfigurationSaveMode.Modified);
28+
ConfigurationManager.RefreshSection(sectionName);
29+
}
30+
31+
public static void DeleteItem(string key, string sectionName = "appSettings")
32+
{
33+
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
34+
configuration.AppSettings.Settings.Remove(key);
35+
configuration.Save(ConfigurationSaveMode.Modified);
36+
ConfigurationManager.RefreshSection(sectionName);
37+
}
38+
39+
public static void ModifyItem(string key, string value, string sectionName = "appSettings")
40+
{
41+
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
42+
configuration.AppSettings.Settings[key].Value = value;
43+
configuration.Save(ConfigurationSaveMode.Modified);
44+
ConfigurationManager.RefreshSection(sectionName);
45+
}
46+
47+
public static string ReadItem(string key)
48+
{
49+
return ConfigurationManager.AppSettings.Get(key);
50+
}
51+
}
52+
}

CookPopularCSharpToolkit/Communal/Helpers/ObjectCreateHelper.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Reflection;
33
using System.Reflection.Emit;
4+
using System.Windows.Media;
45

56

67

@@ -51,6 +52,19 @@ public static TObject CreateInstanceInIL<TObject>()
5152
}
5253
}
5354

55+
/// <summary>
56+
/// <see cref="Activator"/>创建对象
57+
/// </summary>
58+
/// <param name="typeName">类的完全限定名(即包括命名空间),格式为:命名空间.类名</param>
59+
/// <returns></returns>
60+
public static object CreateInstanceInActivator(string typeName)
61+
{
62+
var type = Type.GetType(typeName);
63+
var instance = type == null ? null : Activator.CreateInstance(type);
64+
65+
return instance;
66+
}
67+
5468
/// <summary>
5569
/// <see cref="Activator"/>创建对象
5670
/// </summary>
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
/*
2+
* Description:VerifyHelper
3+
* Author: Chance.Zheng
4+
* Create Time: 2023-03-07 15:11:57
5+
* .Net Version: 4.6
6+
* CLR Version: 4.0.30319.42000
7+
* Copyright (c) CookCSharp 2023 All Rights Reserved.
8+
*/
9+
10+
11+
using System;
12+
using System.Collections.Generic;
13+
using System.Diagnostics;
14+
using System.Globalization;
15+
using System.IO;
16+
using System.Linq;
17+
using System.Text;
18+
using System.Threading;
19+
using System.Threading.Tasks;
20+
21+
22+
namespace CookPopularCSharpToolkit.Communal
23+
{
24+
public static class VerifyHelper
25+
{
26+
[DebuggerStepThrough]
27+
public static void IsApartmentState(ApartmentState requiredState, string message)
28+
{
29+
if (Thread.CurrentThread.GetApartmentState() != requiredState)
30+
{
31+
throw new InvalidOperationException(message);
32+
}
33+
}
34+
35+
[DebuggerStepThrough]
36+
public static void IsNeitherNullNorEmpty(string value, string name)
37+
{
38+
if (value == null)
39+
{
40+
throw new ArgumentNullException(name, "The parameter can not be either null or empty.");
41+
}
42+
43+
if ("" == value)
44+
{
45+
throw new ArgumentException("The parameter can not be either null or empty.", name);
46+
}
47+
}
48+
49+
[DebuggerStepThrough]
50+
public static void IsNeitherNullNorWhitespace(string value, string name)
51+
{
52+
if (value == null)
53+
{
54+
throw new ArgumentNullException(name, "The parameter can not be either null or empty or consist only of white space characters.");
55+
}
56+
57+
if ("" == value.Trim())
58+
{
59+
throw new ArgumentException("The parameter can not be either null or empty or consist only of white space characters.", name);
60+
}
61+
}
62+
63+
[DebuggerStepThrough]
64+
public static void IsNotDefault<T>(T obj, string name) where T : struct
65+
{
66+
if (default(T).Equals(obj))
67+
{
68+
throw new ArgumentException("The parameter must not be the default value.", name);
69+
}
70+
}
71+
72+
[DebuggerStepThrough]
73+
public static void IsNotNull<T>(T obj, string name) where T : class
74+
{
75+
if (obj == null)
76+
{
77+
throw new ArgumentNullException(name);
78+
}
79+
}
80+
81+
[DebuggerStepThrough]
82+
public static void IsNull<T>(T obj, string name) where T : class
83+
{
84+
if (obj != null)
85+
{
86+
throw new ArgumentException("The parameter must be null.", name);
87+
}
88+
}
89+
90+
[DebuggerStepThrough]
91+
public static void PropertyIsNotNull<T>(T obj, string name) where T : class
92+
{
93+
if (obj == null)
94+
{
95+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The property {0} cannot be null at this time.", new object[1] { name }));
96+
}
97+
}
98+
99+
[DebuggerStepThrough]
100+
public static void PropertyIsNull<T>(T obj, string name) where T : class
101+
{
102+
if (obj != null)
103+
{
104+
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The property {0} must be null at this time.", new object[1] { name }));
105+
}
106+
}
107+
108+
[DebuggerStepThrough]
109+
public static void IsTrue(bool statement, string name)
110+
{
111+
if (!statement)
112+
{
113+
throw new ArgumentException("", name);
114+
}
115+
}
116+
117+
[DebuggerStepThrough]
118+
public static void IsTrue(bool statement, string name, string message)
119+
{
120+
if (!statement)
121+
{
122+
throw new ArgumentException(message, name);
123+
}
124+
}
125+
126+
[DebuggerStepThrough]
127+
public static void AreEqual<T>(T expected, T actual, string parameterName, string message)
128+
{
129+
if (expected == null)
130+
{
131+
if (actual != null && !actual.Equals(expected))
132+
{
133+
throw new ArgumentException(message, parameterName);
134+
}
135+
}
136+
else if (!expected.Equals(actual))
137+
{
138+
throw new ArgumentException(message, parameterName);
139+
}
140+
}
141+
142+
[DebuggerStepThrough]
143+
public static void AreNotEqual<T>(T notExpected, T actual, string parameterName, string message)
144+
{
145+
if (notExpected == null)
146+
{
147+
if (actual == null || actual.Equals(notExpected))
148+
{
149+
throw new ArgumentException(message, parameterName);
150+
}
151+
}
152+
else if (notExpected.Equals(actual))
153+
{
154+
throw new ArgumentException(message, parameterName);
155+
}
156+
}
157+
158+
[DebuggerStepThrough]
159+
public static void UriIsAbsolute(Uri uri, string parameterName)
160+
{
161+
IsNotNull(uri, parameterName);
162+
if (!uri.IsAbsoluteUri)
163+
{
164+
throw new ArgumentException("The URI must be absolute.", parameterName);
165+
}
166+
}
167+
168+
[DebuggerStepThrough]
169+
public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive, string parameterName)
170+
{
171+
if (value < lowerBoundInclusive || value >= upperBoundExclusive)
172+
{
173+
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The integer value must be bounded with [{0}, {1})", new object[2] { lowerBoundInclusive, upperBoundExclusive }), parameterName);
174+
}
175+
}
176+
177+
[DebuggerStepThrough]
178+
public static void BoundedDoubleInc(double lowerBoundInclusive, double value, double upperBoundInclusive, string message, string parameter)
179+
{
180+
if (value < lowerBoundInclusive || value > upperBoundInclusive)
181+
{
182+
throw new ArgumentException(message, parameter);
183+
}
184+
}
185+
186+
[DebuggerStepThrough]
187+
public static void TypeSupportsInterface(Type type, Type interfaceType, string parameterName)
188+
{
189+
IsNotNull(type, "type");
190+
IsNotNull(interfaceType, "interfaceType");
191+
if (type.GetInterface(interfaceType.Name) == null)
192+
{
193+
throw new ArgumentException("The type of this parameter does not support a required interface", parameterName);
194+
}
195+
}
196+
197+
[DebuggerStepThrough]
198+
public static void FileExists(string filePath, string parameterName)
199+
{
200+
IsNeitherNullNorEmpty(filePath, parameterName);
201+
if (!File.Exists(filePath))
202+
{
203+
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "No file exists at \"{0}\"", new object[1] { filePath }), parameterName);
204+
}
205+
}
206+
207+
[DebuggerStepThrough]
208+
internal static void ImplementsInterface(object parameter, Type interfaceType, string parameterName)
209+
{
210+
bool flag = false;
211+
Type[] interfaces = parameter.GetType().GetInterfaces();
212+
foreach (Type type in interfaces)
213+
{
214+
if (type == interfaceType)
215+
{
216+
flag = true;
217+
break;
218+
}
219+
}
220+
221+
if (!flag)
222+
{
223+
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The parameter must implement interface {0}.", new object[1] { interfaceType.ToString() }), parameterName);
224+
}
225+
}
226+
}
227+
}

CookPopularCSharpToolkit/Windows/Converters/ToBooleanConverters.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using CookPopularCSharpToolkit.Communal;
22
using System;
3+
using System.ComponentModel;
34
using System.Globalization;
45
using System.Windows;
56
using System.Windows.Data;
67
using System.Windows.Markup;
8+
using System.Windows.Media;
79

810

911

CookPopularCSharpToolkit/Windows/Extensions/WindowExtension.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ public static void RemoveIcon(this Window window)
171171

172172
//改变窗体的样式
173173
int extendedStyle = NativeMethods.GetWindowLong(hwnd, NativeMethods.GWL_EXSTYLE);
174-
CookPopularCSharpToolkit.Windows.Interop.NativeMethods.SetWindowLong(hwnd, NativeMethods.GWL_EXSTYLE, extendedStyle | NativeMethods.WS_EX_DLGMODALFRAME);
174+
Interop.NativeMethods.SetWindowLong(hwnd, NativeMethods.GWL_EXSTYLE, extendedStyle | NativeMethods.WS_EX_DLGMODALFRAME);
175175

176176
//更新窗口的非客户区,以反映变化
177-
CookPopularCSharpToolkit.Windows.Interop.NativeMethods.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, CookPopularCSharpToolkit.Windows.Interop.NativeMethods.SWP.NOMOVE |
178-
CookPopularCSharpToolkit.Windows.Interop.NativeMethods.SWP.NOSIZE | CookPopularCSharpToolkit.Windows.Interop.NativeMethods.SWP.NOZORDER | CookPopularCSharpToolkit.Windows.Interop.NativeMethods.SWP.FRAMECHANGED);
177+
Interop.NativeMethods.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, Interop.NativeMethods.SWP.NOMOVE |
178+
Interop.NativeMethods.SWP.NOSIZE | Interop.NativeMethods.SWP.NOZORDER | Interop.NativeMethods.SWP.FRAMECHANGED);
179179
}
180180

181181
/// <summary>

CookPopularCSharpToolkit/Windows/TaskWithThread/SynchronizationWithAsync.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace CookPopularCSharpToolkit.Windows
1919
/// <remarks><see cref="Dispatcher"/>与<see cref="SynchronizationContext"/></remarks>
2020
public sealed class SynchronizationWithAsync
2121
{
22-
public static void AppInvokeAsync(Action action)
22+
public static DispatcherOperation AppInvokeAsync(Action action)
2323
{
24-
Application.Current.Dispatcher.InvokeAsync(action, DispatcherPriority.Normal);
24+
return Application.Current.Dispatcher.InvokeAsync(action, DispatcherPriority.Normal);
2525
}
2626

2727
public static void AppInvoke(Action action)

CookPopularControl/Communal/Attached/WindowAttached.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private static void OnShowInTaskManagerChanged(DependencyObject d, DependencyPro
9696
}
9797
}
9898

99-
private static void Window_SourceInitialized(object sender, EventArgs e)
99+
private static void Window_SourceInitialized(object? sender, EventArgs e)
100100
{
101101
if (sender is System.Windows.Window window)
102102
{

CookPopularControl/Communal/Data/Enum/PopupAnimationX.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)