473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Setting Objects Equal to an Object of Base Class

I am extending FileSystemInfo class so that I can Implement Icomparable. My
custom class looks like:

Class FSFileSystemInfo
Inherits FileSystemInfo : Implements Icomparable
Function CompareTo(ByVal o As Object) As Integer _
Implements IComparable.CompareTo

My issue comes when I try to set an instance of FSFileSystemInfo to an
object that is FileSystemInfo type. Such as:

Dim DirInfo As New DirectoryInfo("./")
Dim FSInfo() As FSFileSystemInfo
DirInfo = New DirectoryInfo(Server.MapPath(".\"))
FSInfo = DirInfo.GetFileSystemInfos("*-*.pdf") //THIS FAILS

I get a Cast Error when I do the previous statment and I am unsure how to
cast one object into another within VB.NET. Thanks for any help in advance.
Feb 19 '06 #1
4 1569
The DirInfo.GetFileSystemInfos method is returning an object of the
FileSystemInfo type whereas you are attempting to assign it to a vaiable of
the FSFileSystemInfo
type. You need to convert the FileSystemInfo object to a FSFileSystemInfo
object.

Try:

FSInfo = CType(DirInfo.GetFileSystemInfos("*-*.pdf"), FSFileSystemInfo)
"FacultasNetDeveloper" <da**********@hotmail.com> wrote in message
news:77**********************************@microsof t.com...
I am extending FileSystemInfo class so that I can Implement Icomparable. My
custom class looks like:

Class FSFileSystemInfo
Inherits FileSystemInfo : Implements Icomparable
Function CompareTo(ByVal o As Object) As Integer _
Implements IComparable.CompareTo

My issue comes when I try to set an instance of FSFileSystemInfo to an
object that is FileSystemInfo type. Such as:

Dim DirInfo As New DirectoryInfo("./")
Dim FSInfo() As FSFileSystemInfo
DirInfo = New DirectoryInfo(Server.MapPath(".\"))
FSInfo = DirInfo.GetFileSystemInfos("*-*.pdf") //THIS FAILS

I get a Cast Error when I do the previous statment and I am unsure how to
cast one object into another within VB.NET. Thanks for any help in
advance.

Feb 19 '06 #2
Thanks Stephany,

I tried the following and still get an error.
FSInfo = CType(DirInfo.GetFileSystemInfos("*-*.pdf"), FSFileSystemInfo())
Since FSInfo is an array I assume I will have to convert the array of
FileSystemInfo objects returned by GetFileSystemInfos into an array of
FSFileSystemInfo Objects. However this still seems to yeild

Unable to cast object of type 'System.IO.FileSystemInfo[]'
to type 'FSFileSystemInfo[]'.

"Stephany Young" wrote:
The DirInfo.GetFileSystemInfos method is returning an object of the
FileSystemInfo type whereas you are attempting to assign it to a vaiable of
the FSFileSystemInfo
type. You need to convert the FileSystemInfo object to a FSFileSystemInfo
object.

Try:

FSInfo = CType(DirInfo.GetFileSystemInfos("*-*.pdf"), FSFileSystemInfo)
"FacultasNetDeveloper" <da**********@hotmail.com> wrote in message
news:77**********************************@microsof t.com...
I am extending FileSystemInfo class so that I can Implement Icomparable. My
custom class looks like:

Class FSFileSystemInfo
Inherits FileSystemInfo : Implements Icomparable
Function CompareTo(ByVal o As Object) As Integer _
Implements IComparable.CompareTo

My issue comes when I try to set an instance of FSFileSystemInfo to an
object that is FileSystemInfo type. Such as:

Dim DirInfo As New DirectoryInfo("./")
Dim FSInfo() As FSFileSystemInfo
DirInfo = New DirectoryInfo(Server.MapPath(".\"))
FSInfo = DirInfo.GetFileSystemInfos("*-*.pdf") //THIS FAILS

I get a Cast Error when I do the previous statment and I am unsure how to
cast one object into another within VB.NET. Thanks for any help in
advance.


Feb 19 '06 #3
Sorry ... Missed the array and ended up putting you crook.

I'm going to have to ask you at this stage, what sort of operations are you
going to be carrying out with your FSFileSystemInfo class.

The reason I ask is that implementing your class is going to be fraught with
difficulty for reasons that include:

- FileSystemInfo is the base class for the DirectoryInfo and
FileInfo classes.

- DirectoryInfo.GetFileSystemInfos returns an array that can be
a mixture of DirectoryInfo and FileInfo objects.

- You will not be able to deal with the returned DirectoryInfo and
FileInfo objects unless you create your own classes that derive
from FSFileSystemInfo.

If you are looking to get a list of files in a directory that match a given
pattern and sort them, then you do not need to go to all this trouble.

Instead you can use the shared Directory.GetFiles(string, string) overloaded
method to return a string array of the matching files and then use one of
the shared Array.Sort overloaded methods to sort the aray, with or woithout
an IComparer as required.
"FacultasNetDeveloper" <da**********@hotmail.com> wrote in message
news:30**********************************@microsof t.com...
Thanks Stephany,

I tried the following and still get an error.
FSInfo = CType(DirInfo.GetFileSystemInfos("*-*.pdf"), FSFileSystemInfo())
Since FSInfo is an array I assume I will have to convert the array of
FileSystemInfo objects returned by GetFileSystemInfos into an array of
FSFileSystemInfo Objects. However this still seems to yeild

Unable to cast object of type 'System.IO.FileSystemInfo[]'
to type 'FSFileSystemInfo[]'.

"Stephany Young" wrote:
The DirInfo.GetFileSystemInfos method is returning an object of the
FileSystemInfo type whereas you are attempting to assign it to a vaiable
of
the FSFileSystemInfo
type. You need to convert the FileSystemInfo object to a FSFileSystemInfo
object.

Try:

FSInfo = CType(DirInfo.GetFileSystemInfos("*-*.pdf"), FSFileSystemInfo)
"FacultasNetDeveloper" <da**********@hotmail.com> wrote in message
news:77**********************************@microsof t.com...
>I am extending FileSystemInfo class so that I can Implement Icomparable.
>My
> custom class looks like:
>
> Class FSFileSystemInfo
> Inherits FileSystemInfo : Implements Icomparable
> Function CompareTo(ByVal o As Object) As Integer _
> Implements IComparable.CompareTo
>
> My issue comes when I try to set an instance of FSFileSystemInfo to an
> object that is FileSystemInfo type. Such as:
>
> Dim DirInfo As New DirectoryInfo("./")
> Dim FSInfo() As FSFileSystemInfo
> DirInfo = New DirectoryInfo(Server.MapPath(".\"))
> FSInfo = DirInfo.GetFileSystemInfos("*-*.pdf") //THIS FAILS
>
> I get a Cast Error when I do the previous statment and I am unsure how
> to
> cast one object into another within VB.NET. Thanks for any help in
> advance.
>
>


Feb 19 '06 #4
That's it. I just got off on a wrong foot. thanks!

"Stephany Young" wrote:
Sorry ... Missed the array and ended up putting you crook.

I'm going to have to ask you at this stage, what sort of operations are you
going to be carrying out with your FSFileSystemInfo class.

The reason I ask is that implementing your class is going to be fraught with
difficulty for reasons that include:

- FileSystemInfo is the base class for the DirectoryInfo and
FileInfo classes.

- DirectoryInfo.GetFileSystemInfos returns an array that can be
a mixture of DirectoryInfo and FileInfo objects.

- You will not be able to deal with the returned DirectoryInfo and
FileInfo objects unless you create your own classes that derive
from FSFileSystemInfo.

If you are looking to get a list of files in a directory that match a given
pattern and sort them, then you do not need to go to all this trouble.

Instead you can use the shared Directory.GetFiles(string, string) overloaded
method to return a string array of the matching files and then use one of
the shared Array.Sort overloaded methods to sort the aray, with or woithout
an IComparer as required.
"FacultasNetDeveloper" <da**********@hotmail.com> wrote in message
news:30**********************************@microsof t.com...
Thanks Stephany,

I tried the following and still get an error.
FSInfo = CType(DirInfo.GetFileSystemInfos("*-*.pdf"), FSFileSystemInfo())
Since FSInfo is an array I assume I will have to convert the array of
FileSystemInfo objects returned by GetFileSystemInfos into an array of
FSFileSystemInfo Objects. However this still seems to yeild

Unable to cast object of type 'System.IO.FileSystemInfo[]'
to type 'FSFileSystemInfo[]'.

"Stephany Young" wrote:
The DirInfo.GetFileSystemInfos method is returning an object of the
FileSystemInfo type whereas you are attempting to assign it to a vaiable
of
the FSFileSystemInfo
type. You need to convert the FileSystemInfo object to a FSFileSystemInfo
object.

Try:

FSInfo = CType(DirInfo.GetFileSystemInfos("*-*.pdf"), FSFileSystemInfo)
"FacultasNetDeveloper" <da**********@hotmail.com> wrote in message
news:77**********************************@microsof t.com...
>I am extending FileSystemInfo class so that I can Implement Icomparable.
>My
> custom class looks like:
>
> Class FSFileSystemInfo
> Inherits FileSystemInfo : Implements Icomparable
> Function CompareTo(ByVal o As Object) As Integer _
> Implements IComparable.CompareTo
>
> My issue comes when I try to set an instance of FSFileSystemInfo to an
> object that is FileSystemInfo type. Such as:
>
> Dim DirInfo As New DirectoryInfo("./")
> Dim FSInfo() As FSFileSystemInfo
> DirInfo = New DirectoryInfo(Server.MapPath(".\"))
> FSInfo = DirInfo.GetFileSystemInfos("*-*.pdf") //THIS FAILS
>
> I get a Cast Error when I do the previous statment and I am unsure how
> to
> cast one object into another within VB.NET. Thanks for any help in
> advance.
>
>


Feb 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: K.K. | last post by:
Suppose I have a class called Vehicle with many fields. Now I make a new class derived from Vehicle called Car. I'd like to make a method to copy the data from a Vehicle instance to a Car instance....
0
by: Cat | last post by:
I have class Base, and class Derived. I am serializing Derived objects from XML, and these Derived objects are allowed to 'inherit' the values from other named Base objects already defined in...
7
by: Prabhudhas Peter | last post by:
I have two object instances of a same class... and i assigned values in both object instances (or the values can be taken from databse and assigned to the members of the objects)... Now i want to...
161
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.....
15
by: shuisheng | last post by:
Dear All, Assume I have a class named Obj. class Obj { }; And a class named Shape which is derived from Obj. class Shape: public Obj
4
by: =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post by:
Hello, (sorry to begin with Java in a Python list ;-) in Java, when I want to pass input to a function, I pass "InputStream", which is a base class of any input stream. In Python, I found...
15
by: Juha Nieminen | last post by:
I'm sure this is not a new idea, but I have never heard about it before. I'm wondering if this could work: Assume that you have a common base class and a bunch of classes derived from it, and...
3
by: kjell | last post by:
Hi, I wonder if someone may have a solution to a small problem I'm experiencing with a C++ program? I'm have two classes in my application that provides methods for setting parameters in the...
7
by: Yen Kwoon | last post by:
Note: This problem is related to gcc but after some back and forth in group gnu.gcc.help it seems to have morph into more of a c++ specificiation question, hence the transplanting to this group. ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.