Alternatives to nested interfaces (not possible in C#)

Posted by ericdes on Stack Overflow See other posts from Stack Overflow or by ericdes
Published on 2010-02-18T08:43:00Z Indexed on 2010/05/10 18:34 UTC
Read the original article Hit count: 259

Filed under:
|

I'm using interfaces in this case mostly as a handle to an immutable instance of an object. The problem is that nested interfaces in C# are not allowed. Here is the code:

public interface ICountry
{
    ICountryInfo Info { get; }

    // Nested interface results in error message:
    // Error    13  'ICountryInfo': interfaces cannot declare types
    public interface ICountryInfo
    {
        int Population { get; }
        string Note { get; }
    }
}


public class Country : ICountry
{
    CountryInfo Info { get; set; }

    public class CountryInfo : ICountry.ICountryInfo
    {
        int Population { get; set; }
        string Note { get; set; }
        .....
    }
    .....
}

I'm looking for an alternative, anybody would have a solution?

© Stack Overflow or respective owner

Related posts about c#

Related posts about interfaces