Last active
February 28, 2020 22:20
-
-
Save marcelodeandrade/6240753e6458e385b6ab3e291438f9ad to your computer and use it in GitHub Desktop.
Dynamic get/set properties
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
<% | |
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