我正在使用自定义类在方法之间传递数据。主要功能之一是图像处理,因此我有一个图像路径和一个自定义拇指路径作为我的类的属性。我想使用System.IO.Path
类中包含的方法作为属性的一部分,但我似乎不能这样做。
我知道如何通过使用string
类型而不是类型来使其工作,System.IO.Path
所以我不需要任何人告诉我如何做到这一点。我只是认为能够声明我ImagePath
的 asSystem.IO.Path
会容易得多,因为我可以在我的财产上使用这些Path
方法。ImagePath
我一定对声明类型有一些了解,我希望我能从这个问题中学习。
类是如何定义的:
Public Class myClass
'structured information which will be passed to a replicator
Public Property ID As Integer
Public Property ImagePath As System.IO.Path '<== this doesn't work
Public Property ThumbPath As System.IO.Path '<== this doesn't work
Public Property GroupID As Byte
Public Property SystemID As Byte
Public Property Comment As String
'Other properties
End Class
我想如何使用这个类:
Public Function myReplicatorFunc(myObj as myClass)
Dim myTempPath as string
Dim myDBObj as myDBConnection
'handle database connections
myTempPath = myObj.ImagePath.GetDirectoryName() & "\" _
myDBObj.GetIntID.toString() & "\" _
myObj.ImagePath.GetExtension()
My.Computer.FileSystem.RenameFile(myObj.ThumbPath.toString, myTempPath)
'Other file movements for replication etc
End Function
为什么我不能将属性声明为 System.IO.Path 类?如果由于某种原因答案只是“否”(请解释原因),那么我如何使用这些System.IO.Path
方法作为我的属性的扩展,而不用重写为具有相同方法的精确副本的自定义类?