fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Assign property by reference

Assign property by reference 2 months 2 weeks ago #10502

  wriedmann's Avatar Topic Author wriedmann Offline Posts: 1870
Hi,

I have a LOT of such statements in one of my X# applications:
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

www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Last edit: by wriedmann.

Assign property by reference 2 months 2 weeks ago #10503

  robert's Avatar robert Offline Posts: 1324
Wolfgang,
Have you tried the preprocessor:
Something like
#command GETSTRING <oObject> <cColname> => IF <oObject>:HasRow(<(cColName)> ) ;;
                   SELF:<cColName> := <oObject>:GetRow(<(cColName)> ) ; ENDIF

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

Assign property by reference 2 months 2 weeks ago #10504

  wriedmann's Avatar Topic Author wriedmann Offline Posts: 1870
Hi Robert,

thank you yery much!

This command works:
#command SETSTRING <oProperty> <oRow> <cColname> => IF <oRow>:HasRow(<(cColName)> ) ;;
                   <oProperty> := <oRow>:GetString(<(cColName)> ) ; endif
and the relative code:
SetString self:Produkt oRow "produkt"

Thank you very much!

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy

www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Assign property by reference 2 months 2 weeks ago #10505

  wriedmann's Avatar Topic Author wriedmann Offline Posts: 1870
Hi Robert,

this the entire method now:

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

www.riedmann.it - docs.xsharp.it
Attachments:

Please Log in or Create an account to join the conversation.

Assign property by reference 2 months 2 weeks ago #10506

  robert's Avatar robert Offline Posts: 1324
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

Please Log in or Create an account to join the conversation.

Assign property by reference 2 months 2 weeks ago #10507

  Chris's Avatar Chris Offline Posts: 1466

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 :)
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

Assign property by reference 2 months 2 weeks ago #10515

  wriedmann's Avatar Topic Author wriedmann Offline Posts: 1870
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

www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Assign property by reference 2 months 2 weeks ago #10518

  robert's Avatar robert Offline Posts: 1324
Wolfgang,

I know. I was just teasing...

Robert
XSharp Development Team
The Netherlands

Please Log in or Create an account to join the conversation.

  • Page:
  • 1