private static string GetName(IEntity entity, CSharpAmbience ambience) { string fullName = ambience.ConvertSymbol(entity); if (entity.SymbolKind == SymbolKind.Operator) { int offset = 17; int index = fullName.IndexOf("implicit operator "); if (index < 0) { index = fullName.IndexOf("explicit operator "); if (index < 0) { index = fullName.IndexOf("operator "); offset = fullName.IndexOf('(') - index; } } if (index >= 0) { fullName = fullName.Substring(0, index) + entity.Name + fullName.Substring(index + offset); } } return(fullName); }
public void SetSearchedMembers(IEnumerable <object> members) { searchedMembers = new List <object> (members); var firstMember = searchedMembers.FirstOrDefault(); if (firstMember is INamedElement) { var namedElement = (INamedElement)firstMember; memberName = namedElement.Name; keywordName = CSharpAmbience.NetToCSharpTypeName(namedElement.FullName); if (keywordName == namedElement.FullName) { keywordName = null; } } if (firstMember is string) { memberName = firstMember.ToString(); } if (firstMember is IVariable) { memberName = ((IVariable)firstMember).Name; } if (firstMember is ITypeParameter) { memberName = ((ITypeParameter)firstMember).Name; } }
public static string csharpCode(this IMethod iMethod) { var @namespace = iMethod.@namespace(); var typeName = iMethod.typeName(); var ambiance = new CSharpAmbience(); var csharpCode = ("\t\t{0}".line() + "\t\t{{".line() + "\t\t\tthrow new System.Exception(\"O2 Auto Generated Method\");".line() + "\t\t}}".line()) .format(ambiance.Convert(iMethod)); if (typeName.valid()) { csharpCode = ("\tclass {0}".line() + "\t{{".line() + "{1}".line() + "\t}}".line()) .format(typeName, csharpCode); } if (@namespace.valid()) { csharpCode = ("namespace {0}".line() + "{{".line() + "{1}".line() + "}}".line()) .format(@namespace, csharpCode); } //if (@namespace.valid()); return(csharpCode); }
protected override object CreateFancyDescription() { var ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowDeclaringType; string header = ambience.ConvertSymbol(Entity); var documentation = XmlDocumentationElement.Get(Entity); ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList; var b = new CSharpDocumentationBuilder(ambience); b.AddCodeBlock(header, keepLargeMargin: true); if (documentation != null) { foreach (var child in documentation.Children) { b.AddDocumentationElement(child); } } var flowDocument = b.CreateFlowDocument(); flowDocument.PagePadding = new Thickness(0); // default is NOT Thickness(0), but Thickness(Auto), which adds unnecessary space return(new FlowDocumentScrollViewer { Document = flowDocument, VerticalScrollBarVisibility = ScrollBarVisibility.Auto }); }
void AppendParameterList(StringBuilder result, CodeGenerationOptions options, IList <IParameter> parameters) { for (int i = 0; i < parameters.Count; i++) { if (i > 0) { result.Append(", "); } var p = parameters[i]; if (p.IsOut) { result.Append("out "); } if (p.IsRef) { result.Append("ref "); } if (p.IsParams) { result.Append("params "); } AppendReturnType(result, options, p.Type); result.Append(" "); result.Append(CSharpAmbience.FilterName(p.Name)); } }
public void RoundMethodParameterConvertedToStringUsingAmbienceReturnsDoubleNumberString() { IAmbience ambience = new CSharpAmbience(); string text = ambience.Convert(GetFirstRoundMethodParameter()); Assert.AreEqual("double number", text); }
public void ExitMethodParameterConvertedToStringUsingAmbienceReturnsObjectCodeString() { IAmbience ambience = new CSharpAmbience(); string text = ambience.Convert(GetFirstExitMethodParameter()); Assert.AreEqual("object code", text); }
public void FixtureSetUp() { ambience = new CSharpAmbience(); compilation = new SimpleCompilation(TypeSystemLoaderTests.TestAssembly, TypeSystemLoaderTests.Mscorlib.WithOptions(TypeSystemOptions.Default)); }
public static string fullName(this IMethod iMethod) { if (iMethod == null) return "[null value]"; CSharpAmbience ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.UseFullyQualifiedMemberNames; return ambience.Convert(iMethod); }
public static object CreateEntityDescription(Brush textColor, ISymbol symbol, string xmlDocumentation = null) { CSharpAmbience ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags; return(CreateEntityDescription(textColor, ambience.ConvertSymbol(symbol), xmlDocumentation)); }
static CSharpAmbience CreateAmbience() { CSharpAmbience ambience = new CSharpAmbience(); // Do not forget to update CSharpAmbienceTests.ILSpyMainTreeViewTypeFlags, if this ever changes. ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList | ConversionFlags.PlaceReturnTypeAfterParameterList; return(ambience); }
public static string fullName(this IProperty iProperty) { if (iProperty == null) return "[null value]"; CSharpAmbience ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.UseFullyQualifiedMemberNames | ConversionFlags.UseFullyQualifiedTypeNames; return ambience.Convert(iProperty); }
public void FixtureSetUp() { valueCollection = SharedProjectContentRegistryForTests.Instance.Mscorlib.GetClass("System.Collections.Generic.Dictionary.ValueCollection", 2); Assert.AreEqual(2, valueCollection.TypeParameters.Count); Assert.AreEqual(2, valueCollection.DeclaringType.TypeParameters.Count); fullMemberNameAmbience = new CSharpAmbience(); fullMemberNameAmbience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.UseFullyQualifiedMemberNames; }
public void ExitMethodReturnTypeConvertedToStringUsingAmbienceReturnsVoid() { IAmbience ambience = new CSharpAmbience(); List <IMethod> methods = GetExitMethods(); IReturnType returnType = methods[0].ReturnType; string text = ambience.Convert(returnType); Assert.AreEqual("void", text); }
static CSharpAmbience CreateAmbience() { CSharpAmbience ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.ShowParameterList | ConversionFlags.ShowReturnType | ConversionFlags.ShowTypeParameterList | ConversionFlags.PlaceReturnTypeAfterParameterList; return(ambience); }
public OverrideCompletionData(int declarationBegin, IMember m, CSharpTypeResolveContext contextAtCaret) : base(m) { this.declarationBegin = declarationBegin; this.contextAtCaret = contextAtCaret; var ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList | ConversionFlags.ShowParameterList | ConversionFlags.ShowParameterNames; this.CompletionText = ambience.ConvertEntity(m); }
static string GetText(ResolveResult result) { // ReSharper disable CanBeReplacedWithTryCastAndCheckForNull if (result == null) { return(null); } if (result is MixedResolveResult) { return(GetText(((MixedResolveResult)result).PrimaryResult)); } IAmbience ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags | ConversionFlags.ShowAccessibility; if (result is MemberResolveResult) { return(GetMemberText(ambience, ((MemberResolveResult)result).ResolvedMember)); } if (result is LocalResolveResult) { var rr = (LocalResolveResult)result; ambience.ConversionFlags = ConversionFlags.UseFullyQualifiedTypeNames | ConversionFlags.ShowReturnType; var b = new StringBuilder(); b.Append(rr.IsParameter ? "parameter " : "local variable "); b.Append(ambience.Convert(rr.Field)); return(b.ToString()); } if (result is NamespaceResolveResult) { return("namespace " + ((NamespaceResolveResult)result).Name); } if (result is TypeResolveResult) { IClass c = ((TypeResolveResult)result).ResolvedClass; if (c != null) { return(GetMemberText(ambience, c)); } return(ambience.Convert(result.ResolvedType)); } if (result is MethodGroupResolveResult) { var mrr = result as MethodGroupResolveResult; IMethod m = mrr.GetMethodIfSingleOverload(); if (m != null) { return(GetMemberText(ambience, m)); } return("Overload of " + ambience.Convert(mrr.ContainingType) + "." + mrr.Name); } return(null); // ReSharper restore CanBeReplacedWithTryCastAndCheckForNull }
public CodeDecompiler(ParsedMethodName mp) { if (mp == null) { throw new ArgumentNullException("Failed to instantiate CodeDecompiler due to NULL parameter.", "MethodNameParser mp"); } this._mp = mp; this.sourceCodeBasePath = System.IO.Path.GetFullPath($"{HttpRuntime.AppDomainAppPath.ToString()}..\\DemoWebCamp\\SourceCode"); this.decompiler = new CSharpDecompiler($@"{this.sourceCodeBasePath}\bin\{this._mp.DllName}", new ICSharpCode.Decompiler.DecompilerSettings()); this.amb = new CSharpAmbience(); }
public override IMember ImplementMember(RefactorerContext ctx, IType cls, IMember member, IReturnType privateImplementationType) { if (privateImplementationType != null) { // Workaround for bug in the code generator. Generic private implementation types are not generated correctly when they are generic. Ambience amb = new CSharpAmbience(); string tn = amb.GetString(privateImplementationType, OutputFlags.IncludeGenerics | OutputFlags.UseFullName | OutputFlags.UseIntrinsicTypeNames); privateImplementationType = new DomReturnType(tn); } return(base.ImplementMember(ctx, cls, member, privateImplementationType)); }
public void DynamicTypeInGenerics() { CSharpAmbience a = new CSharpAmbience(); a.ConversionFlags = ConversionFlags.ShowReturnType | ConversionFlags.ShowParameterList; Assert.AreEqual("List<dynamic> DynamicGenerics1(Action<object, dynamic[], object>)", a.Convert(testClass.Methods.Single(me => me.Name == "DynamicGenerics1"))); Assert.AreEqual("void DynamicGenerics2(Action<object, dynamic, object>)", a.Convert(testClass.Methods.Single(me => me.Name == "DynamicGenerics2"))); Assert.AreEqual("void DynamicGenerics3(Action<int, dynamic, object>)", a.Convert(testClass.Methods.Single(me => me.Name == "DynamicGenerics3"))); Assert.AreEqual("void DynamicGenerics4(Action<int[], dynamic, object>)", a.Convert(testClass.Methods.Single(me => me.Name == "DynamicGenerics4"))); Assert.AreEqual("void DynamicGenerics5(Action<int[], dynamic, object>)", a.Convert(testClass.Methods.Single(me => me.Name == "DynamicGenerics5"))); }
static CSharpAmbience CreateAmbience() { CSharpAmbience ambience = new CSharpAmbience(); // Do not forget to update CSharpAmbienceTests.ILSpyMainTreeViewTypeFlags, if this ever changes. ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList | ConversionFlags.PlaceReturnTypeAfterParameterList; if (new DecompilationOptions().DecompilerSettings.LiftNullables) { ambience.ConversionFlags |= ConversionFlags.UseNullableSpecifierForValueTypes; } return(ambience); }
public TypeLookupResponse GetTypeLookupResponse(TypeLookupRequest request) { var res = _bufferParser.ParsedContent(request.Buffer, request.FileName); var loc = new TextLocation(request.Line, request.Column); var resolveResult = ResolveAtLocation.Resolve(res.Compilation, res.UnresolvedFile, res.SyntaxTree, loc); var response = new TypeLookupResponse(); var ambience = new CSharpAmbience() { ConversionFlags = AmbienceFlags, }; if (resolveResult == null || resolveResult is NamespaceResolveResult) { response.Type = ""; } else if (resolveResult != null) { response.Type = resolveResult.Type.ToString(); if (resolveResult is CSharpInvocationResolveResult) { var result = resolveResult as CSharpInvocationResolveResult; response.Type = ambience.ConvertEntity(result.Member); } else if (resolveResult is LocalResolveResult) { var result = resolveResult as LocalResolveResult; response.Type = ambience.ConvertVariable(result.Variable); } else if (resolveResult is MemberResolveResult) { var result = resolveResult as MemberResolveResult; response.Type = ambience.ConvertEntity(result.Member); } else if (resolveResult is TypeResolveResult) { ambience.ConversionFlags |= ConversionFlags.UseFullyQualifiedTypeNames; response.Type = ambience.ConvertType(resolveResult.Type); } if (resolveResult.Type is UnknownType) { response.Type = "Unknown Type: " + resolveResult.Type.Name; } if (resolveResult.Type == SpecialType.UnknownType) { response.Type = "Unknown Type"; } } return(response); }
void Analyze(CompletionContext context, SemanticModel model, SyntaxNode node, ISymbol within, ParameterListSyntax parameterList, ISymbol symbol, HashSet <string> addedSymbols, CancellationToken cancellationToken) { var type = CheckParameterList(model, parameterList, symbol, cancellationToken); if (type == null) { return; } var startType = type; var typeString = CSharpAmbience.SafeMinimalDisplayString(type, model, context.CompletionListSpan.Start, Ambience.LabelFormat); var pDict = ImmutableDictionary <string, string> .Empty; if (typeString != null) { pDict = pDict.Add("CastTypeString", typeString); } pDict = pDict.Add("DescriptionMarkup", "- <span foreground=\"darkgray\" size='small'>" + GettextCatalog.GetString("Cast to '{0}'", type.Name) + "</span>"); pDict = pDict.Add("NodeString", node.ToString()); while (type.SpecialType != SpecialType.System_Object) { foreach (var member in type.GetMembers()) { if (member.IsImplicitlyDeclared || member.IsStatic) { continue; } if (member.IsOrdinaryMethod() || member.Kind == SymbolKind.Field || member.Kind == SymbolKind.Property) { if (member.IsAccessibleWithin(within)) { var completionData = SymbolCompletionItem.CreateWithSymbolId( member.Name, new [] { member }, CompletionItemRules.Default, context.Position, properties: pDict ); if (addedSymbols.Contains(completionData.DisplayText)) { continue; } addedSymbols.Add(completionData.DisplayText); context.AddItem(completionData); } } } type = type.BaseType; } }
//// public override string CreateFieldEncapsulation (IUnresolvedTypeDefinition implementingType, IField field, string propertyName, Accessibility modifiers, bool readOnly) //// { //// SetIndentTo (implementingType); //// StringBuilder result = new StringBuilder (); //// AppendIndent (result); //// ////// if (modifiers != MonoDevelop.Projects.Dom.Modifiers.None) { ////// switch (modifiers) { ////// } ////// result.Append (ambience.GetString (modifiers)); ////// result.Append (" "); ////// } //// var options = new CodeGenerationOptions () { //// ImplementingType = field.DeclaringTypeDefinition, //// Part = implementingType //// }; //// result.Append ("public "); //// AppendReturnType (result, options, field.ReturnType); //// result.Append (" "); //// result.Append (propertyName); //// AppendBraceStart (result, Policy.PropertyBraceStyle); //// AppendIndent (result); //// //// result.Append ("get"); //// AppendBraceStart (result, Policy.PropertyGetBraceStyle); //// AppendIndent (result); //// result.Append ("return this."); //// result.Append (CSharpAmbience.FilterName (field.Name)); //// result.Append (";"); //// AppendLine (result); //// AppendBraceEnd (result, Policy.PropertyGetBraceStyle); //// AppendLine (result); //// //// if (!readOnly) { //// AppendIndent (result); //// result.Append ("set"); //// AppendBraceStart (result, Policy.PropertyGetBraceStyle); //// AppendIndent (result); //// result.Append (CSharpAmbience.FilterName (field.Name)); //// result.Append (" = value;"); //// AppendLine (result); //// AppendBraceEnd (result, Policy.PropertyGetBraceStyle); //// AppendLine (result); //// } //// //// AppendBraceEnd (result, Policy.PropertyBraceStyle); //// return result.ToString (); //// } // // int CountBlankLines (IReadonlyTextDocument doc, int startLine) // { // int result = 0; // IDocumentLine line; // while ((line = doc.GetLine (startLine + result)) != null && doc.GetLineIndent (line).Length == line.Length) { // result++; // } // // return result; // } // // static bool InsertUsingAfter (AstNode node) // { // return node is NewLineNode && IsCommentOrUsing (node.GetNextSibling (s => !(s is NewLineNode))) || // IsCommentOrUsing (node) || (node is PreProcessorDirective); // } // // static bool IsCommentOrUsing (AstNode node) // { // return node is ICSharpCode.NRefactory.CSharp.Comment || // node is UsingDeclaration || // node is UsingAliasDeclaration; // } // // // static string OutputNode (TextEditor editor, DocumentContext context, AstNode node) // { // using (var stringWriter = new System.IO.StringWriter ()) { //// formatter.Indentation = indentLevel; // var formatter = new TextWriterTokenWriter (stringWriter); // stringWriter.NewLine = editor.EolMarker; // // var visitor = new CSharpOutputVisitor (formatter, null /* TODO: BROKEN DUE ROSLYN PORT (note: that code should be unused) */ ); // node.AcceptVisitor (visitor); // return stringWriter.ToString (); // } // } // // // public AstType CreateShortType (ICompilation compilation, CSharpUnresolvedFile parsedFile, TextLocation loc, IType fullType) // { // var csResolver = parsedFile.GetResolver (compilation, loc); // var builder = new ICSharpCode.NRefactory.CSharp.Refactoring.TypeSystemAstBuilder (csResolver); // return builder.ConvertType (fullType); // } // // public override void CompleteStatement (MonoDevelop.Ide.Gui.Document doc) // { // // TODO: BROKEN DUE ROSLYN PORT - needs to be ported to NR6 //// var fixer = new ConstructFixer (doc.GetFormattingOptions (), doc.Editor.CreateNRefactoryTextEditorOptions ()); //// int newOffset; //// if (fixer.TryFix (new DocumentWrapper (doc.Editor), doc.Editor.CaretOffset, out newOffset)) { //// doc.Editor.CaretOffset = newOffset; //// } // } static CodeGeneratorMemberResult GenerateProtocolCode(IMethodSymbol method, CodeGenerationOptions options) { int bodyStartOffset = -1, bodyEndOffset = -1; var result = new StringBuilder(); var exportAttribute = method.GetAttributes().FirstOrDefault(attr => attr.AttributeClass.Name == "ExportAttribute"); if (exportAttribute != null) { result.Append("[Export(\""); result.Append(exportAttribute.ConstructorArguments.First().Value.ToString()); result.Append("\")]"); result.AppendLine(); } AppendModifiers(result, options, method); AppendReturnType(result, options, method.ReturnType); result.Append(" "); if (options.ExplicitDeclaration) { AppendReturnType(result, options, method.ContainingType); result.Append("."); } result.Append(CSharpAmbience.FilterName(method.Name)); if (method.TypeParameters.Length > 0) { result.Append("<"); for (int i = 0; i < method.TypeParameters.Length; i++) { if (i > 0) { result.Append(", "); } var p = method.TypeParameters[i]; result.Append(CSharpAmbience.FilterName(p.Name)); } result.Append(">"); } result.Append("("); AppendParameterList(result, options, method.Parameters, true); result.Append(")"); var typeParameters = method.TypeParameters; result.Append("{"); AppendIndent(result); bodyStartOffset = result.Length; result.Append("throw new System.NotImplementedException ();"); bodyEndOffset = result.Length; AppendLine(result); result.Append("}"); return(new CodeGeneratorMemberResult(result.ToString(), bodyStartOffset, bodyEndOffset)); }
public override string CreateFieldEncapsulation(IUnresolvedTypeDefinition implementingType, IField field, string propertyName, Accessibility modifiers, bool readOnly) { SetIndentTo(implementingType); StringBuilder result = new StringBuilder(); AppendIndent(result); // if (modifiers != MonoDevelop.Projects.Dom.Modifiers.None) { // switch (modifiers) { // } // result.Append (ambience.GetString (modifiers)); // result.Append (" "); // } var options = new CodeGenerationOptions() { ImplementingType = field.DeclaringTypeDefinition, Part = implementingType }; result.Append("public "); AppendReturnType(result, options, field.ReturnType); result.Append(" "); result.Append(propertyName); AppendBraceStart(result, Policy.PropertyBraceStyle); AppendIndent(result); result.Append("get"); AppendBraceStart(result, Policy.PropertyGetBraceStyle); AppendIndent(result); result.Append("return this."); result.Append(CSharpAmbience.FilterName(field.Name)); result.Append(";"); AppendLine(result); AppendBraceEnd(result, Policy.PropertyGetBraceStyle); AppendLine(result); if (!readOnly) { AppendIndent(result); result.Append("set"); AppendBraceStart(result, Policy.PropertyGetBraceStyle); AppendIndent(result); result.Append(CSharpAmbience.FilterName(field.Name)); result.Append(" = value;"); AppendLine(result); AppendBraceEnd(result, Policy.PropertyGetBraceStyle); AppendLine(result); } AppendBraceEnd(result, Policy.PropertyBraceStyle); return(result.ToString()); }
CompletionItem CreateNewMethodCreationItem(SyntaxNode parent, SemanticModel semanticModel, ITypeSymbol delegateType, int position, string optDelegateName, IMethodSymbol delegateMethod, CancellationToken cancellationToken) { var sb = new StringBuilder(); string varName = optDelegateName ?? "Handle" + delegateType.Name; var curType = semanticModel.GetEnclosingSymbol <INamedTypeSymbol> (position, cancellationToken); var uniqueName = new UniqueNameGenerator(semanticModel).CreateUniqueMethodName(parent, varName); var pDict = ImmutableDictionary <string, string> .Empty; pDict = pDict.Add("RightSideMarkup", "<span size='small'>" + GettextCatalog.GetString("Creates new method") + "</span>"); var indent = "\t"; sb = new StringBuilder(); var enclosingSymbol = semanticModel.GetEnclosingSymbol(position, default(CancellationToken)); if (enclosingSymbol != null && enclosingSymbol.IsStatic) { sb.Append("static "); } sb.Append("void "); int pos2 = sb.Length; sb.Append(uniqueName); sb.Append(' '); sb.Append("("); for (int k = 0; k < delegateMethod.Parameters.Length; k++) { if (k > 0) { sb.Append(", "); } sb.Append(CSharpAmbience.SafeMinimalDisplayString(delegateMethod.Parameters [k], semanticModel, position, MonoDevelop.Ide.TypeSystem.Ambience.LabelFormat)); } sb.Append(")"); sb.Append(eolMarker); sb.Append(indent); sb.Append("{"); sb.Append(eolMarker); sb.Append(indent); sb.Append(oneIndentMarker); //int cursorPos = pos + sb.Length; sb.Append(indent); sb.Append("}"); sb.Append(eolMarker); pDict = pDict.Add("Position", position.ToString()); pDict = pDict.Add("NewMethod", sb.ToString()); pDict = pDict.Add("MethodName", varName); return(CompletionItem.Create(uniqueName, properties: pDict, tags: newMethodTags, rules: NewMethodRules)); }
/* * void ResolveReturnTypes () * { * returnType = member.ReturnType; * foreach (IUsing u in unit.Usings) { * foreach (KeyValuePair<string, IReturnType> alias in u.Aliases) { * if (alias.Key == member.ReturnType.FullName) { * returnType = alias.Value; * return; * } * } * } * }*/ CodeGeneratorMemberResult GenerateCode(IField field, CodeGenerationOptions options) { StringBuilder result = new StringBuilder(); AppendIndent(result); AppendModifiers(result, options, field); result.Append(" "); AppendReturnType(result, options, field.ReturnType); result.Append(" "); result.Append(CSharpAmbience.FilterName(field.Name)); result.Append(";"); return(new CodeGeneratorMemberResult(result.ToString(), -1, -1)); }
private ICompletionData CompletionData(IEntity entity) { ICompletionData completionData = null; if (entity.Documentation != null) { completionData = new CompletionData(_signature, _completionText, _signature + Environment.NewLine + DocumentationConverter.ConvertDocumentation(entity.Documentation)); } else { IDocumentationProvider docProvider = null; if (entity.ParentAssembly.AssemblyName != null) { docProvider = XmlDocumentationProviderFactory.Get(entity.ParentAssembly.AssemblyName); } var ambience = new CSharpAmbience { ConversionFlags = ConversionFlags.ShowParameterList | ConversionFlags.ShowParameterNames | ConversionFlags.ShowReturnType | ConversionFlags.ShowBody | ConversionFlags.ShowTypeParameterList }; var documentationSignature = ambience.ConvertEntity(entity); if (docProvider != null) { DocumentationComment documentationComment = docProvider.GetDocumentation(entity); if (documentationComment != null) { var documentation = documentationSignature + Environment.NewLine + DocumentationConverter.ConvertDocumentation( documentationComment.Xml.Text); completionData = new CompletionData(_signature, _completionText, documentation); } else { completionData = new CompletionData(_signature, _completionText, documentationSignature); } } else { completionData = new CompletionData(_signature, _completionText, documentationSignature); } } return(completionData); }
FlowDocumentScrollViewer GenerateHeader() { var ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags; var stringBuilder = new StringBuilder(); var formatter = new ParameterHighlightingOutputFormatter(stringBuilder, highlightedParameterIndex); ambience.ConvertSymbol(Method, formatter, FormattingOptionsFactory.CreateSharpDevelop()); var documentation = XmlDocumentationElement.Get(Method); ambience.ConversionFlags = ConversionFlags.ShowTypeParameterList; var b = new CSharpDocumentationBuilder(ambience); string parameterName = null; if (Method.Parameters.Count > highlightedParameterIndex) { parameterName = Method.Parameters[highlightedParameterIndex].Name; } b.AddSignatureBlock(stringBuilder.ToString(), formatter.parameterStartOffset, formatter.parameterLength, parameterName); var b2 = new CSharpDocumentationBuilder(ambience); b2.ParameterName = parameterName; b2.ShowAllParameters = false; if (documentation != null) { foreach (var child in documentation.Children) { b2.AddDocumentationElement(child); } } content = new FlowDocumentScrollViewer { Document = b2.CreateFlowDocument(), VerticalScrollBarVisibility = ScrollBarVisibility.Auto }; var flowDocument = b.CreateFlowDocument(); flowDocument.PagePadding = new Thickness(0); // default is NOT Thickness(0), but Thickness(Auto), which adds unnecessary space return(new FlowDocumentScrollViewer { Document = flowDocument, VerticalScrollBarVisibility = ScrollBarVisibility.Auto }); }
void GenerateHeader() { CSharpAmbience ambience = new CSharpAmbience(); ambience.ConversionFlags = ConversionFlags.StandardConversionFlags; var stringBuilder = new StringBuilder(); //var formatter = new ParameterHighlightingOutputFormatter(stringBuilder, highlightedParameterIndex); //ambience.ConvertEntity(Method, formatter, FormattingOptionsFactory.CreateSharpDevelop()); //TokenWriter customConverter = new TextWriterTokenWriter(); //ambience.ConvertSymbol(Method, customConverter, FormattingOptionsFactory.CreateSharpDevelop()); //var inlineBuilder = new HighlightedInlineBuilder(stringBuilder.ToString()); //inlineBuilder.SetFontWeight(formatter.parameterStartOffset, formatter.parameterLength, FontWeights.Bold); //header.Inlines.Clear(); //header.Inlines.AddRange(inlineBuilder.CreateRuns()); }
public override IMember ImplementMember (RefactorerContext ctx, IType cls, IMember member, IReturnType privateImplementationType) { if (privateImplementationType != null) { // Workaround for bug in the code generator. Generic private implementation types are not generated correctly when they are generic. Ambience amb = new CSharpAmbience (); string tn = amb.GetString (privateImplementationType, OutputFlags.IncludeGenerics | OutputFlags.UseFullName | OutputFlags.UseIntrinsicTypeNames); privateImplementationType = new DomReturnType (tn); } return base.ImplementMember (ctx, cls, member, privateImplementationType); }
void AppendPropertyComment (StringBuilder builder, string indent, IProperty property) { if (property.Parameters != null) { CSharpAmbience ambience = new CSharpAmbience (); foreach (IParameter para in property.Parameters) { builder.Append (Environment.NewLine); builder.Append (indent); builder.Append ("/// <param name=\""); builder.Append (para.Name); builder.Append ("\">\n"); builder.Append (indent); builder.Append ("/// A <see cref=\""); builder.Append (ambience.GetString (para.ReturnType, OutputFlags.ClassBrowserEntries | OutputFlags.UseFullName | OutputFlags.UseNETTypeNames)); builder.Append ("\"/>\n"); builder.Append (indent); builder.Append ("/// </param>"); } } }
void AppendMethodComment (StringBuilder builder, string indent, IMethod method) { CSharpAmbience ambience = new CSharpAmbience (); if (method.Parameters != null) { foreach (IParameter para in method.Parameters) { builder.Append (Environment.NewLine); builder.Append (indent); builder.Append ("/// <param name=\""); builder.Append (para.Name); builder.Append ("\">\n"); builder.Append (indent); builder.Append ("/// A <see cref=\""); builder.Append (ambience.GetString (para.ReturnType, OutputFlags.ClassBrowserEntries | OutputFlags.UseFullName | OutputFlags.UseNETTypeNames)); builder.Append ("\"/>\n"); builder.Append (indent); builder.Append ("/// </param>"); } } if (method.ReturnType != null && method.ReturnType.FullName != "System.Void") { builder.Append (Environment.NewLine); builder.Append (indent); builder.Append("/// <returns>\n"); builder.Append (indent); builder.Append ("/// A <see cref=\""); builder.Append (ambience.GetString (method.ReturnType, OutputFlags.ClassBrowserEntries | OutputFlags.UseFullName | OutputFlags.UseNETTypeNames)); builder.Append ("\"/>\n"); builder.Append (indent); builder.Append ("/// </returns>"); } }