public bool TryGetRoscharConcatMethodWithArity(int arity, [NotNullWhen(true)] out IMethodSymbol?concatMethod) { var roscharParamInfo = ParameterInfo.GetParameterInfo(ReadOnlySpanOfCharType); var argumentList = new ParameterInfo[arity]; for (int index = 0; index < arity; index++) { argumentList[index] = roscharParamInfo; } concatMethod = StringType.GetMembers(nameof(string.Concat)) .OfType <IMethodSymbol>() .GetFirstOrDefaultMemberWithParameterInfos(argumentList); return(concatMethod is not null); }
public SystemTypeSymbols(Compilation compilation) { if (StringType != null) { return; } StringType = compilation.GetTypeByMetadataName(typeof(string).FullName); if (StringType != null) { StringIsNullOrEmpty = StringType.GetMembers("IsNullOrEmpty").OfType <IMethodSymbol>().First(); StringIsNullOrWhiteSpace = StringType.GetMembers("IsNullOrWhiteSpace").OfType <IMethodSymbol>().First(); AddRange(NotNullFrameworkMethods, StringType.GetMembers("Substring").OfType <IMethodSymbol>()); AddRange(NotNullFrameworkMethods, StringType.GetMembers("Replace").OfType <IMethodSymbol>()); } UriType = compilation.GetTypeByMetadataName(typeof(Uri).FullName); if (UriType != null) { UriTryCreate = UriType.GetMembers("TryCreate").OfType <IMethodSymbol>().ToImmutableArray(); NotNullFrameworkMethods.Add(UriType.GetMembers("ToString").OfType <IMethodSymbol>().First()); } var dictionary = compilation.GetTypeByMetadataName(typeof(Dictionary <,>).FullName); DictionaryValues = dictionary?.GetMembers("Values").OfType <IPropertySymbol>().First(); DictionaryKeys = dictionary?.GetMembers("Keys").OfType <IPropertySymbol>().First(); var guid = compilation.GetTypeByMetadataName(typeof(Guid).FullName); AddRange(NotNullFrameworkMethods, guid.GetMembers("ToString").OfType <IMethodSymbol>()); Enumerable = compilation?.GetTypeByMetadataName(typeof(Enumerable).FullName); if (Enumerable != null) { AddRange(NotNullFrameworkMethods, Enumerable.GetMembers("ToList").OfType <IMethodSymbol>()); AddRange(NotNullFrameworkMethods, Enumerable.GetMembers("ToArray").OfType <IMethodSymbol>()); AddRange(NotNullFrameworkMethods, Enumerable.GetMembers("Where").OfType <IMethodSymbol>()); AddRange(NotNullFrameworkMethods, Enumerable.GetMembers("Select").OfType <IMethodSymbol>()); AddRange(NotNullFrameworkMethods, Enumerable.GetMembers("Empty").OfType <IMethodSymbol>()); AddRange(NotNullFrameworkMethods, Enumerable.GetMembers("First").OfType <IMethodSymbol>()); } var path = compilation.GetTypeByMetadataName(typeof(System.IO.Path).FullName); if (path != null) { var getTempPath = path.GetMembers("GetTempPath").OfType <IMethodSymbol>().FirstOrDefault(); if (getTempPath != null) { NotNullFrameworkMethods.Add(getTempPath); } } var marshal = compilation.GetTypeByMetadataName(typeof(System.Runtime.InteropServices.Marshal).FullName); if (marshal != null) { var getObject = marshal.GetMembers("GetObjectForIUnknown").OfType <IMethodSymbol>().FirstOrDefault(); if (getObject != null) { NotNullFrameworkMethods.Add(getObject); } } var task = compilation.GetTypeByMetadataName(typeof(Task).FullName); if (task != null) { var fromResult = task.GetMembers("FromResult").OfType <IMethodSymbol>().FirstOrDefault(); if (fromResult != null) { NotNullFrameworkMethods.Add(fromResult); } } var task1 = compilation.GetTypeByMetadataName(typeof(Task <>).FullName); if (task1 != null) { ConfigureAwait = task1.GetMembers("ConfigureAwait").OfType <IMethodSymbol>().FirstOrDefault(); } var int64 = compilation.GetTypeByMetadataName(typeof(long).FullName); if (int64 != null) { AddRange(NotNullFrameworkMethods, int64.GetMembers("ToString").OfType <IMethodSymbol>()); } // TODO: this should be moved to AdditionalFiles at some point AddRange(NotNullFrameworkMethods, ParseMethodName(compilation, "AutoMapper.IMapper.Map")); }