Esempio n. 1
0
 public static bool IsGenericTypeParameterOf(this TypeSyntax type, MethodDeclarationSyntax method)
 {
     return(method
            ?.TypeParameterList
            ?.Parameters
            .Any(t => t.Identifier.Text == type.GetPartialTypeName())
            ?? false);
 }
        public CompilationUnitSyntax ComputeRoot(CompilationUnitSyntax root)
        {
            var typesToReplace = _method.ParameterList.Parameters
                                 .Select(n => n.Type)
                                 .Append(_method.ReturnType)
                                 .SelectMany(t => t.DescendantNodes().OfType <TypeSyntax>().Prepend(t))
                                 .Where(type => type.GetPartialTypeName() == _type.GetPartialTypeName());

            var newMethod = _method
                            .ReplaceNodes(typesToReplace, (o, r) => GetGenericTypeName().ToIdentifierName().Nicefy())
                            .AddTypeParameterListParameters(GetTypeParameter());

            if (_inherit)
            {
                newMethod = newMethod.AddConstraintClauses(TypeParameterConstraint(GetGenericTypeName(), _type));
            }

            return(root.ReplaceNode(_method, newMethod));
        }