Created
September 14, 2012 17:55
-
-
Save kcargile/3723535 to your computer and use it in GitHub Desktop.
.NET Converts the specified collection to an array without references to dynamically generated proxies.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Extensions | |
{ | |
/// <summary> | |
/// Extension methods for classes that implement the <see cref="IEnumerable"/> interface. | |
/// </summary> | |
public static class IEnumerableExtensions | |
{ | |
/// <summary> | |
/// Converts the collection to an array that is guaranteed not to be proxied. | |
/// </summary> | |
/// <typeparam name="TU">The type of the U.</typeparam> | |
/// <param name="source">The source.</param> | |
/// <returns>An array of the specified type.</returns> | |
public static TU[] ToNonProxiedArray<TU>(this IEnumerable<TU> source) where TU : ICloneable | |
{ | |
int ct = source.Count(); | |
IList<TU> sourceList = source.ToList(); | |
TU[] final = new TU[ct]; | |
for (int i = 0; i < ct; i++) | |
{ | |
final[i] = (TU)sourceList[i].Clone(); | |
} | |
return final; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment