diff --git a/Bin/net40/SunnyUI.Demo.exe b/Bin/net40/SunnyUI.Demo.exe index dd5343bf..dd60f7dc 100644 Binary files a/Bin/net40/SunnyUI.Demo.exe and b/Bin/net40/SunnyUI.Demo.exe differ diff --git a/Bin/net40/SunnyUI.dll b/Bin/net40/SunnyUI.dll index c589e7ed..1bc9dd2a 100644 Binary files a/Bin/net40/SunnyUI.dll and b/Bin/net40/SunnyUI.dll differ diff --git a/SunnyUI.Demo/Controls/FButton.Designer.cs b/SunnyUI.Demo/Controls/FButton.Designer.cs index ceb6e266..1cc712d1 100644 --- a/SunnyUI.Demo/Controls/FButton.Designer.cs +++ b/SunnyUI.Demo/Controls/FButton.Designer.cs @@ -162,8 +162,9 @@ namespace Sunny.UI.Demo this.uiSymbolButton25.StyleCustomMode = true; this.uiSymbolButton25.Symbol = 61453; this.uiSymbolButton25.TabIndex = 112; - this.uiSymbolButton25.Text = "Link"; + this.uiSymbolButton25.Text = "类库"; this.uiSymbolButton25.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.uiSymbolButton25.Click += new System.EventHandler(this.uiSymbolButton25_Click); // // uiImageButton4 // @@ -426,7 +427,6 @@ namespace Sunny.UI.Demo // uiSymbolButton18 // this.uiSymbolButton18.Cursor = System.Windows.Forms.Cursors.Hand; - this.uiSymbolButton18.Enabled = false; this.uiSymbolButton18.Font = new System.Drawing.Font("微软雅黑", 12F); this.uiSymbolButton18.Location = new System.Drawing.Point(30, 395); this.uiSymbolButton18.MinimumSize = new System.Drawing.Size(1, 1); diff --git a/SunnyUI.Demo/Controls/FButton.cs b/SunnyUI.Demo/Controls/FButton.cs index a8b5fb7c..75a8bc77 100644 --- a/SunnyUI.Demo/Controls/FButton.cs +++ b/SunnyUI.Demo/Controls/FButton.cs @@ -57,5 +57,10 @@ namespace Sunny.UI.Demo { Console.WriteLine(uiSwitch1.Active); } + + private void uiSymbolButton25_Click(object sender, EventArgs e) + { + Frame.SelectPage(5000); + } } } diff --git a/SunnyUI.Demo/FMain.cs b/SunnyUI.Demo/FMain.cs index b6ccfb9f..94906fd9 100644 --- a/SunnyUI.Demo/FMain.cs +++ b/SunnyUI.Demo/FMain.cs @@ -80,6 +80,8 @@ namespace Sunny.UI.Demo //直接增加一个页面,不在左侧列表显示 AddPage(new FColorful()); + AddPage(new FCommon()); + //选中第一个节点 Aside.SelectPage(1002); } diff --git a/SunnyUI.Demo/SunnyUI.Demo.csproj b/SunnyUI.Demo/SunnyUI.Demo.csproj index 81cf26c1..f6bdbd82 100644 --- a/SunnyUI.Demo/SunnyUI.Demo.csproj +++ b/SunnyUI.Demo/SunnyUI.Demo.csproj @@ -361,6 +361,13 @@ FColorful.cs + + Form + + + FCommon.cs + + FBarChartEx.cs @@ -521,6 +528,9 @@ FColorful.cs + + FCommon.cs + .editorconfig diff --git a/SunnyUI.Demo/Units/FCommon.Designer.cs b/SunnyUI.Demo/Units/FCommon.Designer.cs new file mode 100644 index 00000000..8c024a95 --- /dev/null +++ b/SunnyUI.Demo/Units/FCommon.Designer.cs @@ -0,0 +1,68 @@ + +namespace Sunny.UI.Demo +{ + partial class FCommon + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.uiButton1 = new Sunny.UI.UIButton(); + this.SuspendLayout(); + // + // uiButton1 + // + this.uiButton1.Cursor = System.Windows.Forms.Cursors.Hand; + this.uiButton1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.uiButton1.Location = new System.Drawing.Point(30, 60); + this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1); + this.uiButton1.Name = "uiButton1"; + this.uiButton1.Size = new System.Drawing.Size(100, 35); + this.uiButton1.TabIndex = 0; + this.uiButton1.Text = "Mapper"; + this.uiButton1.Click += new System.EventHandler(this.uiButton1_Click); + // + // FCommon + // + this.AllowShowTitle = true; + this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.uiButton1); + this.Name = "FCommon"; + this.Padding = new System.Windows.Forms.Padding(0, 35, 0, 0); + this.PageIndex = 5000; + this.ShowTitle = true; + this.Symbol = 62098; + this.Text = "类库"; + this.ResumeLayout(false); + + } + + #endregion + + private UIButton uiButton1; + } +} \ No newline at end of file diff --git a/SunnyUI.Demo/Units/FCommon.cs b/SunnyUI.Demo/Units/FCommon.cs new file mode 100644 index 00000000..4e1acd13 --- /dev/null +++ b/SunnyUI.Demo/Units/FCommon.cs @@ -0,0 +1,15 @@ +namespace Sunny.UI.Demo +{ + public partial class FCommon : UIPage + { + public FCommon() + { + InitializeComponent(); + } + + private void uiButton1_Click(object sender, System.EventArgs e) + { + MapperDemo.Demo(); + } + } +} diff --git a/SunnyUI.Demo/Units/FCommon.resx b/SunnyUI.Demo/Units/FCommon.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/SunnyUI.Demo/Units/FCommon.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SunnyUI.Demo/Units/UMapperDemo.cs b/SunnyUI.Demo/Units/UMapperDemo.cs new file mode 100644 index 00000000..63c1bfb2 --- /dev/null +++ b/SunnyUI.Demo/Units/UMapperDemo.cs @@ -0,0 +1,98 @@ +using Sunny.UI.Static; +using System; +using System.Collections.Generic; +using System.Drawing; + +namespace Sunny.UI.Demo +{ + public static class MapperDemo + { + public static void Demo() + { + MapperT1 t1 = new MapperT1(); + t1.A = "Hello world."; + t1.B = 1024; + t1.C = 768; + t1.D = DateTime.Now; + t1.E = new Point(100, 200); + t1.F = new MapperT3("Struct String", '\n', new MapperT4("I am T4")); + t1.G = new Size(100, 200); + t1.H = new List() { "AA", "BB" }; + t1.I = new string[2] { "AA", "BB" }; + + MapperT2 t2 = new MapperT2(); + t2.MapperFrom(t1); + t2.WriteConsole(); + } + } + + public class MapperT1 + { + public string A { get; set; } + + public int B { get; set; } + + public double C { get; set; } + + public DateTime D { get; set; } + + public Point E { get; set; } + + public MapperT3 F { get; set; } + + public Size G { get; set; } + + public List H { get; set; } + + public string[] I { get; set; } + } + + public class MapperT2 + { + public string A { get; set; } + + public int B { get; set; } + + public double C { get; set; } + + public DateTime D { get; set; } + + public Point E { get; set; } + + public MapperT3 F { get; set; } + + public List H { get; set; } + + public string[] I { get; set; } + } + + public struct MapperT3 + { + public string String { get; set; } + public char Char { get; set; } + + public MapperT4 T4 { get; set; } + + public MapperT3(string str, char c, MapperT4 t4) + { + String = str; + Char = c; + T4 = t4; + } + } + + public class MapperT4 + { + public string String { get; set; } + + public MapperT4() + { + + } + + public MapperT4(string str) + { + String = str; + } + } +} diff --git a/SunnyUI/Static/UAudio.cs b/SunnyUI/Common/UAudio.cs similarity index 100% rename from SunnyUI/Static/UAudio.cs rename to SunnyUI/Common/UAudio.cs diff --git a/SunnyUI/Static/UControl.cs b/SunnyUI/Common/UControl.cs similarity index 100% rename from SunnyUI/Static/UControl.cs rename to SunnyUI/Common/UControl.cs diff --git a/SunnyUI/Units/UDefine.cs b/SunnyUI/Common/UDefine.cs similarity index 100% rename from SunnyUI/Units/UDefine.cs rename to SunnyUI/Common/UDefine.cs diff --git a/SunnyUI/Static/UDir.cs b/SunnyUI/Common/UDir.cs similarity index 100% rename from SunnyUI/Static/UDir.cs rename to SunnyUI/Common/UDir.cs diff --git a/SunnyUI/Static/UEnvironment.cs b/SunnyUI/Common/UEnvironment.cs similarity index 100% rename from SunnyUI/Static/UEnvironment.cs rename to SunnyUI/Common/UEnvironment.cs diff --git a/SunnyUI/Units/UFastBitmap.cs b/SunnyUI/Common/UFastBitmap.cs similarity index 100% rename from SunnyUI/Units/UFastBitmap.cs rename to SunnyUI/Common/UFastBitmap.cs diff --git a/SunnyUI/Static/UFile.cs b/SunnyUI/Common/UFile.cs similarity index 100% rename from SunnyUI/Static/UFile.cs rename to SunnyUI/Common/UFile.cs diff --git a/SunnyUI/Units/UFolderBrowserDialogEx.cs b/SunnyUI/Common/UFolderBrowserDialogEx.cs similarity index 100% rename from SunnyUI/Units/UFolderBrowserDialogEx.cs rename to SunnyUI/Common/UFolderBrowserDialogEx.cs diff --git a/SunnyUI/Static/UGDI.cs b/SunnyUI/Common/UGDI.cs similarity index 100% rename from SunnyUI/Static/UGDI.cs rename to SunnyUI/Common/UGDI.cs diff --git a/SunnyUI/Units/UGif.cs b/SunnyUI/Common/UGif.cs similarity index 100% rename from SunnyUI/Units/UGif.cs rename to SunnyUI/Common/UGif.cs diff --git a/SunnyUI/Static/UGraphics.cs b/SunnyUI/Common/UGraphics.cs similarity index 100% rename from SunnyUI/Static/UGraphics.cs rename to SunnyUI/Common/UGraphics.cs diff --git a/SunnyUI/Units/UHook.cs b/SunnyUI/Common/UHook.cs similarity index 100% rename from SunnyUI/Units/UHook.cs rename to SunnyUI/Common/UHook.cs diff --git a/SunnyUI/Static/UImage.cs b/SunnyUI/Common/UImage.cs similarity index 100% rename from SunnyUI/Static/UImage.cs rename to SunnyUI/Common/UImage.cs diff --git a/SunnyUI/Units/UIniConfig.cs b/SunnyUI/Common/UIniConfig.cs similarity index 100% rename from SunnyUI/Units/UIniConfig.cs rename to SunnyUI/Common/UIniConfig.cs diff --git a/SunnyUI/Units/UIniFile.cs b/SunnyUI/Common/UIniFile.cs similarity index 100% rename from SunnyUI/Units/UIniFile.cs rename to SunnyUI/Common/UIniFile.cs diff --git a/SunnyUI/Units/UJson.cs b/SunnyUI/Common/UJson.cs similarity index 100% rename from SunnyUI/Units/UJson.cs rename to SunnyUI/Common/UJson.cs diff --git a/SunnyUI/Units/UJsonConfig.cs b/SunnyUI/Common/UJsonConfig.cs similarity index 100% rename from SunnyUI/Units/UJsonConfig.cs rename to SunnyUI/Common/UJsonConfig.cs diff --git a/SunnyUI/Static/ULedChars.cs b/SunnyUI/Common/ULedChars.cs similarity index 100% rename from SunnyUI/Static/ULedChars.cs rename to SunnyUI/Common/ULedChars.cs diff --git a/SunnyUI/Units/ULocalize.cs b/SunnyUI/Common/ULocalize.cs similarity index 100% rename from SunnyUI/Units/ULocalize.cs rename to SunnyUI/Common/ULocalize.cs diff --git a/SunnyUI/Units/UMMFile.cs b/SunnyUI/Common/UMMFile.cs similarity index 100% rename from SunnyUI/Units/UMMFile.cs rename to SunnyUI/Common/UMMFile.cs diff --git a/SunnyUI/Common/UMapper.cs b/SunnyUI/Common/UMapper.cs new file mode 100644 index 00000000..cee2eeb6 --- /dev/null +++ b/SunnyUI/Common/UMapper.cs @@ -0,0 +1,181 @@ +/****************************************************************************** + * SunnyUI 开源控件库、工具类库、扩展类库、多页面开发框架。 + * CopyRight (C) 2012-2021 ShenYongHua(沈永华). + * QQ群:56829229 QQ:17612584 EMail:SunnyUI@QQ.Com + * + * Blog: https://www.cnblogs.com/yhuse + * Gitee: https://gitee.com/yhuse/SunnyUI + * GitHub: https://github.com/yhuse/SunnyUI + * + * SunnyUI.dll can be used for free under the GPL-3.0 license. + * If you use this code, please keep this note. + * 如果您使用此代码,请保留此说明。 + ****************************************************************************** + * 文件名称: UMapper.cs + * 文件说明: 轻量级的对象映射框架,可以映射值类型(包括Struct),和以值类型构成的List和数组。 + * 当前版本: V3.0 + * 创建日期: 2021-09-30 + * + * 2021-09-30: V3.0.7 增加文件说明 +******************************************************************************/ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Sunny.UI +{ + public static class SunnyMapper + { + private static void Mapper(T1 source, T2 dest) + where T1 : class + where T2 : class + { + if (source == null || dest == null) + { + return; + } + + var listSource = source.GetType().GetNeedProperties().ToDictionary(prop => prop.Name); + var listDest = dest.GetType().GetNeedProperties().ToDictionary(prop => prop.Name); + + foreach (var item in listDest) + { + if (listSource.NotContainsKey(item.Key)) continue; + + var sourceInfo = listSource[item.Key]; + Type sourceType = sourceInfo.PropertyType; + object sourceValue = sourceInfo.GetValue(source, null); + + var destInfo = item.Value; + Type destType = item.Value.PropertyType; + + if (!sourceType.Equals(destType)) continue; + if (sourceType.IsValueType) + { + //Console.WriteLine("ValueType: " + item.Key + ", " + sourceType.FullName); + destInfo.SetValue(dest, sourceValue, null); + } + else + { + if (sourceType == typeof(string)) + { + //Console.WriteLine("String: " + item.Key + ", " + sourceType.FullName); + destInfo.SetValue(dest, sourceValue, null); + continue; + } + + if (sourceType.IsList()) + { + //Console.WriteLine("List: " + item.Key + ", " + sourceType.FullName); + Type[] sourceTypes = sourceType.GetGenericArguments(); + Type[] destTypes = destType.GetGenericArguments(); + if (sourceTypes.Length != 1) continue; + if (destTypes.Length != 1) continue; + if (!sourceTypes[0].Equals(destTypes[0])) continue; + + if (sourceValue == null) + { + destInfo.SetValue(dest, null, null); + } + else + { + Type typeDataList = typeof(List<>).MakeGenericType(destTypes[0]); + MethodInfo AddInfo = typeDataList.GetMethod("Add", BindingFlags.Public | BindingFlags.Instance); + if (AddInfo == null) continue; + + if (sourceTypes[0].IsValueType || sourceTypes[0] == typeof(string)) + { + object listvalue = typeDataList.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, new object[] { }); + IEnumerable sourceList = sourceValue as IEnumerable; + foreach (var listItem in sourceList) + { + AddInfo.Invoke(listvalue, new[] { listItem }); + } + + destInfo.SetValue(dest, listvalue, null); + } + else + { + //暂时不考虑 + } + } + + continue; + } + + if (sourceType.IsArray) + { + //Console.WriteLine("Array: " + item.Key + ", " + sourceType.FullName); + if (sourceValue == null) + { + destInfo.SetValue(dest, null, null); + } + else + { + ICollection sourceList = sourceValue as ICollection; + Type type = sourceType.GetElementType(); + var array = Array.CreateInstance(type, sourceList.Count); + + int index = 0; + foreach (var listItem in sourceList) + { + array.SetValue(listItem, index++); + } + + destInfo.SetValue(dest, array, null); + } + + continue; + } + + if (sourceType.IsDictionary()) + { + + continue; + } + + //类没有无参构造函数的话,创建有问题 + //if (sourceType.IsClass) + //{ + // if (sourceValue == null) + // { + // destInfo.SetValue(dest, null, null); + // } + // else + // { + // object obj = Activator.CreateInstance(sourceType, null); + // obj.MapperFrom(sourceValue); + // destInfo.SetValue(dest, obj, null); + // } + // + // continue; + //} + } + } + } + + public static void MapperTo(this T1 source, T2 dest) + where T1 : class + where T2 : class + { + Mapper(source, dest); + } + + public static void MapperFrom(this T1 dest, T2 source) + where T1 : class + where T2 : class + { + Mapper(source, dest); + } + + public static Type GetArrayElementType(this Type t) + { + if (!t.IsArray) return null; + string name = t.FullName.Replace("[]", string.Empty); + return t.Assembly.GetType(name); + } + } +} diff --git a/SunnyUI/Static/UMessageTip.cs b/SunnyUI/Common/UMessageTip.cs similarity index 100% rename from SunnyUI/Static/UMessageTip.cs rename to SunnyUI/Common/UMessageTip.cs diff --git a/SunnyUI/Static/UPrivilegeAPI.cs b/SunnyUI/Common/UPrivilegeAPI.cs similarity index 100% rename from SunnyUI/Static/UPrivilegeAPI.cs rename to SunnyUI/Common/UPrivilegeAPI.cs diff --git a/SunnyUI/Static/UScrollBarInfo.cs b/SunnyUI/Common/UScrollBarInfo.cs similarity index 100% rename from SunnyUI/Static/UScrollBarInfo.cs rename to SunnyUI/Common/UScrollBarInfo.cs diff --git a/SunnyUI/Units/USevenZip.cs b/SunnyUI/Common/USevenZip.cs similarity index 100% rename from SunnyUI/Units/USevenZip.cs rename to SunnyUI/Common/USevenZip.cs diff --git a/SunnyUI/Units/USuspendCtrlAltDel.cs b/SunnyUI/Common/USuspendCtrlAltDel.cs similarity index 100% rename from SunnyUI/Units/USuspendCtrlAltDel.cs rename to SunnyUI/Common/USuspendCtrlAltDel.cs diff --git a/SunnyUI/Static/USyncTime.cs b/SunnyUI/Common/USyncTime.cs similarity index 100% rename from SunnyUI/Static/USyncTime.cs rename to SunnyUI/Common/USyncTime.cs diff --git a/SunnyUI/Static/USystem.cs b/SunnyUI/Common/USystem.cs similarity index 100% rename from SunnyUI/Static/USystem.cs rename to SunnyUI/Common/USystem.cs diff --git a/SunnyUI/Units/UThunder.cs b/SunnyUI/Common/UThunder.cs similarity index 100% rename from SunnyUI/Units/UThunder.cs rename to SunnyUI/Common/UThunder.cs diff --git a/SunnyUI/Units/UTranslate.cs b/SunnyUI/Common/UTranslate.cs similarity index 100% rename from SunnyUI/Units/UTranslate.cs rename to SunnyUI/Common/UTranslate.cs diff --git a/SunnyUI/Pages/UIPage.Designer.cs b/SunnyUI/Frames/UIPage.Designer.cs similarity index 100% rename from SunnyUI/Pages/UIPage.Designer.cs rename to SunnyUI/Frames/UIPage.Designer.cs diff --git a/SunnyUI/Pages/UIPage.cs b/SunnyUI/Frames/UIPage.cs similarity index 100% rename from SunnyUI/Pages/UIPage.cs rename to SunnyUI/Frames/UIPage.cs diff --git a/SunnyUI/Pages/UIPage.resx b/SunnyUI/Frames/UIPage.resx similarity index 100% rename from SunnyUI/Pages/UIPage.resx rename to SunnyUI/Frames/UIPage.resx diff --git a/SunnyUI/Pages/UITitlePage.Designer.cs b/SunnyUI/Frames/UITitlePage.Designer.cs similarity index 100% rename from SunnyUI/Pages/UITitlePage.Designer.cs rename to SunnyUI/Frames/UITitlePage.Designer.cs diff --git a/SunnyUI/Pages/UITitlePage.cs b/SunnyUI/Frames/UITitlePage.cs similarity index 100% rename from SunnyUI/Pages/UITitlePage.cs rename to SunnyUI/Frames/UITitlePage.cs diff --git a/SunnyUI/Pages/UITitlePage.resx b/SunnyUI/Frames/UITitlePage.resx similarity index 100% rename from SunnyUI/Pages/UITitlePage.resx rename to SunnyUI/Frames/UITitlePage.resx diff --git a/SunnyUI/Static/UMapper.cs b/SunnyUI/Static/UMapper.cs deleted file mode 100644 index bb439c71..00000000 --- a/SunnyUI/Static/UMapper.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Linq; - -namespace Sunny.UI -{ - public static class MapperEx - { - private static void Mapper(T source, T dest) - { - var listSource = source.GetType().GetNeedProperties().ToDictionary(prop => prop.Name); - var listDest = source.GetType().GetNeedProperties().ToDictionary(prop => prop.Name); - - foreach (var item in listDest) - { - if (listSource.ContainsKey(item.Key)) - { - var sourceInfo = listSource[item.Key]; - object sourceValue = sourceInfo.GetValue(source, null); - Type sourceType = sourceInfo.PropertyType; - - Type destType = item.Value.PropertyType; - var destInfo = item.Value; - - if (sourceType.IsValueType) - { - destInfo.SetValue(dest, sourceValue, null); - } - else - { - - } - } - } - } - - public static void MapperTo(this T source, T dest) - { - Mapper(source, dest); - } - - public static void MapperFrom(this T dest, T source) - { - Mapper(source, dest); - } - } -}