All pastes #795754 Raw Edit

Miscellany

public text v1 · immutable
#795754 ·published 2007-11-24 12:39 UTC
rendered paste body
	public interface IItemsCollectionReadOnly<TKey, TValue>
	{
		TValue this[TKey Key] { get; }
		bool ContainsKey( TKey Key );
		bool TryGetValue( TKey key, out TValue Value );
		bool Contains( KeyValuePair<TKey, TValue> Pair );
		void CopyTo( KeyValuePair<TKey, TValue>[] Array, int ArrayIndex );
		int Count { get; }
		bool IsReadOnly { get; }
		ICollection<TKey> Keys { get; }
		ICollection<TValue> Values { get; }
		IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator();
		Item FindItemByPath( string Path );
	}
	public interface IItemsCollection<TKey, TValue> : IItemsCollectionReadOnly<TKey, TValue>
	{
		new TValue this[TKey Key] { get; set; }
		void Add( TKey Key, TValue Value );
		void Add( KeyValuePair<TKey, TValue> Pair );
		bool Remove( TKey Key );
		bool Remove( KeyValuePair<TKey, TValue> Pair );
		void Clear();
	}
	/// <summary>
	/// Collection of items
	/// </summary>
	public class ItemsCollection : IItemsCollection<Item, Dictionary<string, List<Version>>>, IXmlSerializable
	{
		private Dictionary<Item, Dictionary<string, List<Version>>> items = new Dictionary<Item, Dictionary<string, List<Version>>>();



    public interface IReadOnlyCollection<TKey, TValue>
    {
        bool TryGetValue(TKey key, out TValue value);
    }
    public class MyCollection<TKey, TValue>
        : Dictionary<TKey, TValue>, IReadOnlyCollection<TKey, TValue>
    { }
    public class MyClass
    {
        private MyCollection<int, string> _myCollection;
        public IReadOnlyCollection<int, string> MyCollection
        {
            get
            {
                return _myCollection;
            }
        }
        private void PrivateMethod()
        {
            _myCollection.Add(1, "test");
        }
    }
    public class SomeClass
    {
        private void SomeMethod()
        {
            MyClass myClass = new MyClass();
            string s;
            myClass.MyCollection.TryGetValue(1, out s);
        }
    }