How can I create a list with objects containing a set of values to feed XML.
I do have declared : public List<line> line{ get; set; }
I need to create multiple objects of line for every orderline. I'm sure the problem is in IEnumerable declaration yet i don't knwo how to fix it. Right now the code ends at getEnumerator() since its null.
protected mySchema.lines createlines() { mySchema.lines lines = new mySchema.lines(); lines.zz = '3'; lines.xx = '100.00'; System.Collections.IEnumerable list = lines.line; System.Collections.IEnumerator enumerator = list.GetEnumerator(); while (enumerator.MoveNext()) { line myline = enumerator.current; myline = this.createline(); } return FaWiersze; } protected mySchema.line createline() { mySchema.line line = new mySchema.line(); line.qq = '1'; line.ww = 'aaa'; line.ee = 'bbb'; line.rr = 'ccc.'; return line; }
You can get more about ArrayList, including the containing assembly, in ArrayList documention.
Sorry about the bug, it's partially because I wrote code directly here (without a compiler) and partially because of bad naming on your side. The best approach will be distingushing those two Lines elements by choosing a better name for one of them (based on the business domain, which is unknown to me). Line isn't a good name, because it implies that the property holds a single line, not a collection of lines.
I tried to add System.Collections.ArrayList yet I can't find it, even installed System.Collections.NonGeneric that is added to reference in my project yet again I cant call it with 'using'.
Does 'Lines' name is right? It gives me error member names cannot be the same as their enclosing type'. When I change it to Line the error is gone.
private readonly List<Line> Lines { get; } = new List<Line>();
Line dones not contain definition for Add. Does the Add method come for System.Collections.ArrayList?
The non-generic list in .NET is called System.Collections.ArrayList.
But note that you class may use a generic collection while exposing a non-generic interface. For example:
public class Lines { private readonly List Lines { get; } = new List(); public void AddLine(Line line) { Lines.Add(line); } }
I have all names remade so it;s perfectly ideantical. Yet the problem is still there.
What other non generic type could I use to archive my goal?
CLR Interop is case-senstive therefore mySchema and MySchema are twodifferent names. The same applies to Lines vs lines and Line vs line.
Assuming that the namespace is called mySchema, the code should look like this, if you insist on ignoring my recommendation to avoid generics in X :
mySchema.Lines lines = new mySchema.Lines(); System.Collections.Generic.List myLine = new System.Collections.Generic.List(); lines.Line = myLine;
The lines class looks like below. And yes, the code fails on line 3
Edit. chaning to MySchema.line actually didnt changed, the error is still the same
mySchema.lines lines = new mySchema.lines(); System.Collections.Generic.List MyLine = new System.Collections.Generic.List(); lines.line = MyLine;
[XmlType(TypeName = "Lines")] public class Lines { public String LinesNum { get; set; } [XmlElement(ElementName = "Line")] public List Line{ get; set; } }
If I understand you correctly, you're saying that the type of lines.is List<line>, but the following code fails at the third line with "Cannot implicitly convert from type 'System.Collections.Generic.List' to type 'System.Collections.Generic.List'1". Is that correct?
mySchema.lines lines = new mySchema.lines(); System.Collections.Generic.List MyLine = new System.Collections.Generic.List(); lines.line = MyLine;
Should it actually be List<myschema.line> instead of List<line>?
Sorry forgot to mention that for the test case I changed List<line> to Array line. The first part (line 1-9) is for Array line and the second part is for List<line> just added it all together so it may look confusing.
Both error occours on the same line, when I try to set the value lines.line = Arr; / lines.line = MyLine;
The first part of your code makes no sense. The Array class in X++ is a completely different type than your List<line>. That's what the second error message is about.
Where do you get the first error?
Well I tried te below. Yet I can't assign the list or array to my lines.line. As far I know array is non generic but still I cant make it work.
The errors I get it Generic.List
Error Cannot implicitly convert from type 'System.Collections.Generic.List' to type 'System.Collections.Generic.List'1.
Error Cannot implicitly convert from type 'Array' to type 'System.Array'.
Array Arr = new Array (Types::Class); int j = 1; while(j <= 3) { Arr.value(j, this.createline()); j ; } lines.line = Arr; System.Collections.Generic.List MyLine = new System.Collections.Generic.List(); MyLine.Add(this.createline()); MyLine.Add(this.createline()); MyLine.Add(this.createline()); lines.line = MyLine;
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,836
Most Valuable Professional
nmaenpaa
101,156