Q: Default getter for IList I'm getting started building a C# application, and I've run into a bit of a thorn in the eye:
Most of my classes have a bunch of properties, like this:
private IList<Address> _addresses;
private IList<Phone> _phones;

public virtual IList<Address> Addresses
{
    get
    {
        if (_addresses == null)
            _addresses = new List<Address>();
        return _addresses;
    }
    set { _addresses = value; }
}
public virtual IList<Phone> Phones
{
    get
    {
        if (_phones == null)
            _phones = new List<Phone>();
        return _phones;
    }
    set { _phones = value; }
}

I was wondering, is there a way to define this kind of behavior (Specifically, the default getter) in one place, and reuse that? Should I extend IList somehow?
Just like I can use 
public virtual string Temp { get; set; }

Instead of:
private string _temp;
public virtual string Temp
{
    get { return _temp; }
    set { _temp = value; }
}


A: You can do with a List<T> exactly what you do with a string. The issue that you are probably running into is that in both cases the property is null until you assign a value, thus the if statement in the getter.
You won't be able to resolve this by extending IList.
You can initialize the backing field:
private IList<Thing> _things = new List<Thing>();

In the next version of C#, you'll actually be able to initialize an auto-property in the same way. The syntax takes a little getting used to:
public IList<Thing> Things { get; set; } = new List<Thing>();

You could also use this syntax in your getter to initialize the collection on first call to the getter:
get { return _things ?? (_things = new List<Thing()); }

Finally, you can assign the values to auto-properties in your constructor. This may be more prone to error, as the declaration and assignment have no visible connection.

A: The shortest way currently to do this would be:
public static List<int> _list;

public static List<int> List
{
    get { return _list ?? (_list = new List<int>()); }
    set { _list = value; }
}

Which initializes _list if it's null, and otherwise returns the _list field.

A: You could initialize your fields:
private IList<Address> _addresses = new List<Address>();
private IList<Phone> _phones= new List<Phone>();

Or set the properties in the constructor:
//constructor
public MyClass()
{
    Addresses = new List<Address>();
    Phones = new List<Phone>();
}

These aren't exactly the same the same as your code, though. In your case, if the properties are never called, they will never be initialized.

A: In the uppcoming C# 6 you can do the following:
public virtual IList<Address> Addresses { get; set; } = new List<Address>(); 
public virtual IList<Phone> Phones { get; set; } = new List<Phone>();

for now you could use auto-properties and a default contructor to make it shorter:
public virtual IList<Address> Addresses { get; set; }; 
public virtual IList<Phone> Phones { get; set; };

public CLASS()
{
    Addresses = new List<Address>();
    Phones = new List<Phone>()
}

NOTE: Both solutions will initialize the lists immediatly and not on first access. If that is not wanted I think you can use PostSharp for such stuff.

Should I extend IList somehow?

This would not help, as in case of a "non initialized field" your custom implementation would not even be "there yet".

A: I would make a static helper function while waiting for C# 6, that is how it's done in my MVVM framework of choice. I think this is a fairly general implementation, more overloads could be added to handle corner cases.
public static class PropertyHelper
{
    public static T Get<T, U>(ref T backingField, U initialValue = null)
        where T : class
        where U : class, T, new()
    {
        initialValue = initialValue ?? new U();
        return backingField ?? (backingField = initialValue);
    }
}

public class MyClass
{
    private IList<int> myVar;

    public IList<int> MyProperty
    {
        get { return PropertyHelper.Get<IList<int>, List<int>>(ref myVar); }
        set { myVar = value; }
    }

    private IList<int> myVar2;

    public IList<int> MyProperty2
    {
        get { return PropertyHelper.Get(ref myVar2, new List<int>()); }
        set { myVar2 = value; }
    }
}

