Skip to content

Instantly share code, notes, and snippets.

@RickStrahl
Last active November 23, 2018 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickStrahl/345718192cc6ccd65a636109e785d314 to your computer and use it in GitHub Desktop.
Save RickStrahl/345718192cc6ccd65a636109e785d314 to your computer and use it in GitHub Desktop.
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
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 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