Вынесение в отдельное пространство имён

This commit is contained in:
2025-04-28 09:21:46 +04:00
parent d6fef4c2c8
commit 06985b99be
3 changed files with 0 additions and 0 deletions
@@ -0,0 +1,66 @@
namespace Pf2eViewer;
partial class EntityTreeViewerControl
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
VerticalScrollBar = new VScrollBar();
ContentPanel = new Panel();
SuspendLayout();
//
// VerticalScrollBar
//
VerticalScrollBar.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right;
VerticalScrollBar.Location = new Point(400, 0);
VerticalScrollBar.Name = "VerticalScrollBar";
VerticalScrollBar.Size = new Size(20, 520);
VerticalScrollBar.TabIndex = 0;
//
// ContentPanel
//
ContentPanel.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
ContentPanel.Location = new Point(0, 0);
ContentPanel.Name = "ContentPanel";
ContentPanel.Size = new Size(400, 520);
ContentPanel.TabIndex = 2;
//
// EntityTreeViewerControl
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(ContentPanel);
Controls.Add(VerticalScrollBar);
Name = "EntityTreeViewerControl";
Size = new Size(420, 520);
ResumeLayout(false);
}
#endregion
private VScrollBar VerticalScrollBar;
private Panel ContentPanel;
}
@@ -0,0 +1,229 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
namespace Pf2eViewer;
public partial class EntityTreeViewerControl : UserControl
{
private int _itemHeight = 20;
private EntityView? _entityView = null;
public int ItemHeight
{
get => _itemHeight;
set
{
_itemHeight = value;
UpdateView();
}
}
public EntityView? EntityView
{
get => _entityView;
set
{
_entityView = value;
UpdateView();
}
}
public EntityTreeViewerControl()
{
InitializeComponent();
}
public void UpdateView()
{
ContentPanel.Controls.Clear();
if (EntityView?.Entity is null)
{
return;
}
Rows.Clear();
Rows.Add(new HeaderRow("Entity"));
Rows.Add(new ObjectComplex(null, EntityView.Entity));
Rows.Add(new HeaderRow(EntityView.SubEntity?.GetType().ToString() ?? "SubEntity"));
Rows.Add(new ObjectComplex(null, EntityView.SubEntity));
List<DisplayRow> displayRows = Rows.SelectMany(r => r.GetTextRows()).ToList();
for (int i = 0; i < displayRows.Count; i++)
{
DisplayRow dr = displayRows[i];
TextBox tb = new()
{
Top = i * ItemHeight,
Left = 0,
Width = ContentPanel.Width,
Height = ItemHeight,
Font = Font,
Text = string.Join(
"",
[new(' ', dr.Depth * 2), dr.Name, dr.Value != "" ? " : " : "", dr.Value]
),
Margin = new(0),
};
ContentPanel.Controls.Add(tb);
}
}
private Panel GetObjectPanel(object obj)
{
Panel result = new();
Type type = obj.GetType();
PropertyInfo[] properties = type.GetProperties();
/*
FieldInfo[] fields = type.GetFields(
BindingFlags.Instance
| BindingFlags.Static
| BindingFlags.NonPublic
| BindingFlags.Public
);
*/
for (int i = 0; i < properties.Length; i++)
{
PropertyInfo property = properties[i];
TextBox tb = new()
{
Top = i * ItemHeight,
Left = 0,
Width = ContentPanel.Width,
Height = ItemHeight,
Font = Font,
Text = property.Name,
Margin = new(0),
};
result.Controls.Add(tb);
}
result.Width = ContentPanel.Width;
result.Height = properties.Length * ItemHeight * 2;
return result;
}
private List<Row> Rows = [];
private class DisplayRow
{
public string Name = "";
public string Value = "";
public int Depth = 0;
}
private abstract class Row
{
public abstract ICollection<DisplayRow> GetTextRows();
public int Depth = 0;
}
private class HeaderRow(string name) : Row
{
public readonly string Name = name;
public override ICollection<DisplayRow> GetTextRows()
{
return [new() { Name = Name, Depth = Depth }];
}
}
private abstract class ObjectField(PropertyInfo property, object? parent) : Row
{
public readonly PropertyInfo? Property = property;
public readonly string Name = property.Name;
public readonly Type Type = property.PropertyType;
public abstract int Rows { get; }
public static ObjectField Resolve(PropertyInfo property, object? parent)
{
return property.PropertyType.IsPrimitive
? new ObjectPrimitive(property, parent)
: new ObjectComplex(property, parent);
}
}
private class ObjectPrimitive : ObjectField
{
public readonly object? Value;
public override int Rows => 1;
public ObjectPrimitive(PropertyInfo? property, object? parent)
: base(property, parent)
{
Value = Property.GetValue(parent, null);
}
public override ICollection<DisplayRow> GetTextRows()
{
return
[
new()
{
Name = Name,
Value = Value?.ToString() ?? "null",
Depth = Depth,
},
];
}
}
private class ObjectComplex : ObjectField
{
public readonly List<ObjectField> Fields;
public bool Collapsed = false;
public override int Rows => 1 + Fields.Select(f => f.Rows).Sum();
public ObjectComplex(PropertyInfo? property, object? parent)
: base(property, parent)
{
PropertyInfo[] properties = Type.GetProperties();
object? value = Property?.GetValue(parent, null) ?? parent;
Fields = properties.Select(f => Resolve(f, value)).ToList();
}
public override ICollection<DisplayRow> GetTextRows()
{
List<DisplayRow> rows = [new() { Name = Name, Depth = Depth }];
if (!Collapsed)
{
rows.AddRange(Fields.SelectMany(f => f.GetTextRows()).ToList());
}
return rows;
}
}
}
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>