ISimpleConfiguration接口增加了GetValue方法的重载。
Private Overloads Function GetValue(ByVal [assembly] As System.Reflection.Assembly, ByVal key As String, ByVal defaultValue As Object, ByVal remark As String) As Object Implements ComponentFramework.ISimpleConfiguration.GetValue
可以对Lily.XMLHelper组件中的Lily.XMLHelper.XmlEntity类支持。
下面来看一个简单的示例:
ConfigurationInfo类用于配置文档管理方式,如FTP或LAN。
主要有几个属性:
- ConnectionString
- ConnectionType
- FilePath
首先定义类
Public Class ConfigurationInfo
Inherits Lily.XMLHelper.XmlEntity
Private md_ConnectionString As String = String.Empty
Private md_ConnectionType As String = String.Empty
Private md_FilePath As String = String.Empty
#End Region
<Lily.XMLHelper.XMLAttribute("ConnectionString", "ConnectionString", False, True)> _
Property ConnectionString() As String
Get
Return Me.md_ConnectionString
End Get
Set(ByVal Value As String)
Me.md_ConnectionString = Value
End Set
End Property
<Lily.XMLHelper.XMLAttribute("connectiontype", "ConnectionType")> _
Property ConnectionType() As String
Get
Return Me.md_ConnectionType
End Get
Set(ByVal Value As String)
Me.md_ConnectionType = Value
End Set
End Property
<Lily.XMLHelper.XMLAttribute("FilePath", "FilePath")> _
Property FilePath() As String
Get
Return Me.md_FilePath
End Get
Set(ByVal Value As String)
Me.md_FilePath = Value
End Set
End Property
End Class
从上面可以看出,主要是通过XMLAttribute来进行描述的。第一个参数是节点的名称,第二个参数是属性的名称。用于反射获取或设置属性的值。
定义好配置类后,可以通过以下方法,获取对象。
c = CType(Lily.ComponentFramework.ComponentManager.SimpleConfiguration.GetValue(System.Reflection.Assembly.GetAssembly(GetType(ConfigurationInfo)), "连接类型", New ConfigurationInfo, "工程项目文件管理连接类型配置"), ConfigurationInfo)
c就是强类型的ConfigurationIfno了。红色部份,为什么要实例化一个对象呢,如果当前系统没有定义,则返回默认的配置对象。