示例#1
0
            public override SyntaxNode VisitParameter(ParameterSyntax node)
            {
                string fullName = SyntaxUtils.GetFullName(node);

                if (this.GetRemapInfo(fullName, out List <AttributeSyntax> listAttributes, node.Type.ToString(), out string newType, out string newName))
                {
                    node = (ParameterSyntax)base.VisitParameter(node);
                    if (listAttributes != null)
                    {
                        foreach (var attrNode in listAttributes)
                        {
                            var attrListNode =
                                SyntaxFactory.AttributeList(
                                    SyntaxFactory.SingletonSeparatedList <AttributeSyntax>(attrNode));
                            node = node.WithAttributeLists(node.AttributeLists.Add(attrListNode));
                        }
                    }

                    if (newName != null)
                    {
                        node = node.WithIdentifier(SyntaxFactory.Identifier(newName));
                    }

                    if (newType != null)
                    {
                        node = node.WithType(SyntaxFactory.ParseTypeName(newType).WithTrailingTrivia(SyntaxFactory.Space));

                        // Get rid of the NativeTypeName attribute so the type we just changed to doesn't get overridden
                        var attr = SyntaxUtils.GetAttribute(node.AttributeLists, "NativeTypeName");
                        if (attr != null)
                        {
                            node = node.RemoveNode(attr, SyntaxRemoveOptions.KeepLeadingTrivia);
                        }
                    }
                }
        public static bool IsPotentialCrossArch(MethodDeclarationSyntax node)
        {
            var dllImportAttr = SyntaxUtils.GetAttribute(node.AttributeLists, "DllImport");

            if (dllImportAttr != null)
            {
                return(true);
            }

            return(false);
        }
示例#3
0
            public override SyntaxNode VisitParameter(ParameterSyntax node)
            {
                string fullName = GetFullNameWithoutArchSuffix(node);

                if (this.GetRemapInfo(fullName, out List <AttributeSyntax> listAttributes, node.Type.ToString(), out string newType, out string newName))
                {
                    node = (ParameterSyntax)base.VisitParameter(node);
                    if (listAttributes != null)
                    {
                        foreach (var attrNode in listAttributes)
                        {
                            var attrListNode =
                                SyntaxFactory.AttributeList(
                                    SyntaxFactory.SingletonSeparatedList <AttributeSyntax>(attrNode));
                            node = node.WithAttributeLists(node.AttributeLists.Add(attrListNode));
                        }
                    }

                    if (newName != null)
                    {
                        node = node.WithIdentifier(SyntaxFactory.Identifier(newName));
                    }

                    if (newType != null)
                    {
                        node = node.WithType(SyntaxFactory.ParseTypeName(newType).WithTrailingTrivia(SyntaxFactory.Space));

                        // Get rid of the NativeTypeName attribute so the type we just changed to doesn't get overridden
                        var attr = SyntaxUtils.GetAttribute(node.AttributeLists, "NativeTypeName");
                        if (attr != null)
                        {
                            var attrList = (AttributeListSyntax)attr.Parent;

                            // We want to delete the attribute, but if it's the last one in the list,
                            // remove the list
                            if (attrList.Attributes.Count == 1)
                            {
                                node = node.RemoveNode(attrList, SyntaxRemoveOptions.KeepLeadingTrivia);
                            }
                            // If it's not the last attribute, just remove the attribute
                            else
                            {
                                node = node.RemoveNode(attr, SyntaxRemoveOptions.KeepLeadingTrivia);
                            }
                        }
                    }
                }