-
-
Save AlexLaforge/d0f7d9757c83cdf6886146ca2ec6455d 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