Пример #1
0
        private static Symbol SymbolFromRoslynSymbol(int offset, Microsoft.CodeAnalysis.SemanticModel semanticModel, Microsoft.CodeAnalysis.ISymbol symbol)
        {
            var result = new Symbol();

            if (symbol is Microsoft.CodeAnalysis.IMethodSymbol methodSymbol)
            {
                result.IsVariadic = methodSymbol.Parameters.LastOrDefault()?.IsParams ?? false;
                result.Kind       = CursorKind.CXXMethod;

                result.Arguments = new List <ParameterSymbol>();

                foreach (var parameter in methodSymbol.Parameters)
                {
                    var argument = new ParameterSymbol();
                    argument.Name = parameter.Name;

                    var info = CheckForStaticExtension.GetReturnType(parameter);

                    if (info.HasValue)
                    {
                        argument.TypeDescription = info.Value.name;
                        argument.IsBuiltInType   = info.Value.inbuilt;
                    }

                    result.Arguments.Add(argument);
                }
            }

            result.Name = symbol.Name;

            var returnTypeInfo = CheckForStaticExtension.GetReturnType(symbol);

            if (returnTypeInfo.HasValue)
            {
                result.ResultType    = returnTypeInfo.Value.name;
                result.IsBuiltInType = returnTypeInfo.Value.inbuilt;
            }

            result.TypeDescription = symbol.Kind == Microsoft.CodeAnalysis.SymbolKind.NamedType ? symbol.ToDisplayString() : symbol.ToMinimalDisplayString(semanticModel, offset);
            var xmlDocumentation = symbol.GetDocumentationCommentXml();

            var docComment = DocumentationComment.From(xmlDocumentation, Environment.NewLine);

            result.BriefComment = docComment.SummaryText;

            return(result);
        }
Пример #2
0
        public SamplePresenter(Microsoft.CodeAnalysis.ISymbol symbol)
        {
            var asmName = symbol.ContainingAssembly.Name;

            if (asmName == "zarif")
            {
                flagOk = false;
                return;
            }

            var appDTE      = (DTE2)Package.GetGlobalService(typeof(SDTE));
            var curProj     = appDTE.ActiveDocument.ProjectItem.ContainingProject;
            var vsCurProj   = (VSProject)curProj.Object;
            var asmFilePath = vsCurProj.References.OfType <Reference>().FirstOrDefault(r => r.Name == asmName).Path;

            var className    = symbol.ContainingType.ToDisplayString(Microsoft.CodeAnalysis.SymbolDisplayFormat.FullyQualifiedFormat).Replace("global::", "");
            var functionName = symbol.Name;

            var paramTypes = new List <Type>();

            foreach (var parm in ((Microsoft.CodeAnalysis.IMethodSymbol)symbol).Parameters)
            {
                paramTypes.Add(parm.Type.Name.ToString().ToType());
            }


            var objAssembly = Assembly.LoadFrom(asmFilePath);

            ClassType = objAssembly.GetType(className);
            // var ClassCons2 = ClassType.GetConstructors();
            classInstance = ValueSampler.SampleValue(ClassType);
            if (ClassType == null)
            {
                flagOk = false;
                return;
            }

            if (!(ClassType.GetConstructor(Type.EmptyTypes) == null && ClassType.IsAbstract && ClassType.IsSealed))
            {
                if (classInstance == null)
                {
                    if (ClassType.GetConstructor(Type.EmptyTypes) != null)
                    {
                        classInstance = Activator.CreateInstance(ClassType);
                    }
                    else
                    {
                        flagOk = false;
                        return;
                    }
                }
            }

            MI = ClassType.GetMethod(functionName, paramTypes.ToArray());
            if (MI == null)
            {
                flagOk = false;
                return;
            }

            var StyleFilePath  = Path.GetTempPath() + "Style.css";
            var SampleFilePath = Path.GetTempPath() + "present.html";

            if (!File.Exists(StyleFilePath))
            {
                File.WriteAllText(StyleFilePath, Constant.StylePage);
            }

            // -----------Assigning Value---------
            @namespace = ClassType.Namespace;
            if (MI.DeclaringType != null)
            {
                declaringType = "<p><em>DeclaringType: <strong>" + MI.DeclaringType.Name + "</strong></em></p>";
            }

            // remarks = "Remarks of method";
            doc = symbol.GetDocumentationCommentXml();
            var @nameSpaceDot = @namespace + ".";

            @methodname = MI.Name;
            @return     = MI.ReturnType.Name;
            var parInfos = MI.GetParameters();

            var cnt = 1;

            foreach (var pInfo in parInfos)
            {
                @paramsType += pInfo.ParameterType.Name;
                if (parInfos.Count() != cnt)
                {
                    @paramsType += ",";
                }
                cnt += 1;
            }

            if (parInfos.Count() == 0)
            {
                GenerateSamples(1);
            }
            else
            {
                GenerateSamples(3);
            }

            // -----------------------------------
            strPageContent = strPageContent.Replace("@namespace", @namespace).Replace("@declaringType", declaringType).Replace("@methodname", @methodname).Replace("@return", @return);
            strPageContent = strPageContent.Replace("@params", paramsType).Replace("@doc", @doc).Replace("@tRows", @tRows).Replace("@remarks", remarks);
            System.IO.File.WriteAllText(SampleFilePath, strPageContent);
        }