Trouble is that you can't implement any code in an interface, so you can't create a implicit cast operator!
There is no real solution: Except to declare a "dummy" derived class or a static instance of a derived class that is empty:
public interface IStringType
{
string GetValue();
bool IsSet();
void SetValue(string val);
}
public class ConcreteStringType : IStringType
{
public string GetValue() { return string.Empty; }
}
public void ReadName(IStringType i)
{
string Name = (i ?? new ConcreteStringType()).GetValue();
}
Or
public interface IStringType
{
string GetValue();
bool IsSet();
void SetValue(string val);
}
public class DerivedStringType : IStringType
{
}
public static DerivedStringType inst = new DerivedStringType();
public void ReadName(IStringType i)
{
string Name = (i ?? inst).GetValue();
}
Nasty...