Page 1 of 1
Assign property by reference
Posted: Mon Sep 02, 2019 2:49 pm
by wriedmann
Hi,
I have a LOT of such statements in one of my X# applications:
Code: Select all
if oRow:HasRow( "produkt" )
self:Produkt := oRow:GetString( "produkt" )
endif
Hoping to simplify that code I have tried to pass the property by reference, but in C# this is not allowed ( and therefore it is also not allowed in X#). Strangely VB.NET allows this....
The only possibility seems to be to use Reflection.
Maybe someone of you has a better idea how to solve this with an one-liner, without using Reflection.
Wolfgang
Assign property by reference
Posted: Mon Sep 02, 2019 3:05 pm
by robert
Wolfgang,
Have you tried the preprocessor:
Something like
Code: Select all
#command GETSTRING <oObject> <cColname> => IF <oObject>:HasRow(<(cColName)> ) ;;
SELF:<cColName> := <oObject>:GetRow(<(cColName)> ) ; ENDIF
Robert
Assign property by reference
Posted: Mon Sep 02, 2019 3:15 pm
by wriedmann
Hi Robert,
thank you yery much!
This command works:
Code: Select all
#command SETSTRING <oProperty> <oRow> <cColname> => IF <oRow>:HasRow(<(cColName)> ) ;;
<oProperty> := <oRow>:GetString(<(cColName)> ) ; endif
and the relative code:
Code: Select all
SetString self:Produkt oRow "produkt"
Thank you very much!
Wolfgang
Assign property by reference
Posted: Mon Sep 02, 2019 3:32 pm
by wriedmann
Hi Robert,
this the entire method now:
- FillFromDataRow.png (15.45 KiB) Viewed 495 times
The statement has not only the advantage to keep the code shorter and much more readable, but also to make it more robust in case of future changes - it is much less error prone.
Thank you again!
Wolfgang
Assign property by reference
Posted: Mon Sep 02, 2019 3:39 pm
by robert
Wolfgang,
Nice.
And if you had used Visual Studio, then the UDC keywords SetInt, SetString etc would have been shown in the keyword color.
Robert
Assign property by reference
Posted: Mon Sep 02, 2019 3:44 pm
by Chris
robert wrote:
Nice.
And if you had used Visual Studio, then the UDC keywords SetInt, SetString etc would have been shown in the keyword color.
Wolfgang knows how to do this in XIDE as well
Assign property by reference
Posted: Tue Sep 03, 2019 7:10 am
by wriedmann
Hi Robert,
Visual Studio has several advantages over XIDE - I'm aware of that.
But for me the speed and some of the advantages of XIDE over Visual Studio are much more important, so I prefer to continue with XIDE.
And personally I see it as a big advantage that X# has also its own IDE, specially for people coming from VO.
Wolfgang
Assign property by reference
Posted: Tue Sep 03, 2019 8:50 am
by robert
Wolfgang,
I know. I was just teasing...
Robert