public override object Serialize(object clrObject, int depth) { CollectionResourceType resourceType = base.ResourceType as CollectionResourceType; if (clrObject as PSObject != null) { clrObject = (clrObject as PSObject).BaseObject; } if (clrObject != null) { Type type = clrObject.GetType(); if (!TypeSystem.ContainsDictionaryInterface(type)) { if (!TypeSystem.ContainsEnumerableInterface(type)) { object[] assemblyQualifiedName = new object[1]; assemblyQualifiedName[0] = type.AssemblyQualifiedName; throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.CollectionSeralizationFailedNotValidCollectionType, assemblyQualifiedName)); } else { return(this.SerializeEnumerable(clrObject as IEnumerable, resourceType, depth)); } } else { return(this.SerializeDictionary(clrObject as IDictionary, resourceType, depth)); } } else { return(this.SerializeEnumerable(null, resourceType, depth)); } }
public static object ConvertTo(this IEnumerable collection, Type convertToType) { if (!TypeSystem.IsArrayType(convertToType)) { if (!TypeSystem.IsStackType(convertToType)) { if (!TypeSystem.IsQueueType(convertToType)) { if (!TypeSystem.ContainsDictionaryInterface(convertToType)) { if (!TypeSystem.ContainsEnumerableInterface(convertToType)) { return(null); } else { return(collection.ToList(convertToType)); } } else { return(collection.ToDictionary(convertToType)); } } else { return(collection.ToQueue(convertToType)); } } else { return(collection.ToStack(convertToType)); } } else { return(collection.ToArray(convertToType)); } }