T
tshad
I am just trying to get my head around passing objects as interfaces or
classes.
If I have the following 3 files:
**********************************
File: IStatusDisplay.cs
public interface IStatusDisplay
{
string Status { get; set; }
string StatusBar { get; set; }
}
File: MapSetup.cs
namespace MapSetup
{
public partial class MapSetup : Form, IStatusDisplay
{
private void ChecktFilesThread()
{
Maintenance.CheckFiles(this);
}
string IStatusDisplay.Status
{
get{return Status.Text;}
set{Status.Text = value;}
}
string IStatusDisplay.StatusBar
{
get{ return toolStripStatusLabel1.Text;}
set{toolStripStatusLabel1.Text = value;}
}
}
Form: Maintenance.cs
public class Maintenance
{
public delegate string FixTablesDelegate(TableFieldList tableFields,
UnmappedNamesCollection unmappedNames,
DataView dv, IStatusDisplay display);
public static void CheckFiles(IStatusDisplay display)
{
string[] strFiles = null;
}
}
*************************************
I find that this is valid whether I have "display" as an:
1) "IStatusDisplay" type, which would only allow me access to "Status" and
"StatusBar", which are a subset of the MapSetup class and would not let me
have access to the Form objects of the MapSetup class.
2) "Form" type, which would let me have access to all the methods and
properties of the Form objects in the MapSetup class which is also a subset
of the MapSetup class and would not let me have access to the "Status" and
"StatusBar" properties of the MapSetup class.
This I understand.
But I can't change the CheckFiles statement to:
public static void CheckFiles(MapStatus display)
I get an error here. But I can't get access to the whole MapStatus object
which consists of both the Form and IStatusDisplay.
Why is that?
It is a type like the interface, isn't it?
By passing "this", I can get access to both the Form and IStatusDisplay
separately. Is there a way to get access to both?
Thanks,
Tom
classes.
If I have the following 3 files:
**********************************
File: IStatusDisplay.cs
public interface IStatusDisplay
{
string Status { get; set; }
string StatusBar { get; set; }
}
File: MapSetup.cs
namespace MapSetup
{
public partial class MapSetup : Form, IStatusDisplay
{
private void ChecktFilesThread()
{
Maintenance.CheckFiles(this);
}
string IStatusDisplay.Status
{
get{return Status.Text;}
set{Status.Text = value;}
}
string IStatusDisplay.StatusBar
{
get{ return toolStripStatusLabel1.Text;}
set{toolStripStatusLabel1.Text = value;}
}
}
Form: Maintenance.cs
public class Maintenance
{
public delegate string FixTablesDelegate(TableFieldList tableFields,
UnmappedNamesCollection unmappedNames,
DataView dv, IStatusDisplay display);
public static void CheckFiles(IStatusDisplay display)
{
string[] strFiles = null;
}
}
*************************************
I find that this is valid whether I have "display" as an:
1) "IStatusDisplay" type, which would only allow me access to "Status" and
"StatusBar", which are a subset of the MapSetup class and would not let me
have access to the Form objects of the MapSetup class.
2) "Form" type, which would let me have access to all the methods and
properties of the Form objects in the MapSetup class which is also a subset
of the MapSetup class and would not let me have access to the "Status" and
"StatusBar" properties of the MapSetup class.
This I understand.
But I can't change the CheckFiles statement to:
public static void CheckFiles(MapStatus display)
I get an error here. But I can't get access to the whole MapStatus object
which consists of both the Form and IStatusDisplay.
Why is that?
It is a type like the interface, isn't it?
By passing "this", I can get access to both the Form and IStatusDisplay
separately. Is there a way to get access to both?
Thanks,
Tom