public ClassTemplateInfo GenerateClassInfoForInterface(InterfaceDeclarationSyntax interfaceTree)
        {
            var ret    = new ClassTemplateInfo();
            var parent = interfaceTree.Parent;

            while (parent != null && !(parent is NamespaceDeclarationSyntax))
            {
                parent = parent.Parent;
            }

            var ns = parent as NamespaceDeclarationSyntax;

            ret.Namespace            = ns.Name.ToString();
            ret.InterfaceName        = GetInterfaceName(interfaceTree.Identifier);
            ret.GeneratedClassSuffix = ret.InterfaceName.Replace(".", "");
            ret.Modifiers            = interfaceTree.Modifiers.Select(t => t.ValueText).FirstOrDefault(m => m == "public" || m == "internal");

            if (interfaceTree.TypeParameterList != null)
            {
                var typeParameters = interfaceTree.TypeParameterList.Parameters;
                if (typeParameters.Any())
                {
                    ret.TypeParameters = string.Join(", ", typeParameters.Select(p => p.Identifier.ValueText));
                }

                ret.ConstraintClauses = interfaceTree.ConstraintClauses.ToFullString().Trim();
            }

            ret.MethodList = interfaceTree.Members
                             .OfType <MethodDeclarationSyntax>()
                             .Select(x => new MethodTemplateInfo
            {
                Name         = x.Identifier.Text,
                ReturnType   = x.ReturnType.ToString(),
                ArgumentList = string.Join(",",
                                           x.ParameterList.Parameters
                                           .Select(y => y.Identifier.Text)),
                ArgumentListWithTypes = string.Join(",",
                                                    x.ParameterList.Parameters
                                                    .Select(y => $"{y.Type.ToString()} {y.Identifier.Text}")),
                ArgumentTypesList = string.Join(",", x.ParameterList.Parameters
                                                .Select(y => $"typeof({y.Type.ToString()})")),
                IsRefitMethod = HasRefitHttpMethodAttribute(x)
            })
                             .ToList();

            return(ret);
        }
Esempio n. 2
0
        public ClassTemplateInfo GenerateClassInfoForInterface(InterfaceDeclarationSyntax interfaceTree)
        {
            var ret    = new ClassTemplateInfo();
            var parent = interfaceTree.Parent;

            while (parent != null && !(parent is NamespaceDeclarationSyntax))
            {
                parent = parent.Parent;
            }

            ret.InterfaceName        = GetInterfaceName(interfaceTree.Identifier);
            ret.GeneratedClassSuffix = ret.InterfaceName.Replace(".", "");
            ret.Modifiers            = interfaceTree.Modifiers.Select(t => t.ValueText).FirstOrDefault(m => m == "public" || m == "internal");
            ret.BaseClasses          = interfaceTree.BaseList?.Types.Select(b => b.GetSimpleName()).Where(b => b != null)
                                       .Select(t => new BaseClassInfo
            {
                Name = t.Identifier.ValueText,
                TypeParametersInfo = (t is GenericNameSyntax g ? g.TypeArgumentList.Arguments.Select(a => a.GetTypeInfo()).ToList() : null)
            }).ToList();
Esempio n. 3
0
        public ClassTemplateInfo GenerateClassInfoForInterface(InterfaceDeclarationSyntax interfaceTree)
        {
            var ret    = new ClassTemplateInfo();
            var parent = interfaceTree.Parent;

            while (parent != null && !(parent is NamespaceDeclarationSyntax))
            {
                parent = parent.Parent;
            }

            var ns = parent as NamespaceDeclarationSyntax;

            ret.Namespace     = ns.Name.ToString();
            ret.InterfaceName = interfaceTree.Identifier.ValueText;

            if (interfaceTree.TypeParameterList != null)
            {
                var typeParameters = interfaceTree.TypeParameterList.Parameters;
                if (typeParameters.Any())
                {
                    ret.TypeParameters = string.Join(", ", typeParameters.Select(p => p.Identifier.ValueText));
                }
                ret.ConstraintClauses = interfaceTree.ConstraintClauses.ToFullString().Trim();
            }
            ret.MethodList = interfaceTree.Members
                             .OfType <MethodDeclarationSyntax>()
                             .Select(x => new MethodTemplateInfo()
            {
                Name         = x.Identifier.ValueText,
                ReturnType   = x.ReturnType.ToString(),
                ArgumentList = String.Join(",", x.ParameterList.Parameters
                                           .Select(y => y.Identifier.ValueText)),
                ArgumentListWithTypes = String.Join(",", x.ParameterList.Parameters
                                                    .Select(y => String.Format("{0} {1}", y.Type.ToString(), y.Identifier.ValueText))),
                IsRefitMethod = HasRefitHttpMethodAttribute(x)
            })
                             .ToList();

            return(ret);
        }
Esempio n. 4
0
        public ClassTemplateInfo GenerateClassInfoForInterface(InterfaceDeclarationSyntax interfaceTree)
        {
            var ret = new ClassTemplateInfo();
            var parent = interfaceTree.Parent;
            while (parent != null && !(parent is NamespaceDeclarationSyntax)) parent = parent.Parent;

            var ns = parent as NamespaceDeclarationSyntax;
            ret.Namespace = ns.Name.ToString();
            ret.InterfaceName = interfaceTree.Identifier.ValueText;
            ret.Modifiers = interfaceTree.Modifiers.Select(t => t.ValueText).FirstOrDefault(m => m == "public" || m == "internal");

            if (interfaceTree.TypeParameterList != null) {
                var typeParameters = interfaceTree.TypeParameterList.Parameters;
                if (typeParameters.Any()) {
                    ret.TypeParameters = string.Join(", ", typeParameters.Select(p => p.Identifier.ValueText));
                }
                ret.ConstraintClauses = interfaceTree.ConstraintClauses.ToFullString().Trim();
            }
            ret.MethodList = interfaceTree.Members
                .OfType<MethodDeclarationSyntax>()
                .Select(x => new MethodTemplateInfo() {
                    Name = x.Identifier.ValueText,
                    ReturnType = x.ReturnType.ToString(),
                    ArgumentList = String.Join(",", x.ParameterList.Parameters
                        .Select(y => y.Identifier.ValueText)),
                    ArgumentListWithTypes = String.Join(",", x.ParameterList.Parameters
                        .Select(y => String.Format("{0} {1}", y.Type.ToString(), y.Identifier.ValueText))),
                    IsRefitMethod = HasRefitHttpMethodAttribute(x)
                })
                .ToList();

            return ret;
        }