C#. Check if Type is .NET Framework, not my own type
See the question and my original answer on StackOverflowIf you want to check an assembly is published by Microsoft, you could do something like this:
public static bool IsMicrosoftType(Type type)
{
if (type == null)
throw new ArgumentNullException("type");
if (type.Assembly == null)
return false;
object[] atts = type.Assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true);
if ((atts == null) || (atts.Length == 0))
return false;
AssemblyCompanyAttribute aca = (AssemblyCompanyAttribute)atts[0];
return aca.Company != null && aca.Company.IndexOf("Microsoft Corporation", StringComparison.OrdinalIgnoreCase) >= 0;
}
It's not bullet proof as anyone could add such an AssemblyCompany attribute to a custom assembly, but it's a start. For more secure determination, you would need to check Microsoft's authenticode signature from the assembly, like what's done here: Get timestamp from Authenticode Signed files in .NET