+2  A: 

You'd likely find it easier to use params in the definition for the Slot constructor:

Slot(params Loot[] exclusiveLootTypes)

This would allow you to call it like:

new Slot(lootItem1, lootItem2, lootItem2 /*...etc*/);

Otherwise, you'd need to create an array and pass it in.

Anon.
I was hoping to deal with it this way, but this only allows me to use instances, not types. The above new Slot(lootItem1...) would be passing existing instances. I want to pass types, like:<pre><code>new Slot(Quiver, ShotPouch);</code></pre>where Quiver and ShotPouch would be subclasses of Loot.
Superstringcheese
+1  A: 

One approach would be to pass an array of Type objects to the Slot constructor:

public Slot(Type[] exclusiveLootTypes) {
    // be sure and check that each Type is a subtype of Loot!
}

// Construction looks like:
new Slot(new[] {GetType(AmmoContainer), GetType(GemContainer) /* or whatever */});

Then write a property setter for Content that checks the type of the assigned object, and signals some sort of error if that type isn't contained in ExclusiveLootTypes.

David Seiler
+1  A: 

and to combine the previous suggestion to use params, you can use a LINQ extension to convert the params into a List in one step:

public Slot(params Type[] exclusiveLootTypes)
{
    this.Content = null;
    this.Count = 0;

    this.ExclusiveLootTypes = exclusiveLootTypes.ToList();
}
charoco
+2  A: 

It sounds like your object design needs a slight adjustment.

What if the types of loot items were also interfaces, so for example, all ammo loot items inherit from IAmmoContainer.

Then you could pass in the IAmmoContainer type to restrict the slot.

public class Quiver : Container, IAmmoContainer
public class ShotPouch : Container, IAmmoContainer
// ...
new Slot(typeof(IAmmoContainer))

EDIT

Based on the discussion in the comments, here's how I'd go about designing this system.

The Loot class is fine. It represents the base of the loot hierarchy.

Then you define interfaces for the "slots" that an item can occupy. For example:

public class LongSword : Loot, IRightHandItem
public class ShortSword : Loot, IRightHandItem, ILeftHandItem

Then the PlayerInventory class has "slots" as properties, that are restricted to the appropriate type.

public class PlayerInventory
{
    public List<IRightHandItem> RightHandSlot { get; private set; }
    public List<ILeftHandItem> LeftHandSlot { get; private set; }
    // etc...
}
Cameron MacFarland
Slots.Add(new Slot(IAmmoBag), "Backpack"); gives the error: "Argument '1': cannot convert from 'System.Type' to (namespace).Loot[]'.
Superstringcheese
OK, now I'm really confused. So your slot already contains an instance of the types it can contain? Are you trying to restrict the types added to a slot or pre-initialize the slot with the types already?
Cameron MacFarland
Initially - at this point - no, the slot contains nothing (its Content variable which holds a Loot type currently == null.) What I'm trying to do is say that if there are ANY items in the List<Loot> ExclusiveLootTypes, then the slot will run validation (when I code it) to ensure that the Content variable ONLY receives item which subclasses one of the Types in List<Loot> ExclusiveLootTypes.So, I want to create the Slot, and pass a number of subclasses of Loot to it, and then it will add those types to the List<Loot> ExclusiveLootTypes.
Superstringcheese
To clarify, I don't want the pass instances of classes to the Slot, I want to pass subclasses of the abstract class Loot. The slot will then ensure that its Content variable will only get filled by instances which are of the subclass(es) listed in the List<Loot> ExclusiveLootTypes.
Superstringcheese
@your Edit: I don't think this represents what I'm trying to accomplish. In this approach, a PlayerInventory would have a container (List<IRightHandItem> RightHandSlot) which would hold any number of, say, LongSwords simultaneously. Your version of the RightHand "slot" is more like a bag. I defined a Slot as a container which can ONLY hold ONE item - be it a bag, or a sword, or whatever. That one item it can hold can be restricted by it's type. So the RightHand slot will only hold one item; the TYPE of that item - which subclass of Loot it is, is defined in the Slot's ExclusiveLootType list.
Superstringcheese