Saiyanslayer
Saiyanslayer
CC#
Created by Tyler on 12/13/2024 in #help
Advice for learning C# (Beginner - New to C# not programming)
Nick Chapsas has a video on this: https://www.youtube.com/watch?v=1oeMTz7LwrU
5 replies
CC#
Created by Saiyanslayer on 10/25/2024 in #help
✅ Better way to set a property using linq?
thats awesome, thanks!
6 replies
CC#
Created by Saiyanslayer on 10/25/2024 in #help
✅ Better way to set a property using linq?
I'll have to try using a for loop instead now that you mention that.
6 replies
CC#
Created by Saiyanslayer on 10/25/2024 in #help
✅ Better way to set a property using linq?
I'm looping through values witha foreach loop, IIRC you can't bind those
6 replies
CC#
Created by Saiyanslayer on 10/23/2024 in #help
When to use a static helper class vs extension methods
Awesome, thanks everyone!
15 replies
CC#
Created by Saiyanslayer on 10/23/2024 in #help
When to use a static helper class vs extension methods
Root is from an external library
15 replies
CC#
Created by Saiyanslayer on 10/17/2024 in #help
WPF TreeView Fails to load ItemsSource
I think that did it, thanks!
5 replies
CC#
Created by Saiyanslayer on 10/17/2024 in #help
WPF TreeView Fails to load ItemsSource
I think you're right, I'll try making that NodeItem a list
5 replies
CC#
Created by Saiyanslayer on 10/19/2024 in #help
How to find and update a record in a recursive model?
This is what solved my issue:
Xml.Document.Descendants().First(x => x == oldNode.XmlElement).ReplaceWith(newNode.XmlElement);
Xml.Document.Descendants().First(x => x == oldNode.XmlElement).ReplaceWith(newNode.XmlElement);
16 replies
CC#
Created by Saiyanslayer on 10/19/2024 in #help
How to find and update a record in a recursive model?
I wrapped the XDocument stuff because I wanted flexibility on how to access the info: if I change my mind on which package or method to do something, I'll have one place to change it, not dozens
16 replies
CC#
Created by Saiyanslayer on 10/19/2024 in #help
How to find and update a record in a recursive model?
public sealed class NodeTree {
public XDocument? Xml { get; set; } = new XDocument();
public NodeItem? Root => Xml is null || Xml.Document is null || Xml.Document.Root is null
? null
: new NodeItem(Xml.Document.Root);

public void UpdateNode(NodeItem oldNode, NodeItem newNode) {
if ( Xml is null || Xml.Document is null) { return; }

Xml.Document.Descendants().First(x => x == oldNode.XmlElement).ReplaceWith(newNode.XmlElement);
}
}
public sealed class NodeTree {
public XDocument? Xml { get; set; } = new XDocument();
public NodeItem? Root => Xml is null || Xml.Document is null || Xml.Document.Root is null
? null
: new NodeItem(Xml.Document.Root);

public void UpdateNode(NodeItem oldNode, NodeItem newNode) {
if ( Xml is null || Xml.Document is null) { return; }

Xml.Document.Descendants().First(x => x == oldNode.XmlElement).ReplaceWith(newNode.XmlElement);
}
}
16 replies
CC#
Created by Saiyanslayer on 10/19/2024 in #help
How to find and update a record in a recursive model?
public sealed record NodeItem {
public XElement XmlElement { get; init; }
public string Name => XmlElement.Name.LocalName;
public string Value => !XmlElement.HasElements && !string.IsNullOrWhiteSpace(XmlElement.Value)
? XmlElement.Value
: string.Empty;

public bool HasChildren => XmlElement.HasElements;
public bool HasAttributes => XmlElement.HasAttributes;

public List<NodeItem> Children => XmlElement.Elements().Select(x => new NodeItem(x)).ToList();
public List<NodeAttribute> Attributes
=> XmlElement.Attributes().Select(x => new NodeAttribute(x.Name.LocalName, x.Value)).ToList();
public NodeItem(XElement element) => XmlElement = element;
public NodeItem Copy() => new NodeItem(this);
public void SetValue(string value) => XmlElement.SetValue(value);
}

public sealed record NodeAttribute(string Name, string Value);
public sealed record NodeItem {
public XElement XmlElement { get; init; }
public string Name => XmlElement.Name.LocalName;
public string Value => !XmlElement.HasElements && !string.IsNullOrWhiteSpace(XmlElement.Value)
? XmlElement.Value
: string.Empty;

public bool HasChildren => XmlElement.HasElements;
public bool HasAttributes => XmlElement.HasAttributes;

public List<NodeItem> Children => XmlElement.Elements().Select(x => new NodeItem(x)).ToList();
public List<NodeAttribute> Attributes
=> XmlElement.Attributes().Select(x => new NodeAttribute(x.Name.LocalName, x.Value)).ToList();
public NodeItem(XElement element) => XmlElement = element;
public NodeItem Copy() => new NodeItem(this);
public void SetValue(string value) => XmlElement.SetValue(value);
}

public sealed record NodeAttribute(string Name, string Value);
16 replies
CC#
Created by Saiyanslayer on 10/19/2024 in #help
How to find and update a record in a recursive model?
My issue was finding and editing a node especially if two or more nodes had the same name without any id. Clint made a good point and I've refactored the code
16 replies
CC#
Created by Saiyanslayer on 10/19/2024 in #help
How to find and update a record in a recursive model?
Ya I was worried about that. I can share the project if that helps, or show the razor html
16 replies
CC#
Created by Saiyanslayer on 10/19/2024 in #help
How to find and update a record in a recursive model?
That component allows editing and returns the changed node in OnNodeUpdated
16 replies
CC#
Created by Saiyanslayer on 10/19/2024 in #help
How to find and update a record in a recursive model?
Making a web app to edit xml. I have a component that shows the data of the selected node
16 replies
CC#
Created by workani on 10/18/2024 in #help
What should I do next?
Kk. If I were in your position, this video would be my next step: https://youtu.be/FupLQ7y9oy0?si=KMSF5UM5beD5dPyc
10 replies
CC#
Created by workani on 10/18/2024 in #help
What should I do next?
Depends on what your goals is for learning here. You could use C# in web dev, desktop apps, mobile apps, game dev, etc. Why did you start programming in C#?
10 replies
CC#
Created by Saiyanslayer on 10/19/2024 in #help
How to find and update a record in a recursive model?
Background info: these nodes represent a XML file. It might be easier to rely on XDocument instead, but I want to learn more about recursive design.
16 replies
CC#
Created by Saiyanslayer on 10/17/2024 in #help
WPF TreeView Fails to load ItemsSource
The NodeItem:
public class NodeItem {
public string Name { get; set; }
public ObservableCollection<NodeItem> Children { get; set; }

public NodeItem() {
Name = "No name";
Children = new();
}
public NodeItem(NModel node) {
Name = node.Name;
Children = new();
foreach (var child in node.Children) { Children.Add(new NodeItem(child)); }
}
}
public class NodeItem {
public string Name { get; set; }
public ObservableCollection<NodeItem> Children { get; set; }

public NodeItem() {
Name = "No name";
Children = new();
}
public NodeItem(NModel node) {
Name = node.Name;
Children = new();
foreach (var child in node.Children) { Children.Add(new NodeItem(child)); }
}
}
5 replies