コード例 #1
0
        private static TypeReference GetBclType(string typeName, ModuleWeaver weaver)
        {
            var type = weaver.FindTypeDefinition(typeName) ?? throw new RuntimeNullablesException($"Unable to find required BCL type '{typeName}'.");

            return(weaver.ModuleDefinition.ImportReference(type));
        }
コード例 #2
0
        private MethodReference GetBclConstructorWithStringParameters(string typeName, int paramCount, ModuleWeaver weaver)
        {
            var typeDefinition = weaver.FindTypeDefinition(typeName) ?? throw new RuntimeNullablesException($"Unable to find required BCL type '{typeName}'.");

            var constructor = typeDefinition.Methods.FirstOrDefault(
                m => m.IsConstructor && m.Parameters.Count == paramCount && m.Parameters.All(p => p.ParameterType.FullName == StringType.FullName));

            if (constructor == null)
            {
                throw new RuntimeNullablesException($"Unable to find required BCL type constructor on '{typeName}'.");
            }

            return(weaver.ModuleDefinition.ImportReference(constructor));
        }