ShadowTrolll
ShadowTrolll
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
Anyway, thanks again, Good night
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
Well, next comes getting this stuff, somehow, over to SQLite database
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
Sure hope so x_x
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
I looked at the object by hovering
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
I dont have console, I did testing via button in my WPF 😄
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
public string Name { get; set; }
public List<KeyValuePair<string, Object>> Properties { get; set; }

public void DeSerialiseTech(string inp)
{
this.Properties = new List<KeyValuePair<string, Object>>();
Regex rx = new Regex("(\\S+)\\s*=\\s*(\\S*)", RegexOptions.Compiled);
Match rxMatch = rx.Match(inp);
if (rxMatch.Success)
{
this.Name = rxMatch.Groups[1].Value;
Object properties = DeSerialisePart(inp.Substring(rxMatch.Index + rxMatch.Length), rx);
try {
this.Properties = (List<KeyValuePair<string, Object>>)properties;
} catch { }
}
}

private Object DeSerialisePart(string inp, Regex rx)
{
MatchCollection rxMatches = rx.Matches(inp);
if (rxMatches.Count == 0) return inp;

List<KeyValuePair<string, Object>> subDict = new List<KeyValuePair<string, Object>>();
int closeIdx = 0;

foreach (Match rxMatch in rxMatches)
{
if (rxMatch.Index >= closeIdx)
{
if (rxMatch.Groups[2].Value == "{")
{
int startIdx = rxMatch.Index;
closeIdx = startIdx;
int openCnt = 1;
foreach (char c in inp.Substring(startIdx + rxMatch.Length))
{
closeIdx += 1;
if (c == '{') openCnt += 1;
else if (c == '}') openCnt -= 1;
if (openCnt == 0) break;
}

subDict.Add(new KeyValuePair<string, Object>(rxMatch.Groups[1].Value, DeSerialisePart(inp.Substring(startIdx + rxMatch.Length, closeIdx - startIdx - 1), rx)));
}
else subDict.Add(new KeyValuePair<string, Object>(rxMatch.Groups[1].Value, rxMatch.Groups[2].Value));
}
}

return subDict;
}
}
public string Name { get; set; }
public List<KeyValuePair<string, Object>> Properties { get; set; }

public void DeSerialiseTech(string inp)
{
this.Properties = new List<KeyValuePair<string, Object>>();
Regex rx = new Regex("(\\S+)\\s*=\\s*(\\S*)", RegexOptions.Compiled);
Match rxMatch = rx.Match(inp);
if (rxMatch.Success)
{
this.Name = rxMatch.Groups[1].Value;
Object properties = DeSerialisePart(inp.Substring(rxMatch.Index + rxMatch.Length), rx);
try {
this.Properties = (List<KeyValuePair<string, Object>>)properties;
} catch { }
}
}

private Object DeSerialisePart(string inp, Regex rx)
{
MatchCollection rxMatches = rx.Matches(inp);
if (rxMatches.Count == 0) return inp;

List<KeyValuePair<string, Object>> subDict = new List<KeyValuePair<string, Object>>();
int closeIdx = 0;

foreach (Match rxMatch in rxMatches)
{
if (rxMatch.Index >= closeIdx)
{
if (rxMatch.Groups[2].Value == "{")
{
int startIdx = rxMatch.Index;
closeIdx = startIdx;
int openCnt = 1;
foreach (char c in inp.Substring(startIdx + rxMatch.Length))
{
closeIdx += 1;
if (c == '{') openCnt += 1;
else if (c == '}') openCnt -= 1;
if (openCnt == 0) break;
}

subDict.Add(new KeyValuePair<string, Object>(rxMatch.Groups[1].Value, DeSerialisePart(inp.Substring(startIdx + rxMatch.Length, closeIdx - startIdx - 1), rx)));
}
else subDict.Add(new KeyValuePair<string, Object>(rxMatch.Groups[1].Value, rxMatch.Groups[2].Value));
}
}

return subDict;
}
}
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
@vi.ness Holy shit I got it. It was painful, looks kinda ugly but it seems to work!
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
I mean, thats further than I got so far (:
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
Yeeeah I guess, thanks
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
In WPF
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
@vi.ness Is there a quick way to test a class function? I dont want other stuff to happen, just create an instance of this and call DeSerialiseTech
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace StellTechViewer
{
internal class TechObj
{
public string Name { get; set; }
public Dictionary<string, VariantType> Properties { get; set; }

public void DeSerialiseTech(string inp)
{
this.Properties = new Dictionary<string, VariantType>();
Regex rx = new Regex("(\\S+)\\s*=\\s*(\\S*)", RegexOptions.Compiled);
DeSerialisePart(this.Properties, inp, rx);
}

private void DeSerialisePart(Dictionary<string, VariantType> target, string inp, Regex rx)
{
foreach (Match ItemMatch in rx.Matches(inp))
{
Console.WriteLine(ItemMatch);
}
}
}
}
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace StellTechViewer
{
internal class TechObj
{
public string Name { get; set; }
public Dictionary<string, VariantType> Properties { get; set; }

public void DeSerialiseTech(string inp)
{
this.Properties = new Dictionary<string, VariantType>();
Regex rx = new Regex("(\\S+)\\s*=\\s*(\\S*)", RegexOptions.Compiled);
DeSerialisePart(this.Properties, inp, rx);
}

private void DeSerialisePart(Dictionary<string, VariantType> target, string inp, Regex rx)
{
foreach (Match ItemMatch in rx.Matches(inp))
{
Console.WriteLine(ItemMatch);
}
}
}
}
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
yeah, very cool
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
Thanks for help so far btw
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
hope it works, will get back if I have questions
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
if the 2nd group is { I just go into recursion with whatever follows
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
Allright. For the storing, is
Dictionary<string, VariantType>
Dictionary<string, VariantType>
Viable thing to use if I want string-keyed items and they can be anything?
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
I mostly care about the area, category, prerequisites and somehow showing the weight mods
95 replies
CC#
Created by ShadowTrolll on 6/23/2023 in #help
❔ Serialize objects from non-standard format
To be frank I am fine with just using the whole thing in weight_modifier as one string
95 replies