Recently, I sorted out the ASP/VBScript code and found that an ASP implemented MVC framework in the past was a semi-finished product, and efficiency was also a problem. However, I found that there were some codes I wrote in it, and I felt that I could take it out to meet people, so I wrote this article today to record it.
It is said to be ASP, but it has nothing to do with VBScript. The VBScript language is inherited from Visual Basic. The syntax flexibility of VB is no longer satisfactory. As a subset, VBS can be imagined. Microsoft has introduced advanced technologies such as Shenma Reflection and Introspection in .NET. As an abandoned technology, there is no expectation that Microsoft can provide support, so the stubborn and conservative programmers can only rack their brains to imitate and implement some similar functions.
Well, I admit that for a long time I have been one of the stubborn and conservative schools. Today I am introducing one of the functions, dynamically creating a property object, and the attribute object is called this, that is, the objects created dynamically only contain properties (Properties).
The implementation code is posted below for your reference:
The code copy is as follows:
'
' ASP/VBScript Dynamic Object Generator
' Author: WangYe
' For more information please visit
'
' This code is distributed under the BSD license
'
Const PROPERTY_ACCESS_READONLY = 1
Const PROPERTY_ACCESS_WRITEONLY = -1
Const PROPERTY_ACCESS_ALL = 0
Class DynamicObject
Private m_objProperties
Private m_strName
Private Sub Class_Initialize()
Set m_objProperties = CreateObject("Scripting.Dictionary")
m_strName = "AnonymousObject"
End Sub
Private Sub Class_Terminate()
If Not IsObject(m_objProperties) Then
m_objProperties.RemoveAll
End If
Set m_objProperties = Nothing
End Sub
Public Sub setClassName(strName)
m_strName = strName
End Sub
Public Sub add(key, value, access)
m_objProperties.Add key, Array(value, access)
End Sub
Public Sub setValue(key, value, access)
If m_objProperties.Exists(key) Then
m_objProperties.Item(key)(0) = value
m_objProperties.Item(key)(1) = access
Else
add key,value,access
End If
End Sub
Private Function getReadOnlyCode(strKey)
Dim strPrivateName, strPublicGetName