S
SpookyET
I have thought that you can disable a set or a get when you override a
virtual property. I guess that I was wrong. The code below compiles and
doesn't throw the exceptions that I have expected. It calls the base
accessor.
using System;
namespace Test
{
public abstract class MetaDataFile
{
protected string name;
public virtual string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
public class MetaDataFileReader : MetaDataFile
{
public MetaDataFileReader(string name)
{
this.name = name;
}
public override string Name
{
get
{
return name;
}
}
}
public class MetaDataFileWriter : MetaDataFile
{
public override string Name
{
set
{
name = value;
}
}
}
public class Tester
{
public static void Main()
{
MetaDataFile f;
MetaDataFileReader r = new MetaDataFileReader("foobar.torrent");
MetaDataFileWriter w = new MetaDataFileWriter();
r.Name = "test.torrent"; // Should throw a set accessor exception
w.Name = "fooby.torrent";
Console.WriteLine(w.Name); // Should throw a get accessor exception
f = r;
f.Name = "test2.torrent";
}
}
}
virtual property. I guess that I was wrong. The code below compiles and
doesn't throw the exceptions that I have expected. It calls the base
accessor.
using System;
namespace Test
{
public abstract class MetaDataFile
{
protected string name;
public virtual string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
public class MetaDataFileReader : MetaDataFile
{
public MetaDataFileReader(string name)
{
this.name = name;
}
public override string Name
{
get
{
return name;
}
}
}
public class MetaDataFileWriter : MetaDataFile
{
public override string Name
{
set
{
name = value;
}
}
}
public class Tester
{
public static void Main()
{
MetaDataFile f;
MetaDataFileReader r = new MetaDataFileReader("foobar.torrent");
MetaDataFileWriter w = new MetaDataFileWriter();
r.Name = "test.torrent"; // Should throw a set accessor exception
w.Name = "fooby.torrent";
Console.WriteLine(w.Name); // Should throw a get accessor exception
f = r;
f.Name = "test2.torrent";
}
}
}