Mega Code Archive

 
Categories / C# / Reflection
 

Determine if a type is cloneable

//****************************** // Written by Peter Golde // Copyright (c) 2004-2007, Wintellect // // Use and restribution of this code is subject to the license agreement  // contained in the file "License.txt" accompanying this file. //****************************** using System; using System.Collections; using System.Collections.Generic; namespace Wintellect.PowerCollections {   /// <summary>   /// A holder class for various internal utility functions that need to be shared.   /// </summary>     internal static class Util     {         /// <summary>         /// Determine if a type is cloneable: either a value type or implementing         /// ICloneable.         /// </summary>         /// <param name="type">Type to check.</param>         /// <param name="isValue">Returns if the type is a value type, and does not implement ICloneable.</param>         /// <returns>True if the type is cloneable.</returns>         public static bool IsCloneableType(Type type, out bool isValue)         {             isValue = false;             if (typeof(ICloneable).IsAssignableFrom(type)) {                 return true;             }             else if (type.IsValueType) {                 isValue = true;                 return true;             }             else                 return false;         }     } }