public static bool IsTypeOf(this ITypeSymbol symbol, WellKnownType wellKnownType)
 {
     if (wellKnownType.TryGetSpecialType(out var specialType))
     {
         // Make sure checking the special type is the same as checking the metadata string names.
         Debug.Assert(symbol.IsTypeOf(wellKnownType.GetNamespace(), wellKnownType.GetName()) == (symbol.SpecialType == specialType));
         return(symbol.SpecialType == specialType);
     }
     var(Namespace, Name) = wellKnownType.GetNamespaceAndName();
     return(symbol.IsTypeOf(Namespace, Name));
 }
示例#2
0
        public static TypeDefinition?FindPredefinedType(WellKnownType type, LinkContext context)
        {
            var(ns, name) = type.GetNamespaceAndName();
            foreach (var corlibName in corlibNames)
            {
                AssemblyDefinition?corlib = context.TryResolve(corlibName);
                if (corlib == null)
                {
                    continue;
                }

                TypeDefinition resolvedType = corlib.MainModule.GetType(ns, name);
                // The assembly could be a facade with type forwarders, in which case we don't find the type in this assembly.
                if (resolvedType != null)
                {
                    return(resolvedType);
                }
            }

            return(null);
        }
 public static bool IsTypeOf(this TypeReference tr, WellKnownType type)
 {
     var(@namespace, name) = type.GetNamespaceAndName();
     return(tr.IsTypeOf(@namespace, name));
 }