コード例 #1
0
        public static TypeReference?TryImportType(this ITypeSystem typeSystem, Type type)
        {
            if (!typeSystem.TryFindType(GetFullName(type), out var typeDefinition))
            {
                return(null);
            }

            return(typeSystem.ModuleDefinition.ImportReference(typeDefinition));
        }
コード例 #2
0
        private static MethodReference?TryImport <T>(this ITypeSystem typeSystem, Type declaringType, string name, Func <TypeDefinition, IEnumerable <T> > elementLookup, Func <T, bool> constraints, Func <T, MethodDefinition> selector)
            where T : class, IMemberDefinition
        {
            if (!typeSystem.TryFindType(GetFullName(declaringType), out var typeDefinition))
            {
                return(null);
            }

            var method = elementLookup(typeDefinition).Where(p => p.Name == name).Where(constraints).Select(selector).SingleOrDefault();

            if (method == null)
            {
                return(null);
            }

            return(typeSystem.ModuleDefinition.ImportReference(method));
        }