public static MappingInfo Create(FromInfo @from, ToInfo to) { return new MappingInfo { From = from, To = to }; }
private static IEnumerable <MappingInfo> AnalyzeLoadMethod(SemanticModel semanticModel, ISymbol loadMethod) { var syntaxNode = loadMethod.DeclaringSyntaxReferences.Single().GetSyntax(); var methodSymbols = syntaxNode.DescendantNodes() .OfType <InvocationExpressionSyntax>() .Select(invocationExpressionSyntax => semanticModel.GetSymbolInfo(invocationExpressionSyntax.Expression).Symbol as IMethodSymbol) .Where(e => e != null && e.GetFullMetadataName() == ExternalLibraryInformation.Module.Register.FullName && e.Parameters.IsEmpty); foreach (var mapping in methodSymbols.Select(e => e.TypeArguments) .Where(typeArguments => typeArguments.Length == ExternalLibraryInformation.Module.RegisterMethodsGenericCount)) { if (!(mapping[0] is INamedTypeSymbol from)) { throw new AnalyzerException( $"Implementation is invalid: {mapping[0].ToDisplayString()}"); } if (!from.Constructors.Any()) { throw new AnalyzerException( $"Implementation has no constructor: {mapping[0].ToDisplayString()}"); } var constructionInfos = from.Constructors.Select(constructor => ConstructionInfo.Create( constructor.Parameters.Select( parameter => ParameterInfo.Create(parameter.Type.GetFullMetadataName())) .ToList())) .ToList(); var fromInfo = FromInfo.Create(from.GetFullMetadataName(), constructionInfos); var to = mapping[1]; var toInfo = ToInfo.Create(to.GetFullMetadataName()); yield return(MappingInfo.Create(fromInfo, toInfo)); } }