Skip to content

Instantly share code, notes, and snippets.

@marcelodeandrade
Last active February 28, 2020 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marcelodeandrade/6240753e6458e385b6ab3e291438f9ad to your computer and use it in GitHub Desktop.
Save marcelodeandrade/6240753e6458e385b6ab3e291438f9ad to your computer and use it in GitHub Desktop.
Dynamic get/set properties
<%
class teste
private abc
private def
private sub class_initialize
end sub
private sub class_terminate
end sub
public property get propertyCollection
propertyCollection = array("abc", "def")
end property
public property get propertyCollectionCount
propertyCollectionCount = uBound(propertyCollection) + 1
end property
public function getValue(propertyName)
checkProperty(propertyName)
getValue = Eval(propertyName)
end function
public function setValue(propertyName, value)
checkProperty(propertyName)
Execute propertyName & " = " & value
end function
public sub checkProperty(propertyName)
If not in_array(propertyName, propertyCollection) Then
Err.Raise 1, "Invalid property """& propertyName &""" "
End If
end sub
public function in_array(needle, haystack)
dim i
in_array = False
For i = 0 To Ubound(haystack)
If trim(haystack(i)) = trim(needle) Then
in_array = True
exit function
End If
Next
end function
end class
set t = new teste
t.setValue "abc", 1
' t.setValue "xxx", 3
response.write "abc = " & t.getValue("abc")
' response.write "xxx = " & t.getValue("xxx")
response.write "<hr>"
response.write t.propertyCollectionCount
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment