NArrange.Core.CodeElements.TypeParameter.Clone C# (CSharp) Method

Clone() public method

Creates a clone of this instance.
public Clone ( ) : object
return object
        public object Clone()
        {
            TypeParameter clone = new TypeParameter();

            //
            // Copy state
            //
            clone._name = _name;
            clone.IsIn = IsIn;
            clone.IsOut = IsOut;
            foreach (string constraint in Constraints)
            {
                clone.AddConstraint(constraint);
            }

            return clone;
        }

Usage Example

Example #1
0
        public void CloneTest()
        {
            TypeParameter typeParameter = new TypeParameter();
            typeParameter.Name = "T";
            typeParameter.AddConstraint("IDisposable");
            typeParameter.AddConstraint("new()");

            TypeParameter clone = typeParameter.Clone() as TypeParameter;
            Assert.IsNotNull(clone, "Clone should return a TypeParameter instance.");

            Assert.AreEqual(typeParameter.Name, clone.Name, "Name property was not copied correctly.");
            Assert.AreEqual(typeParameter.Constraints.Count, clone.Constraints.Count, "Constraints property was not copied correctly.");
            Assert.AreEqual(typeParameter.Constraints[0], clone.Constraints[0], "Constraints property was not copied correctly.");
            Assert.AreEqual(typeParameter.Constraints[1], clone.Constraints[1], "Constraints property was not copied correctly.");
        }