Assign property by reference

This forum is meant for anything you would like to share with other visitors
Post Reply
User avatar
wriedmann
Posts: 3756
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Assign property by reference

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4529
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Assign property by reference

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3756
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Assign property by reference

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 3756
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Assign property by reference

Post by wriedmann »

Hi Robert,

this the entire method now:
FillFromDataRow.png
FillFromDataRow.png (15.45 KiB) Viewed 522 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4529
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Assign property by reference

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Chris
Posts: 4922
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Assign property by reference

Post 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 :)
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3756
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Assign property by reference

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
robert
Posts: 4529
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Assign property by reference

Post by robert »

Wolfgang,

I know. I was just teasing...

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply