Created
May 12, 2010 01:51
-
-
Save hugoware/398099 to your computer and use it in GitHub Desktop.
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
/// <summary> | |
/// Attempts to identify an anonymous value using the type name and a variety of common traits | |
/// (Unlikely this is the best way to determine) | |
/// </summary> | |
public static bool IsAnonymousType(object value) { | |
//make sure this has a value | |
if (value == null) { return false; } | |
//check if this is anonymous type using the name and | |
//some values that hint it might be anonymous - This | |
//could probably be better though if a better way of | |
//checking for anonymous types becomes available | |
Type type = value.GetType(); | |
return Regex.IsMatch(type.FullName, "^(<>f__AnonymousType|VB\\$AnonymousType)") && | |
type.IsSealed && | |
type.IsGenericType && | |
type.BaseType.Equals(typeof(object)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment