PropertySet

Namespace: Gallio
We found 10 examples in language CSharp for this search. You will see 29 fragments of code.

        [Test]
        public void Copy()
        {
            PropertySet original = new PropertySet();
            original.Add("abc", "123");
            original.Add("def", "");

            PropertySet copy = original.Copy();

            Assert.AreNotSame(original, copy);
            AssertAreEqual(original, copy);
        }

        [Test]
        public void AsReadOnly()
        {
            PropertySet original = new PropertySet();
            original.Add("abc", "123");

            PropertySet readOnly = original.AsReadOnly();
            Assert.IsTrue(readOnly.IsReadOnly);
            AssertAreEqual(original, readOnly);

            MbUnit.Framework.Assert.Throws<NotSupportedException>(delegate { readOnly.Add("def", "456"); });
        }

        private static void AssertAreEqual(PropertySet expected, PropertySet actual)
        {
            Assert.AreEqual(expected.Count, actual.Count);

            foreach (KeyValuePair<string, string> entry in expected)
                Assert.IsTrue(actual.Contains(entry));
        }


        [Test]
        public void Copy()
        {
            PropertySet original = new PropertySet();
            original.Add("abc", "123");
            original.Add("def", "");

            PropertySet copy = original.Copy();

            Assert.AreNotSame(original, copy);
            AssertAreEqual(original, copy);
        }

        [Test]
        public void AsReadOnly()
        {
            PropertySet original = new PropertySet();
            original.Add("abc", "123");

            PropertySet readOnly = original.AsReadOnly();
            Assert.IsTrue(readOnly.IsReadOnly);
            AssertAreEqual(original, readOnly);

            MbUnit.Framework.Assert.Throws<NotSupportedException>(delegate { readOnly.Add("def", "456"); });
        }

        private static void AssertAreEqual(PropertySet expected, PropertySet actual)
        {
            Assert.AreEqual(expected.Count, actual.Count);

            foreach (KeyValuePair<string, string> entry in expected)
                Assert.IsTrue(actual.Contains(entry));
        }

// Copyright 2005-2010 Gallio Project - http://www.gallio.org/
// Portions Copyright 2000-2004 Jonathan de Halleux
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using Gallio.Common;
using Gallio.Common.Collections;

namespace Gallio.Runtime.Extensibility.Schema
{
    /// <summary>
    /// Represents a table of key and value pairs as a sequence of Xml elements whose local name
    /// represents the key and whose text body contains the value.
    /// </summary>
    [Serializable]
    [XmlType(Namespace = SchemaConstants.XmlNamespace)]
    public sealed class KeyValueTable
    {
        private PropertySet propertySet;

        /// <summary>
        /// Creates an empty key value table.
        /// </summary>
        public KeyValueTable()
        {
        }

        /// <summary>
        /// Gets or sets the Xml elements that describe the property entries
        /// during serialization.
        /// </summary>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is null.</exception>
        [XmlAnyElement]
        public XmlElement[] Entries
        {
            get
            {
                XmlDocument doc = new XmlDocument();
                return GenericCollectionUtils.ConvertAllToArray(PropertySet, entry =>
                {
                    XmlElement element = doc.CreateElement(entry.Key, SchemaConstants.XmlNamespace);
                    element.InnerText = entry.Value;
                    return element;
                });
            }
            set
            {
                if (value == null || Array.IndexOf(value, null) >= 0)
                    throw new ArgumentNullException("value");

                PropertySet.Clear();
                foreach (XmlElement element in value)
                {
                    PropertySet.Add(element.LocalName, element.InnerText ?? "");
                }
            }
        }

        /// <summary>
        /// Gets or sets a mutable view of the properties as a property set.
        /// </summary>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is null.</exception>
        [XmlIgnore]
        public PropertySet PropertySet
        {
            get
            {
                if (propertySet == null)
                    propertySet = new PropertySet();
                return propertySet;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");
                propertySet = value;
            }
        }
    }
}


        [Test]
        public void Copy()
        {
            PropertySet original = new PropertySet();
            original.Add("abc", "123");
            original.Add("def", "");

            PropertySet copy = original.Copy();

            Assert.AreNotSame(original, copy);
            AssertAreEqual(original, copy);
        }

        [Test]
        public void AsReadOnly()
        {
            PropertySet original = new PropertySet();
            original.Add("abc", "123");

            PropertySet readOnly = original.AsReadOnly();
            Assert.IsTrue(readOnly.IsReadOnly);
            AssertAreEqual(original, readOnly);

            MbUnit.Framework.Assert.Throws<NotSupportedException>(delegate { readOnly.Add("def", "456"); });
        }

        private static void AssertAreEqual(PropertySet expected, PropertySet actual)
        {
            Assert.AreEqual(expected.Count, actual.Count);

            foreach (KeyValuePair<string, string> entry in expected)
                Assert.IsTrue(actual.Contains(entry));
        }


        [Test]
        public void Copy()
        {
            PropertySet original = new PropertySet();
            original.Add("abc", "123");
            original.Add("def", "");

            PropertySet copy = original.Copy();

            Assert.AreNotSame(original, copy);
            AssertAreEqual(original, copy);
        }

        [Test]
        public void AsReadOnly()
        {
            PropertySet original = new PropertySet();
            original.Add("abc", "123");

            PropertySet readOnly = original.AsReadOnly();
            Assert.IsTrue(readOnly.IsReadOnly);
            AssertAreEqual(original, readOnly);

            MbUnit.Framework.Assert.Throws<NotSupportedException>(delegate { readOnly.Add("def", "456"); });
        }

        private static void AssertAreEqual(PropertySet expected, PropertySet actual)
        {
            Assert.AreEqual(expected.Count, actual.Count);

            foreach (KeyValuePair<string, string> entry in expected)
                Assert.IsTrue(actual.Contains(entry));
        }


        [Test]
        public void Copy()
        {
            PropertySet original = new PropertySet();
            original.Add("abc", "123");
            original.Add("def", "");

            PropertySet copy = original.Copy();

            Assert.AreNotSame(original, copy);
            AssertAreEqual(original, copy);
        }

        [Test]
        public void AsReadOnly()
        {
            PropertySet original = new PropertySet();
            original.Add("abc", "123");

            PropertySet readOnly = original.AsReadOnly();
            Assert.IsTrue(readOnly.IsReadOnly);
            AssertAreEqual(original, readOnly);

            MbUnit.Framework.Assert.Throws<NotSupportedException>(delegate { readOnly.Add("def", "456"); });
        }

        private static void AssertAreEqual(PropertySet expected, PropertySet actual)
        {
            Assert.AreEqual(expected.Count, actual.Count);

            foreach (KeyValuePair<string, string> entry in expected)
                Assert.IsTrue(actual.Contains(entry));
        }


		/// <summary>Finds a PropertySet the by PropertyInfo.</summary>
		/// <param name = "info">The info.</param>
		/// <returns></returns>
		public PropertySet FindByPropertyInfo(PropertyInfo info)
		{
			return this.FirstOrDefault(prop => info == prop.Property);
		}

		public IEnumerator<PropertySet> GetEnumerator()
		{
			return properties.GetEnumerator();
		}

		void IMutableCollection<PropertySet>.Add(PropertySet property)
		{
			if (property == null)
			{
				throw new ArgumentNullException(nameof(property));
			}
			properties.Add(property);
		}

		bool IMutableCollection<PropertySet>.Remove(PropertySet item)
		{
			return properties.Remove(item);
		}


        public void And(VirtualPropertySet b)
        {
            if (this.ReadOnly)
            {
                throw new InvalidOperationException();
            }
            NormalizeBitArrays(this.PropertySet, b.PropertySet);
            this.PropertySet = this.PropertySet.And(b.PropertySet);
        }

        public VirtualPropertySet AsReadOnly()
        {
            return new VirtualPropertySet { PropertySet = new BitArray(this.PropertySet), ReadOnly = true };
        }

        public bool Equals(VirtualPropertySet other)
        {
            return ((other != null) && this.Equals(other.PropertySet));
        }

        public bool Equals(int propertyId)
        {
            return this.PropertySet[propertyId];
        }

        public void Not()
        {
            if (this.ReadOnly)
            {
                throw new InvalidOperationException();
            }
            this.PropertySet = this.PropertySet.Not();
        }

        public void Or(VirtualPropertySet b)
        {
            if (this.ReadOnly)
            {
                throw new InvalidOperationException();
            }
            NormalizeBitArrays(this.PropertySet, b.PropertySet);
            this.PropertySet = this.PropertySet.Or(b.PropertySet);
        }

// Copyright 2005-2010 Gallio Project - http://www.gallio.org/
// Portions Copyright 2000-2004 Jonathan de Halleux
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using Gallio.Common;
using Gallio.Common.Collections;

namespace Gallio.Runtime.Extensibility.Schema
{
    /// <summary>
    /// Represents a table of key and value pairs as a sequence of Xml elements whose local name
    /// represents the key and whose text body contains the value.
    /// </summary>
    [Serializable]
    [XmlType(Namespace = SchemaConstants.XmlNamespace)]
    public sealed class KeyValueTable
    {
        private PropertySet propertySet;

        /// <summary>
        /// Creates an empty key value table.
        /// </summary>
        public KeyValueTable()
        {
        }

        /// <summary>
        /// Gets or sets the Xml elements that describe the property entries
        /// during serialization.
        /// </summary>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is null.</exception>
        [XmlAnyElement]
        public XmlElement[] Entries
        {
            get
            {
                XmlDocument doc = new XmlDocument();
                return GenericCollectionUtils.ConvertAllToArray(PropertySet, entry =>
                {
                    XmlElement element = doc.CreateElement(entry.Key, SchemaConstants.XmlNamespace);
                    element.InnerText = entry.Value;
                    return element;
                });
            }
            set
            {
                if (value == null || Array.IndexOf(value, null) >= 0)
                    throw new ArgumentNullException("value");

                PropertySet.Clear();
                foreach (XmlElement element in value)
                {
                    PropertySet.Add(element.LocalName, element.InnerText ?? "");
                }
            }
        }

        /// <summary>
        /// Gets or sets a mutable view of the properties as a property set.
        /// </summary>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is null.</exception>
        [XmlIgnore]
        public PropertySet PropertySet
        {
            get
            {
                if (propertySet == null)
                    propertySet = new PropertySet();
                return propertySet;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");
                propertySet = value;
            }
        }
    }
}

        public override void Up()
        {
            DropForeignKey("dbo.PropertySet", "Catalog_Id", "dbo.Catalog");
            DropForeignKey("dbo.PropertySet", "CatalogId", "dbo.Catalog");
            DropForeignKey("dbo.Category", "PropertySetId", "dbo.PropertySet");
            DropForeignKey("dbo.Catalog", "PropertySetId", "dbo.PropertySet");
            DropIndex("dbo.PropertySet", new[] { "CatalogId" });
            DropIndex("dbo.PropertySet", new[] { "Catalog_Id" });
            AddForeignKey("dbo.Category", "PropertySetId", "dbo.PropertySet", "Id", cascadeDelete: true);
            AddForeignKey("dbo.Catalog", "PropertySetId", "dbo.PropertySet", "Id", cascadeDelete: true);
            DropColumn("dbo.PropertySet", "CatalogId");
            DropColumn("dbo.PropertySet", "Catalog_Id");
        }
        
        public override void Down()
        {
            AddColumn("dbo.PropertySet", "Catalog_Id", c => c.String(maxLength: 128));
            AddColumn("dbo.PropertySet", "CatalogId", c => c.String(maxLength: 128));
            DropForeignKey("dbo.Catalog", "PropertySetId", "dbo.PropertySet");
            DropForeignKey("dbo.Category", "PropertySetId", "dbo.PropertySet");
            CreateIndex("dbo.PropertySet", "Catalog_Id");
            CreateIndex("dbo.PropertySet", "CatalogId");
            AddForeignKey("dbo.Catalog", "PropertySetId", "dbo.PropertySet", "Id");
            AddForeignKey("dbo.Category", "PropertySetId", "dbo.PropertySet", "Id");
            AddForeignKey("dbo.PropertySet", "CatalogId", "dbo.Catalog", "Id");
            AddForeignKey("dbo.PropertySet", "Catalog_Id", "dbo.Catalog", "Id");
        }

Gallio.Common.Collections.PropertySet : IDictionary

Constructors :

public PropertySet()

Methods :

public Void AddAll(IEnumerable<KeyValuePair<StringString>> collection = )
public PropertySet Copy()
public PropertySet AsReadOnly()
public String GetValue(String key = )
public Void SetValue(String key = , String value = )
public Void MergeWith(PropertySet other = )
public Void Add(KeyValuePair<StringString> item = )
public Void Clear()
public Boolean Contains(KeyValuePair<StringString> item = )
public Void CopyTo(KeyValuePair array = , Int32 arrayIndex = )
public Boolean Remove(KeyValuePair<StringString> item = )
public Int32 get_Count()
public Boolean get_IsReadOnly()
public Boolean ContainsKey(String key = )
public Void Add(String key = , String value = )
public Boolean Remove(String key = )
public Boolean TryGetValue(String key = , String& value = )
public String get_Item(String key = )
public Void set_Item(String key = , String value = )
public ICollection<String> get_Keys()
public ICollection<String> get_Values()
public IEnumerator<KeyValuePair<StringString>> GetEnumerator()
public Boolean Equals(PropertySet other = )
public Boolean Equals(Object obj = )
public Int32 GetHashCode()
public static XmlQualifiedName ProvideXmlSchema(XmlSchemaSet schemas = )
public Type GetType()
public String ToString()

Other methods