[chore:] added address patch
This commit is contained in:
118
AddressPatch.cs
Normal file
118
AddressPatch.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
public class AddressPatch
|
||||
{
|
||||
public string refsid_is { get; set; } = "";
|
||||
public string anrede_is { get; set; } = "";
|
||||
public string titel_is { get; set; } = "";
|
||||
public string vorname_is { get; set; } = "";
|
||||
public string adel_is { get; set; } = "";
|
||||
public string name_is { get; set; } = "";
|
||||
public string namezus_is { get; set; } = "";
|
||||
public string anredzus_is { get; set; } = "";
|
||||
public string strasse_is { get; set; } = "";
|
||||
public string strasse2_is { get; set; } = "";
|
||||
public string plz_is { get; set; } = "";
|
||||
public string ort_is { get; set; } = "";
|
||||
public string land_is { get; set; } = "";
|
||||
public string pplz_is { get; set; } = "";
|
||||
public string postfach_is { get; set; } = "";
|
||||
public string name1_is { get; set; } = "";
|
||||
public string name2_is { get; set; } = "";
|
||||
public string name3_is { get; set; } = "";
|
||||
public string name4_is { get; set; } = "";
|
||||
public string name5_is { get; set; } = "";
|
||||
public string funktion_is { get; set; } = "";
|
||||
public string funktion2_is { get; set; } = "";
|
||||
public string abteilung_is { get; set; } = "";
|
||||
public string funktionad_is { get; set; } = "";
|
||||
|
||||
public bool has_refsid { get; set; }
|
||||
public bool has_anrede { get; set; }
|
||||
public bool has_titel { get; set; }
|
||||
public bool has_vorname { get; set; }
|
||||
public bool has_adel { get; set; }
|
||||
public bool has_name { get; set; }
|
||||
public bool has_namezus { get; set; }
|
||||
public bool has_anredzus { get; set; }
|
||||
public bool has_strasse { get; set; }
|
||||
public bool has_strasse2 { get; set; }
|
||||
public bool has_plz { get; set; }
|
||||
public bool has_ort { get; set; }
|
||||
public bool has_land { get; set; }
|
||||
public bool has_pplz { get; set; }
|
||||
public bool has_postfach { get; set; }
|
||||
public bool has_name1 { get; set; }
|
||||
public bool has_name2 { get; set; }
|
||||
public bool has_name3 { get; set; }
|
||||
public bool has_name4 { get; set; }
|
||||
public bool has_name5 { get; set; }
|
||||
public bool has_funktion { get; set; }
|
||||
public bool has_funktion2 { get; set; }
|
||||
public bool has_abteilung { get; set; }
|
||||
public bool has_funktionad { get; set; }
|
||||
|
||||
public static AddressPatch Import(Uri filename)
|
||||
{
|
||||
var patch = new AddressPatch();
|
||||
|
||||
// Alle Zeilen aus der Datei laden
|
||||
var lines = File.ReadAllLines(filename.LocalPath);
|
||||
|
||||
// Alle Properties der Klasse (Strings und bools)
|
||||
var properties = typeof(AddressPatch).GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
// Nur die Properties, die mit _is enden (also die String-Werte)
|
||||
var stringProps = properties.Where(p => p.PropertyType == typeof(string) && p.Name.EndsWith("_is"));
|
||||
|
||||
foreach (var prop in stringProps)
|
||||
{
|
||||
// Beispiel: prop.Name = "name_is"
|
||||
var baseName = prop.Name.Substring(0, prop.Name.Length - 3); // "name"
|
||||
|
||||
// In der Datei wird nach "name:" gesucht (ohne _is)
|
||||
var line = lines.FirstOrDefault(l => l.StartsWith(baseName + ":"));
|
||||
if (line != null)
|
||||
{
|
||||
// Wert extrahieren (alles nach dem Doppelpunkt)
|
||||
var value = line.Substring(line.IndexOf(':') + 1).Trim();
|
||||
|
||||
// Wert im Patch-Objekt setzen
|
||||
prop.SetValue(patch, value);
|
||||
|
||||
// Passendes has_ Feld aktivieren, z.B. "has_name"
|
||||
var hasProp = properties.FirstOrDefault(p => p.Name == "has_" + baseName);
|
||||
if (hasProp != null && hasProp.PropertyType == typeof(bool)) hasProp.SetValue(patch, true);
|
||||
}
|
||||
}
|
||||
|
||||
return patch;
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
var stringProps = properties.Where(p => p.PropertyType == typeof(string) && p.Name.EndsWith("_is"));
|
||||
|
||||
var lines = new StringBuilder();
|
||||
|
||||
foreach (var prop in stringProps)
|
||||
{
|
||||
// passendes has_ Feld
|
||||
var hasProp =
|
||||
properties.FirstOrDefault(p => p.Name == "has_" + prop.Name.Substring(0, prop.Name.Length - 3));
|
||||
if (hasProp != null && (bool)hasProp.GetValue(this))
|
||||
{
|
||||
var value = (string)prop.GetValue(this);
|
||||
lines.AppendLine($"{prop.Name} => {value}");
|
||||
}
|
||||
}
|
||||
|
||||
return lines.ToString().TrimEnd();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user