20220225
This commit is contained in:
parent
bff4cb735c
commit
87128879a5
@ -18,7 +18,7 @@ public static class SimpleMapper
|
||||
/// <param name="mode">Тип сопоставления</param>
|
||||
/// <param name="list">Список параметров для сопоставления</param>
|
||||
/// <typeparam name="TF">Класс-родитель</typeparam>
|
||||
/// <typeparam name="T">Класс-приёмник</typeparam>
|
||||
/// <typeparam name="T">Класс-приемник</typeparam>
|
||||
public static void MapEx<TF, T> (TF from, ref T to, MapMode mode, List<string> list)
|
||||
{
|
||||
//Копирую поля
|
||||
@ -27,7 +27,7 @@ public static class SimpleMapper
|
||||
foreach (FieldInfo fieldOfA in typeOfA.GetFields())
|
||||
{
|
||||
//Проверяем выполнение условия и прерываем, если не выполняется
|
||||
if (CheckCondition(fieldOfA.Name, fieldOfA.GetValue(from), mode, list))
|
||||
if (!CheckCondition<TF>(fieldOfA.Name, fieldOfA.GetValue(from), mode, list))
|
||||
continue;
|
||||
|
||||
//Получаем FieldInfo для b по имени поля a
|
||||
@ -41,7 +41,7 @@ public static class SimpleMapper
|
||||
foreach (PropertyInfo propertyOfA in typeOfA.GetProperties())
|
||||
{
|
||||
//Проверяем выполнение условия и прерываем, если не выполняется
|
||||
if (CheckCondition(propertyOfA.Name, propertyOfA.GetValue(from), mode, list))
|
||||
if (!CheckCondition<TF>(propertyOfA.Name, propertyOfA.GetValue(from), mode, list))
|
||||
continue;
|
||||
|
||||
//Получаем PropertyInfo для b по имени свойства a
|
||||
@ -56,7 +56,7 @@ public static class SimpleMapper
|
||||
/// </summary>
|
||||
/// <param name="from">Параметр класса F</param>
|
||||
/// <typeparam name="TF">Класс-родитель</typeparam>
|
||||
/// <typeparam name="T">Класс-приёмник</typeparam>
|
||||
/// <typeparam name="T">Класс-приемник</typeparam>
|
||||
/// <returns>Элемент класса T</returns>
|
||||
public static T Map<TF, T> (TF from)
|
||||
{
|
||||
@ -77,7 +77,7 @@ public static class SimpleMapper
|
||||
/// <param name="mode">Режим проверки</param>
|
||||
/// <param name="list">Список игнорирования/добавления</param>
|
||||
/// <returns></returns>
|
||||
private static bool CheckCondition (string itemName, object? itemValue, MapMode mode, ICollection<string> list)
|
||||
private static bool CheckCondition<T> (string itemName, object? itemValue, MapMode mode, ICollection<string> list)
|
||||
{
|
||||
//Если режим "Только список" и поля нет в списке,
|
||||
//либо режим "Только не в списке" и поле есть в списке
|
||||
@ -91,7 +91,7 @@ public static class SimpleMapper
|
||||
MapMode.MapByList => list.Contains(itemName),
|
||||
MapMode.MapIgnoreList => !list.Contains(itemName),
|
||||
MapMode.MapNotDefault => itemValue != default,
|
||||
MapMode.MapNotNullOrDefault => itemValue != null || itemValue != default,
|
||||
MapMode.MapNotNullOrDefault => !Equals(itemValue, default(T)),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null)
|
||||
};
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Version>1.2022.223</Version>
|
||||
<Version>1.2022.225</Version>
|
||||
<Authors>Alexander Babaev</Authors>
|
||||
<Product>ANB Software Components Pack</Product>
|
||||
<Description>Library of some useful functions in C# language.</Description>
|
||||
@ -15,8 +15,8 @@
|
||||
<SignAssembly>False</SignAssembly>
|
||||
<PackageProjectUrl>https://github.com/GoodBoyAlex/anbsoftware_componentspack</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/GoodBoyAlex/anbsoftware_componentspack</RepositoryUrl>
|
||||
<AssemblyVersion>1.2022.0223</AssemblyVersion>
|
||||
<FileVersion>1.2022.223</FileVersion>
|
||||
<AssemblyVersion>1.2022.0225</AssemblyVersion>
|
||||
<FileVersion>1.2022.225</FileVersion>
|
||||
<PackageId>ANBSoftware.ComponentsPack</PackageId>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<AnalysisLevel>6.0</AnalysisLevel>
|
||||
|
75
demo/MainMenu.Designer.cs
generated
Normal file
75
demo/MainMenu.Designer.cs
generated
Normal file
@ -0,0 +1,75 @@
|
||||
namespace demo;
|
||||
|
||||
sealed partial class MainMenu
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent ()
|
||||
{
|
||||
this.CountValueTest = new System.Windows.Forms.Button();
|
||||
this.SimpleMapperTest = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// CountValueTest
|
||||
//
|
||||
this.CountValueTest.Location = new System.Drawing.Point(12, 12);
|
||||
this.CountValueTest.Name = "CountValueTest";
|
||||
this.CountValueTest.Size = new System.Drawing.Size(337, 53);
|
||||
this.CountValueTest.TabIndex = 0;
|
||||
this.CountValueTest.Text = "New CountValue Test";
|
||||
this.CountValueTest.UseVisualStyleBackColor = true;
|
||||
this.CountValueTest.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// SimpleMapperTest
|
||||
//
|
||||
this.SimpleMapperTest.Location = new System.Drawing.Point(12, 71);
|
||||
this.SimpleMapperTest.Name = "SimpleMapperTest";
|
||||
this.SimpleMapperTest.Size = new System.Drawing.Size(335, 51);
|
||||
this.SimpleMapperTest.TabIndex = 1;
|
||||
this.SimpleMapperTest.Text = "New SimpleMapper test";
|
||||
this.SimpleMapperTest.UseVisualStyleBackColor = true;
|
||||
this.SimpleMapperTest.Click += new System.EventHandler(this.SimpleMapperTest_Click);
|
||||
//
|
||||
// MainMenu
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(361, 252);
|
||||
this.Controls.Add(this.SimpleMapperTest);
|
||||
this.Controls.Add(this.CountValueTest);
|
||||
this.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.Name = "MainMenu";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Main menu";
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button CountValueTest;
|
||||
private Button SimpleMapperTest;
|
||||
}
|
30
demo/MainMenu.cs
Normal file
30
demo/MainMenu.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace demo;
|
||||
public sealed partial class MainMenu: Form
|
||||
{
|
||||
public MainMenu ()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void button1_Click (object sender, EventArgs e)
|
||||
{
|
||||
CountValueTest formCountValueTest = new();
|
||||
formCountValueTest.ShowDialog();
|
||||
}
|
||||
|
||||
private void SimpleMapperTest_Click (object sender, EventArgs e)
|
||||
{
|
||||
SampleMapperTest formSampleMapperTest = new();
|
||||
formSampleMapperTest.ShowDialog();
|
||||
}
|
||||
}
|
60
demo/MainMenu.resx
Normal file
60
demo/MainMenu.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -9,6 +9,6 @@ internal static class Program
|
||||
static void Main ()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new CountValueTest());
|
||||
Application.Run(new MainMenu());
|
||||
}
|
||||
}
|
189
demo/SampleMapperTest.Designer.cs
generated
Normal file
189
demo/SampleMapperTest.Designer.cs
generated
Normal file
@ -0,0 +1,189 @@
|
||||
namespace demo;
|
||||
|
||||
sealed partial class SampleMapperTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent ()
|
||||
{
|
||||
this.DemoBoolEdt = new System.Windows.Forms.CheckBox();
|
||||
this.DemoStringEdt = new System.Windows.Forms.TextBox();
|
||||
this.DemoIntEdt = new System.Windows.Forms.NumericUpDown();
|
||||
this.DemoDateTimeEdt = new System.Windows.Forms.DateTimePicker();
|
||||
this.MapBtn = new System.Windows.Forms.Button();
|
||||
this.ResultArea = new System.Windows.Forms.TextBox();
|
||||
this.DemoStringLabel = new System.Windows.Forms.Label();
|
||||
this.DemoIntLabel = new System.Windows.Forms.Label();
|
||||
this.DemoDateTimeLabel = new System.Windows.Forms.Label();
|
||||
this.MapModeEdit = new System.Windows.Forms.ComboBox();
|
||||
this.MapModeLabel = new System.Windows.Forms.Label();
|
||||
((System.ComponentModel.ISupportInitialize)(this.DemoIntEdt)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// DemoBoolEdt
|
||||
//
|
||||
this.DemoBoolEdt.AutoSize = true;
|
||||
this.DemoBoolEdt.Location = new System.Drawing.Point(32, 144);
|
||||
this.DemoBoolEdt.Name = "DemoBoolEdt";
|
||||
this.DemoBoolEdt.Size = new System.Drawing.Size(65, 25);
|
||||
this.DemoBoolEdt.TabIndex = 0;
|
||||
this.DemoBoolEdt.Text = "Bool";
|
||||
this.DemoBoolEdt.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// DemoStringEdt
|
||||
//
|
||||
this.DemoStringEdt.Location = new System.Drawing.Point(32, 42);
|
||||
this.DemoStringEdt.Name = "DemoStringEdt";
|
||||
this.DemoStringEdt.Size = new System.Drawing.Size(737, 29);
|
||||
this.DemoStringEdt.TabIndex = 1;
|
||||
//
|
||||
// DemoIntEdt
|
||||
//
|
||||
this.DemoIntEdt.Location = new System.Drawing.Point(32, 109);
|
||||
this.DemoIntEdt.Name = "DemoIntEdt";
|
||||
this.DemoIntEdt.Size = new System.Drawing.Size(737, 29);
|
||||
this.DemoIntEdt.TabIndex = 2;
|
||||
//
|
||||
// DemoDateTimeEdt
|
||||
//
|
||||
this.DemoDateTimeEdt.CustomFormat = "dd.MM.yyyy HH:mm:ss";
|
||||
this.DemoDateTimeEdt.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
|
||||
this.DemoDateTimeEdt.Location = new System.Drawing.Point(32, 193);
|
||||
this.DemoDateTimeEdt.Name = "DemoDateTimeEdt";
|
||||
this.DemoDateTimeEdt.Size = new System.Drawing.Size(737, 29);
|
||||
this.DemoDateTimeEdt.TabIndex = 3;
|
||||
//
|
||||
// MapBtn
|
||||
//
|
||||
this.MapBtn.Location = new System.Drawing.Point(32, 306);
|
||||
this.MapBtn.Name = "MapBtn";
|
||||
this.MapBtn.Size = new System.Drawing.Size(737, 57);
|
||||
this.MapBtn.TabIndex = 5;
|
||||
this.MapBtn.Text = "MAP";
|
||||
this.MapBtn.UseVisualStyleBackColor = true;
|
||||
this.MapBtn.Click += new System.EventHandler(this.MapBtn_Click);
|
||||
//
|
||||
// ResultArea
|
||||
//
|
||||
this.ResultArea.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.ResultArea.Location = new System.Drawing.Point(811, 0);
|
||||
this.ResultArea.Multiline = true;
|
||||
this.ResultArea.Name = "ResultArea";
|
||||
this.ResultArea.ReadOnly = true;
|
||||
this.ResultArea.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||
this.ResultArea.Size = new System.Drawing.Size(332, 378);
|
||||
this.ResultArea.TabIndex = 6;
|
||||
//
|
||||
// DemoStringLabel
|
||||
//
|
||||
this.DemoStringLabel.AutoSize = true;
|
||||
this.DemoStringLabel.Location = new System.Drawing.Point(32, 18);
|
||||
this.DemoStringLabel.Name = "DemoStringLabel";
|
||||
this.DemoStringLabel.Size = new System.Drawing.Size(54, 21);
|
||||
this.DemoStringLabel.TabIndex = 7;
|
||||
this.DemoStringLabel.Text = "String";
|
||||
//
|
||||
// DemoIntLabel
|
||||
//
|
||||
this.DemoIntLabel.AutoSize = true;
|
||||
this.DemoIntLabel.Location = new System.Drawing.Point(32, 85);
|
||||
this.DemoIntLabel.Name = "DemoIntLabel";
|
||||
this.DemoIntLabel.Size = new System.Drawing.Size(30, 21);
|
||||
this.DemoIntLabel.TabIndex = 8;
|
||||
this.DemoIntLabel.Text = "Int";
|
||||
//
|
||||
// DemoDateTimeLabel
|
||||
//
|
||||
this.DemoDateTimeLabel.AutoSize = true;
|
||||
this.DemoDateTimeLabel.Location = new System.Drawing.Point(32, 169);
|
||||
this.DemoDateTimeLabel.Name = "DemoDateTimeLabel";
|
||||
this.DemoDateTimeLabel.Size = new System.Drawing.Size(81, 21);
|
||||
this.DemoDateTimeLabel.TabIndex = 9;
|
||||
this.DemoDateTimeLabel.Text = "DateTime";
|
||||
//
|
||||
// MapModeEdit
|
||||
//
|
||||
this.MapModeEdit.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.MapModeEdit.FormattingEnabled = true;
|
||||
this.MapModeEdit.Items.AddRange(new object[] {
|
||||
"Full",
|
||||
"Not null",
|
||||
"Not default",
|
||||
"Not null or default"});
|
||||
this.MapModeEdit.Location = new System.Drawing.Point(32, 254);
|
||||
this.MapModeEdit.Name = "MapModeEdit";
|
||||
this.MapModeEdit.Size = new System.Drawing.Size(737, 29);
|
||||
this.MapModeEdit.TabIndex = 10;
|
||||
//
|
||||
// MapModeLabel
|
||||
//
|
||||
this.MapModeLabel.AutoSize = true;
|
||||
this.MapModeLabel.Location = new System.Drawing.Point(32, 230);
|
||||
this.MapModeLabel.Name = "MapModeLabel";
|
||||
this.MapModeLabel.Size = new System.Drawing.Size(91, 21);
|
||||
this.MapModeLabel.TabIndex = 11;
|
||||
this.MapModeLabel.Text = "Map mode";
|
||||
//
|
||||
// SampleMapperTest
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1143, 378);
|
||||
this.Controls.Add(this.MapModeLabel);
|
||||
this.Controls.Add(this.MapModeEdit);
|
||||
this.Controls.Add(this.DemoDateTimeLabel);
|
||||
this.Controls.Add(this.DemoIntLabel);
|
||||
this.Controls.Add(this.DemoStringLabel);
|
||||
this.Controls.Add(this.ResultArea);
|
||||
this.Controls.Add(this.MapBtn);
|
||||
this.Controls.Add(this.DemoDateTimeEdt);
|
||||
this.Controls.Add(this.DemoIntEdt);
|
||||
this.Controls.Add(this.DemoStringEdt);
|
||||
this.Controls.Add(this.DemoBoolEdt);
|
||||
this.Font = new System.Drawing.Font("Times New Roman", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
|
||||
this.Margin = new System.Windows.Forms.Padding(4);
|
||||
this.Name = "SampleMapperTest";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
|
||||
this.Text = "SampleMapper test";
|
||||
((System.ComponentModel.ISupportInitialize)(this.DemoIntEdt)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CheckBox DemoBoolEdt;
|
||||
private TextBox DemoStringEdt;
|
||||
private NumericUpDown DemoIntEdt;
|
||||
private DateTimePicker DemoDateTimeEdt;
|
||||
private Button MapBtn;
|
||||
private TextBox ResultArea;
|
||||
private Label DemoStringLabel;
|
||||
private Label DemoIntLabel;
|
||||
private Label DemoDateTimeLabel;
|
||||
private ComboBox MapModeEdit;
|
||||
private Label MapModeLabel;
|
||||
}
|
73
demo/SampleMapperTest.cs
Normal file
73
demo/SampleMapperTest.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using anbs_cp;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace demo;
|
||||
public sealed partial class SampleMapperTest: Form
|
||||
{
|
||||
public SampleMapperTest ()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void MapBtn_Click (object sender, EventArgs e)
|
||||
{
|
||||
Demo1Class demo1 = new()
|
||||
{
|
||||
DemoString = DemoStringEdt.Text,
|
||||
DemoInt = (int)DemoIntEdt.Value,
|
||||
DemoBool = DemoBoolEdt.Checked,
|
||||
DemoDateTime = DemoDateTimeEdt.Value
|
||||
};
|
||||
|
||||
Demo1Class demo2 = new()
|
||||
{
|
||||
DemoInt = 20220224,
|
||||
DemoBool = true,
|
||||
DemoDateTime = default
|
||||
};
|
||||
|
||||
string serialize1 = JsonConvert.SerializeObject(demo2);
|
||||
|
||||
SimpleMapper.MapMode mode = MapModeEdit.SelectedIndex switch
|
||||
{
|
||||
0 => SimpleMapper.MapMode.MapFull,
|
||||
1 => SimpleMapper.MapMode.MapNotNull,
|
||||
2 => SimpleMapper.MapMode.MapNotDefault,
|
||||
3 => SimpleMapper.MapMode.MapNotNullOrDefault,
|
||||
_ => SimpleMapper.MapMode.MapFull
|
||||
};
|
||||
|
||||
SimpleMapper.MapEx(demo1, ref demo2, mode, new List<string>());
|
||||
|
||||
string serialize2 = JsonConvert.SerializeObject(demo2);
|
||||
|
||||
ResultArea.Text = $@"Demo2 Class before map:
|
||||
{serialize1}
|
||||
and after:{serialize2}";
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Demo1Class
|
||||
{
|
||||
public string? DemoString { get; set; }
|
||||
|
||||
public int DemoInt { get; set; }
|
||||
|
||||
public bool DemoBool { get; set; }
|
||||
|
||||
public DateTime DemoDateTime { get; set; }
|
||||
}
|
||||
|
||||
public class Demo2Class
|
||||
{
|
||||
public string? DemoString { get; set; }
|
||||
|
||||
public int DemoInt { get; set; }
|
||||
|
||||
public bool DemoBool { get; set; }
|
||||
|
||||
public DateTime DemoDateTime { get; set; }
|
||||
|
||||
public string? DemoStringNotMapped { get; set; }
|
||||
}
|
65
demo/SampleMapperTest.resx
Normal file
65
demo/SampleMapperTest.resx
Normal file
@ -0,0 +1,65 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="SampleMapperTest_MapBtn_Click_" xml:space="preserve">
|
||||
<value>Demo2 Class before map:
|
||||
{0}
|
||||
and after:{1}</value>
|
||||
</data>
|
||||
</root>
|
@ -2,13 +2,27 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Configurations>Release;Debug.CNF</Configurations>
|
||||
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
|
||||
<StartupObject></StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug.CNF|AnyCPU'">
|
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\anbs_cp\anbs_cp.csproj" />
|
||||
</ItemGroup>
|
||||
|
2
demo/demo.csproj.DotSettings
Normal file
2
demo/demo.csproj.DotSettings
Normal file
@ -0,0 +1,2 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp100</s:String></wpf:ResourceDictionary>
|
Loading…
x
Reference in New Issue
Block a user