chore: use file-scoped namespace
This commit is contained in:
1 parent
99d2fafb72
commit
bbf1b7d4c6
748 files changed
+57929
-58678
No files matched your search
@@ -5,29 +5,28 @@ using System.Windows.Media;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace HandyControlDemo.Tools.Converter
|
||||
namespace HandyControlDemo.Tools.Converter;
|
||||
|
||||
public class HatchBrushConverter : IValueConverter
|
||||
{
|
||||
public class HatchBrushConverter : IValueConverter
|
||||
private readonly HatchBrushGenerator _brushGenerator;
|
||||
|
||||
public HatchBrushConverter()
|
||||
{
|
||||
private readonly HatchBrushGenerator _brushGenerator;
|
||||
|
||||
public HatchBrushConverter()
|
||||
{
|
||||
_brushGenerator = new HatchBrushGenerator();
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is HatchStyle style)
|
||||
{
|
||||
return _brushGenerator.GetHatchBrush(style, ResourceHelper.GetResource<Color>(ResourceToken.DarkPrimaryColor), Colors.Transparent);
|
||||
}
|
||||
return Brushes.Transparent;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
_brushGenerator = new HatchBrushGenerator();
|
||||
}
|
||||
}
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is HatchStyle style)
|
||||
{
|
||||
return _brushGenerator.GetHatchBrush(style, ResourceHelper.GetResource<Color>(ResourceToken.DarkPrimaryColor), Colors.Transparent);
|
||||
}
|
||||
return Brushes.Transparent;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -4,18 +4,17 @@ using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace HandyControlDemo.Tools.Converter
|
||||
{
|
||||
public class String2BrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value is string str ? ResourceHelper.GetResource<Brush>(str) : default;
|
||||
}
|
||||
namespace HandyControlDemo.Tools.Converter;
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
public class String2BrushConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value is string str ? ResourceHelper.GetResource<Brush>(str) : default;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -3,43 +3,42 @@ using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace HandyControlDemo.Tools.Converter
|
||||
namespace HandyControlDemo.Tools.Converter;
|
||||
|
||||
public class StringRepeatConverter : IValueConverter
|
||||
{
|
||||
public class StringRepeatConverter : IValueConverter
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
if (value is string strValue)
|
||||
{
|
||||
if (value is string strValue)
|
||||
var builder = new StringBuilder();
|
||||
int num;
|
||||
if (parameter is string numStr)
|
||||
{
|
||||
var builder = new StringBuilder();
|
||||
int num;
|
||||
if (parameter is string numStr)
|
||||
{
|
||||
if (!int.TryParse(numStr, out num))
|
||||
{
|
||||
return strValue;
|
||||
}
|
||||
}
|
||||
else if (parameter is int intValue)
|
||||
{
|
||||
num = intValue;
|
||||
}
|
||||
else
|
||||
if (!int.TryParse(numStr, out num))
|
||||
{
|
||||
return strValue;
|
||||
}
|
||||
for (var i = 0; i < num; i++)
|
||||
{
|
||||
builder.Append(strValue);
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
else if (parameter is int intValue)
|
||||
{
|
||||
num = intValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return strValue;
|
||||
}
|
||||
for (var i = 0; i < num; i++)
|
||||
{
|
||||
builder.Append(strValue);
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
using HandyControlDemo.Properties.Langs;
|
||||
|
||||
namespace HandyControlDemo.Tools.Extension
|
||||
namespace HandyControlDemo.Tools.Extension;
|
||||
|
||||
public class LangExtension : HandyControl.Tools.Extension.LangExtension
|
||||
{
|
||||
public class LangExtension : HandyControl.Tools.Extension.LangExtension
|
||||
public LangExtension()
|
||||
{
|
||||
public LangExtension()
|
||||
{
|
||||
Source = LangProvider.Instance;
|
||||
}
|
||||
Source = LangProvider.Instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HandyControlDemo.Tools
|
||||
namespace HandyControlDemo.Tools;
|
||||
|
||||
internal class AssemblyHelper
|
||||
{
|
||||
internal class AssemblyHelper
|
||||
private static readonly string NameSpaceStr = typeof(AssemblyHelper).Assembly.GetName().Name;
|
||||
|
||||
private static readonly Dictionary<string, object> CacheDic = new();
|
||||
|
||||
public static void Register(string name, object instance) => CacheDic[name] = instance;
|
||||
|
||||
public static object ResolveByKey(string key)
|
||||
{
|
||||
private static readonly string NameSpaceStr = typeof(AssemblyHelper).Assembly.GetName().Name;
|
||||
|
||||
private static readonly Dictionary<string, object> CacheDic = new();
|
||||
|
||||
public static void Register(string name, object instance) => CacheDic[name] = instance;
|
||||
|
||||
public static object ResolveByKey(string key)
|
||||
if (CacheDic.TryGetValue(key, out var value))
|
||||
{
|
||||
if (CacheDic.TryGetValue(key, out var value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static object CreateInternalInstance(string className)
|
||||
{
|
||||
try
|
||||
{
|
||||
var type = Type.GetType($"{NameSpaceStr}.{className}");
|
||||
return type == null ? null : Activator.CreateInstance(type);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public static object CreateInternalInstance(string className)
|
||||
{
|
||||
try
|
||||
{
|
||||
var type = Type.GetType($"{NameSpaceStr}.{className}");
|
||||
return type == null ? null : Activator.CreateInstance(type);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace HandyControlDemo.Tools
|
||||
namespace HandyControlDemo.Tools;
|
||||
|
||||
internal class VersionHelper
|
||||
{
|
||||
internal class VersionHelper
|
||||
internal static string GetVersion()
|
||||
{
|
||||
internal static string GetVersion()
|
||||
{
|
||||
var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);
|
||||
var versionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);
|
||||
#if NET40
|
||||
var netVersion = "NET 40";
|
||||
var netVersion = "NET 40";
|
||||
#elif NET45
|
||||
var netVersion = "NET 45";
|
||||
#elif NET451
|
||||
@@ -39,10 +39,9 @@ namespace HandyControlDemo.Tools
|
||||
#elif NETCOREAPP3_1
|
||||
var netVersion = "CORE 31";
|
||||
#endif
|
||||
return $"v {versionInfo.FileVersion} {netVersion}";
|
||||
}
|
||||
|
||||
internal static string GetCopyright() =>
|
||||
FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).LegalCopyright;
|
||||
return $"v {versionInfo.FileVersion} {netVersion}";
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetCopyright() =>
|
||||
FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location).LegalCopyright;
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace HandyControlDemo.Tools
|
||||
{
|
||||
internal class Win32Helper
|
||||
{
|
||||
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
namespace HandyControlDemo.Tools;
|
||||
|
||||
[DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
|
||||
public static extern int MciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
|
||||
}
|
||||
}
|
||||
internal class Win32Helper
|
||||
{
|
||||
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
|
||||
public static extern int MciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
|
||||
}
|
||||
@@ -6,75 +6,74 @@ using HandyControl.Data;
|
||||
using ICSharpCode.AvalonEdit.Highlighting;
|
||||
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
|
||||
|
||||
namespace HandyControlDemo.Tools
|
||||
namespace HandyControlDemo.Tools;
|
||||
|
||||
internal class HighlightingProvider
|
||||
{
|
||||
internal class HighlightingProvider
|
||||
public static HighlightingProvider Default = new Lazy<HighlightingProvider>(() => new HighlightingProvider()).Value;
|
||||
|
||||
protected static readonly Lazy<IHighlightingDefinition> DefaultDefinition = new(() => HighlightingManager.Instance.GetDefinition("C#"));
|
||||
|
||||
private static readonly Dictionary<SkinType, HighlightingProvider> Providers = new();
|
||||
|
||||
protected Dictionary<string, Lazy<IHighlightingDefinition>> Definition;
|
||||
|
||||
public static void Register(SkinType skinType, HighlightingProvider provider)
|
||||
{
|
||||
public static HighlightingProvider Default = new Lazy<HighlightingProvider>(() => new HighlightingProvider()).Value;
|
||||
|
||||
protected static readonly Lazy<IHighlightingDefinition> DefaultDefinition = new(() => HighlightingManager.Instance.GetDefinition("C#"));
|
||||
|
||||
private static readonly Dictionary<SkinType, HighlightingProvider> Providers = new();
|
||||
|
||||
protected Dictionary<string, Lazy<IHighlightingDefinition>> Definition;
|
||||
|
||||
public static void Register(SkinType skinType, HighlightingProvider provider)
|
||||
{
|
||||
Providers[skinType] = provider ?? throw new ArgumentNullException(nameof(provider));
|
||||
provider.InitDefinitions();
|
||||
}
|
||||
|
||||
public static IHighlightingDefinition GetDefinition(SkinType skinType, string name)
|
||||
{
|
||||
if (Providers.TryGetValue(skinType, out var provider))
|
||||
{
|
||||
return provider.GetDefinition(name);
|
||||
}
|
||||
|
||||
return DefaultDefinition.Value;
|
||||
}
|
||||
|
||||
protected static IHighlightingDefinition LoadDefinition(string xshdName)
|
||||
{
|
||||
var streamResourceInfo = Application.GetResourceStream(new Uri($"pack://application:,,,/Resources/xshd/{xshdName}.xshd"));
|
||||
if (streamResourceInfo == null)
|
||||
{
|
||||
return DefaultDefinition.Value;
|
||||
}
|
||||
|
||||
using var reader = new XmlTextReader(streamResourceInfo.Stream);
|
||||
return HighlightingLoader.Load(reader, HighlightingManager.Instance);
|
||||
}
|
||||
|
||||
protected virtual IHighlightingDefinition GetDefinition(string name)
|
||||
{
|
||||
if (Definition.TryGetValue(name, out var definition))
|
||||
{
|
||||
return definition.Value;
|
||||
}
|
||||
|
||||
return DefaultDefinition.Value;
|
||||
}
|
||||
|
||||
protected virtual void InitDefinitions()
|
||||
{
|
||||
Definition = new Dictionary<string, Lazy<IHighlightingDefinition>>
|
||||
{
|
||||
["XML"] = new(() => HighlightingManager.Instance.GetDefinition("XML")),
|
||||
["C#"] = new(() => DefaultDefinition.Value)
|
||||
};
|
||||
}
|
||||
Providers[skinType] = provider ?? throw new ArgumentNullException(nameof(provider));
|
||||
provider.InitDefinitions();
|
||||
}
|
||||
|
||||
internal class HighlightingProviderDark : HighlightingProvider
|
||||
public static IHighlightingDefinition GetDefinition(SkinType skinType, string name)
|
||||
{
|
||||
protected override void InitDefinitions()
|
||||
if (Providers.TryGetValue(skinType, out var provider))
|
||||
{
|
||||
Definition = new Dictionary<string, Lazy<IHighlightingDefinition>>
|
||||
{
|
||||
["XML"] = new(() => LoadDefinition("XML-Dark")),
|
||||
["C#"] = new(() => LoadDefinition("CSharp-Dark")),
|
||||
};
|
||||
return provider.GetDefinition(name);
|
||||
}
|
||||
|
||||
return DefaultDefinition.Value;
|
||||
}
|
||||
|
||||
protected static IHighlightingDefinition LoadDefinition(string xshdName)
|
||||
{
|
||||
var streamResourceInfo = Application.GetResourceStream(new Uri($"pack://application:,,,/Resources/xshd/{xshdName}.xshd"));
|
||||
if (streamResourceInfo == null)
|
||||
{
|
||||
return DefaultDefinition.Value;
|
||||
}
|
||||
|
||||
using var reader = new XmlTextReader(streamResourceInfo.Stream);
|
||||
return HighlightingLoader.Load(reader, HighlightingManager.Instance);
|
||||
}
|
||||
|
||||
protected virtual IHighlightingDefinition GetDefinition(string name)
|
||||
{
|
||||
if (Definition.TryGetValue(name, out var definition))
|
||||
{
|
||||
return definition.Value;
|
||||
}
|
||||
|
||||
return DefaultDefinition.Value;
|
||||
}
|
||||
|
||||
protected virtual void InitDefinitions()
|
||||
{
|
||||
Definition = new Dictionary<string, Lazy<IHighlightingDefinition>>
|
||||
{
|
||||
["XML"] = new(() => HighlightingManager.Instance.GetDefinition("XML")),
|
||||
["C#"] = new(() => DefaultDefinition.Value)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
internal class HighlightingProviderDark : HighlightingProvider
|
||||
{
|
||||
protected override void InitDefinitions()
|
||||
{
|
||||
Definition = new Dictionary<string, Lazy<IHighlightingDefinition>>
|
||||
{
|
||||
["XML"] = new(() => LoadDefinition("XML-Dark")),
|
||||
["C#"] = new(() => LoadDefinition("CSharp-Dark")),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user