Last active
November 23, 2018 06:53
-
-
Save RickStrahl/345718192cc6ccd65a636109e785d314 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO wwDynamic | |
DO wwJsonSerializer | |
CLEAR | |
loCust = CREATEOBJECT("TestClass") | |
loItem = CREATEOBJECT("wwDynamic",loCust) | |
*loItem = CREATEOBJECT("wwDynamic") | |
? loItem.Class | |
loItem.Bogus = "This is bogus" | |
loItem.Entered = DATETIME() | |
? loItem.Bogus | |
? loItem.Entered | |
WITH loItem.Child | |
.Bogus2 = "Child Bogus" | |
.Entered2 = DATETIME() | |
? .Bogus2 | |
? .Entered2 | |
ENDWITH | |
? loItem.cFirstName | |
? loItem.cLastName | |
? loItem.GetFullname() | |
loSer = CREATEOBJECT("wwJsonSerializer") | |
lcJson = loSer.Serialize(loItem,.T.) | |
? lcJson | |
_cliptext = lcJson | |
DEFINE CLASS TestClass as Custom | |
cFirstName = "Rick" | |
cLastName = "Strahl" | |
FUNCTION GetFullName() | |
RETURN this.cFirstname + " " + this.cLastname | |
ENDDEFINE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET PROCEDURE TO wwDynamic ADDITIVE | |
************************************************************* | |
DEFINE CLASS wwDynamic AS RELATION | |
************************************************************* | |
*: original Author: Marco Plaza, 2018 @vfp2nfox | |
*: modified by: Rick Strahl | |
************************************************************* | |
__oReference = null | |
*** Intercept access to unknown properties and create | |
FUNCTION THIS_Access(lcPropertyOrMethod) | |
If Lower(lcPropertyOrMethod) == "__oreference" OR ; | |
Pemstatus(this,lcPropertyOrMethod,5) | |
RETURN this | |
Endif | |
If !Pemstatus(this.__oReference,lcPropertyOrMethod,5) | |
AddProperty(this.__oReference,lcPropertyOrMethod,Createobject('wwDynamic')) | |
ENDIF | |
RETURN this.__oReference | |
ENDFUNC | |
************************************************************************ | |
* Init | |
**************************************** | |
*** Function: | |
*** Assume: | |
*** Pass: | |
*** Return: | |
************************************************************************ | |
FUNCTION Init(loBaseType) | |
IF !VARTYPE(loBaseType) = "O" | |
this.__oReference = CREATEOBJECT("Empty") | |
ELSE | |
this.__oReference = loBaseType | |
ENDIF | |
ENDFUNC | |
* Init | |
ENDDEFINE | |
*EOC wwDynamic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*** This change is required in wwJsonSerializer::WriteValue() to serialize wwDynamic properly | |
*** as DTO objects rather than serializing the dynamic instance itself | |
*** Skip over wwDynamic instance and serialize just the reference | |
CASE lcValueType = "C" AND LOWER(lvValue.Class) = "wwdynamic" | |
this.WriteObject( EVALUATE("lvValue.__oReference")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment