Home > Services > DXCore Services – Language

DXCore Services – Language

April 11th, 2011

The Language DXCore service is one of the most important services that provides access to the programming language fundamentals, including access to language extensions. Language extensions are DXcore plug-in extensions, which implement specific programming language support for Visual Studio, including parsers and code generators.

Lots of the methods of this service have two additional overloads, which take a string parameter identifying the programming language (e.g. “CSharp“, “Visual Basic“) or a LanguageExtensionBase instance of the particular language implementation. You are welcome to pass a specific value (a language you would like to work with) for these parameters, otherwise, the active language will be used, if they are not specified.

Here are the methods of this DXCore service:

Method Name Description
AddTypeSuffix Adds the type suffix (e.g. ‘*’ or ‘^’ in C++) for the specified full type name and element. This method will try to obtain a simple type name with the namespace stripped off.
ChangeElementSectionVisibility( AccessSpecifiedElement, MemberVisibility) Changes the visibility of the section of the specified element in the active text document. Note, visibility sections are used in C++ and F# languages.
CheckBaseMemberVirtualModifier Returns true if the virtual modifier should be checked when searching for a base member (in other words, current language has a serial members order, e.g. C++).
CheckQualifiedName(String, String) Returns true if the given name is qualified by the specified delimiter operators.
CheckSimpleName(String, String) Returns a simple name for the given name qualified by the specified delimiter operators.
CreateLanguageElement( LanguageElementType) Returns a new language element for the given language element type.
CreateParserFromLanguageID(String) Creates a new parser that is capable of parsing text documents matching the specified language ID.
DeclaresTypeBeforeName Returns true if the current language declares the type before the name in variable or parameter declarations (e.g. CSharp).
DisableLanguage(String) Disables parsing for the given language in the current Visual Studio session.
EnableAllLanguages Enables parsing for all languages.
EnableLanguage(String) Enables parsing for the given language.
ExtractFirstIdentifier(String) Removes the first identifier from the passed-in qualified name and returns that identifier. For example, if the qualified name is “System.Boolean“, this method will return “System” and will set the passed-in qualified name to “Boolean“.
GenerateElement( LanguageElement) Generates code for the given language element for the active language. Note, this method always adds a carriage return line feed at the end.
GenerateExpressionCode( Expression) Generates code for the given expression in the active language. Note, this method doesn’t add a carriage return line feed at the end.
GenerateXmlCode( XmlDocComment) Generates code for the given XmlDocComment for the active language.
GetActiveCodeDomProvider Returns a descendant of the CodeDomProvider type for the active language, if possible.
GetActiveCodeGenerator Returns the active code generator.
GetActiveElementBuilder Returns the active ElementBuilder instance.
GetActiveEnvDTEProject( ProjectElement) Returns an instance of the EnvDTE.Project for the given ProjectElement instance.
GetActiveExpressionCodeGenerator Returns the expression code generator for the active language.
GetActiveExpressionParser Returns the expression parser for the active language.
GetActiveLanguageID(IElement) Returns a language ID (as a string) for ASP.NET embedding, code nuggets, asp directives, scripts, or web event handlers.
GetBaseTypeName(String) Returns a simple type name (e.g. ‘bool‘) for the given type full name (“System.Boolean“).
GetBinaryOperatorType( PrimitiveType, PrimitiveType) Returns the resulting type after performing a binary operation on the two given types.
GetBlockNecessityInformation( ParentingStatement) Returns information about the resulting block for the given statement after inserting a new language element.
GetBuiltInTypeNarrowingConversionTable Returns an explicit conversion table for the built-in types.
GetBuiltInTypeWideningConversionTable Returns an implicit conversion table for the built-in types.
GetCaretLocation Return the current CaretLocation instance for the active language.
GetCodeBlockStart( LanguageElement, SourcePoint) Returns the first available insertion point for the given code block.
GetCodeDomProvider(String) Returns a descendant of the CodeDomProvider class for the specified language, if possible.
GetCodeGenerator( LanguageExtensionBase) Returns code generator for the given language extension.
GetCodeGenerator(String) Returns the code generator for the given language.
GetCollapsibleRange( LanguageElement) Returns a SourceRange representing the range of the specified LanguageElement that can be collapsed for the active language.
GetComment(String) Returns a single-line comment for the specified text in the active language.
GetContinueStatement Returns a continue statement for the given language, if supported.
GetDefaultAssemblyReferences( String) Returns a list of default assembly references for the given language (e.g. “Microsoft.VisualBasic” for VB).
GetDefaultValueExpression( PrimitiveExpression) Returns default value expression for the given primitive expression.
GetElementBuilder(String) Returns an ElementBuilder instance specific for the given language.
GetElementFullName( IElement) Returns a language specific full name for the given element.
GetEscapedString( String, Boolean) Returns an escaped version of the passed-in string. For example, in C# this would convert all \r’s to carriage-returns, all \n’s to line-feeds, etc.
GetExpressionCodeGenerator( String) Returns an expression code generator for the given language.
GetExpressionParser(String) Returns an expression parser for the given language.
GetFileLanguageID(SourceFile) Returns the language ID for the given SourceFile instance.
GetFullTypeName Returns a full type name for the given built-in type.
GetHexadecimalValuePresentation( Byte) Returns a hexadecimal value presentation (e.g. “0xFF” in C#, “HFF” in VB).
GetHexadecimalValuePresentation( Byte, String) Returns a hexadecimal value presentation (e.g. “0xFF” in C#, “HFF” in VB).
GetIdentifierFromKeyword(String) Returns an identifier from the keyword for the active language. If the passed-in string is not a keyword, then method does not process it.
GetImplementsCode(Interface, Member, Boolean) Returns the code for the given member implementation.
GetImportsStatement(String) Returns a properly-formatted Imports statement (VB) or using directive (C#) for the specified namespace. Returns an empty string, if an error occurs. This method is identical to GetUsingDirective.
GetLanguageElementCodeGenerator( LanguageElement, String) Returns the language element generator instance for the given language.
GetLanguageExtension(String) Returns a LanguageExtensionBase instance for the given language ID.
GetLanguageExtension- FromDotNetLanguageType( DotNetLanguageType) Returns a LanguageExtensionBase instance for the given DotNetLanguageType enumeration.
GetLanguageExtensionFromFileExt(String) Returns a LanguageExtensionBase instance for the given file extension.
GetLanguageID(DotNetLanguageType) Returns a language ID for the given DotNetLanguageType enumeration.
GetLanguageID(IElement) Returns a language ID for the given element.
GetLanguageID(String) Returns a language ID for the given file extension.
GetMacroExpansion(SourceFile, TextDocument, SourceRange) Returns a string, containing a full expansion of the specified macro.
GetNullCheck(String) Returns a language specific check for nullness.
GetNullReferenceExpression(String) Returns a null reference expression for the given language (e.g. ‘null‘ for C#, ‘Nothing‘ for Visual Basic).
GetObjectTypeReferenceExpression Returns a System.Object type reference expression.
GetOverloadableOperatorName( OperatorType, Int32) Returns an operator name (e.g. “op_Addition” for the given operator type.
GetParserFromFileExt(String) Returns a parser that is capable of parsing files matching the specified file extension.
GetParserFromLanguageID(String) Returns a parser that is capable of parsing text documents matching the specified language ID.
GetProjectLanguageID(Project) Returns a language ID for the given project.
GetProjectLoader(String) Returns a project loader for the given language.
GetRegionFooter Returns a properly formatted region directive footer.
GetRegionHeader(String) Returns a properly-formatted region directive header with the passed-in caption.
GetRegionHeaderAndFooter(String, String, String) Returns properly formatted region directive header and footer with the passed-in caption.
GetSealedKeyword Returns a sealed keyword (e.g. ‘sealed‘ in C#, ‘NotInheritable‘ in VB) for the active language, if supported.
GetSimpleName(String) Returns a simple name for the given full type name.
GetSimpleTypeName(String) Returns a simple type name for the given full type name.
GetSupportedFileExtensions(String) Returns a list of supported file extensions for the given language.
GetTokenCategory(Token) Returns a token category string.
GetTokens(String) Returns a collection of tokens from the given text.
GetTypeKindKeyword(TypeDeclaration) Returns a keyword that defines the given type declaration.
GetTypeParameterInitializer(String) Returns a default initializer for the specified type parameter name.
GetTypeSuffix(String) Returns a type suffix for the given type name. For example, ‘*’ or ‘^’ for C++ language.
GetUsingDirective(String) Returns a properly formatted ‘using’ directive (C#) or Imports statement (VB) for the specified namespace. Returns an empty string, if an error occurs. This method is identical to GetImportsStatement.
GetVariableModifier(String) Returns a variable modifier for the given language.
GetVariableRemoveRanges(Variable) Returns a list of SourceRanges for the given Variable. Useful for a multi-variable declarations.
GetVisibility(MemberVisibility, String) Returns a language specific ‘visibility’ keyword name.
GetXmlCodeGenerator(String) Returns a XmlDocComments generator for the given language.
HasManagedPointers Returns true if the current language uses managed pointers (e.g. C++).
HasSerialMembersOrder Returns true if the current language has serial members order (e.g. C++).
IdentifiersMatch(String, String) Returns true if the specified identifiers are equivalent.
ImplementInterface(TypeDeclaration, Interface) Implements the given interface for the given type.
InheritType(TypeDeclaration, TypeDeclaration) Inherits the specified type for the given type (makes the given type a descendant of the specified type).
IntroduceComments( LanguageElement, CommentCollection) Adds comments from the given comment collection to the specified language element node.
IsBaseInstanceKeyword(String, String) Returns true if the given string equals the ‘base’ instance keyword for the given language.
IsBasicLanguage(String) Returns true if the specified language is Visual Basic.
IsBuiltInType(String) Returns true if the given type name is a language built-in type name (e.g. “object” in C#, “Object” in VB).
IsCaseSensitiveLanguage(String) Returns true if the language is case-sensitive.
IsClassInstanceKeyword(String, String) Returns true if the given string equals a class instance keyword for the given language.
IsCode(CaretLocation) Determines if a CaretLocation is inside the source code.
IsCollapsible(LanguageElement) Determines whether or not the specified LanguageElement is collapsible for the active language.
IsComment(CaretLocation) Determines if the specified CaretLocation is a comment.
IsCPlusPlusLanguage(String) Returns true if specified language is C/C++.
IsCSharpLanguage(String) Returns true if specified language is CSharp.
IsDefaultPrimitiveValue( ITypeElement, IExpression) Returns true if the given expression is primitive and has a default value for the specified type.
IsExtensionMethod(IMethodElement) Returns true if the given method is an extension method.
IsHTML_XMLLanguage(String) Returns true if the specified language is HTML/XML.
IsHtmlLanguage(String) Returns true if the specified language is HTML.
IsHtmlOrXmlLanguage(String) Returns true if the specified language is HTML/XML.
IsInCPlusPlus(IElement) Returns true if the specified element is inside the C/C++ language.
IsInCSharp(IElement) Returns true if the specified element is inside the CSharp language.
IsInVisualBasic(IElement) Returns true if the specified element is inside the Visual Basic language.
IsJavaScriptLanguage(String) Returns true if the specified language is JavaScript.
IsKeyword(String) Returns true if the specified string is a legal keyword for the active language.
IsKeyword(String, String) Returns true if the specified name is a keyword for the given language.
IsKeywordElement(IElement) Returns true if the specified element is a keyword element for the active language.
IsLanguageCaseSensitive(IElement) Returns true if the given element’s language is case-sensitive.
IsLanguageDisabled(String) Returns true if parsing for the specified language is disabled.
IsLeadingIdentifierChar(Char) Returns true if the given character qualifies as a character that can start an identifier.
IsNativeType(TypeDeclaration) Returns true if the given type declaration is native (not managed).
IsNumber(String) Returns true if the specified string is a legal number for the active language.
IsOptionExplicitOff(IElement) Returns true if the Explicit option is off for the source file of the specified element.
IsOptionInferOff(IElement) Returns true if the Infer option is off for the source file of the specified element.
IsOptionStrictOff(IElement) Returns true if the Strict option is off for the source file of the specified element.
IsPlainTextLanguage(String) Returns true if the specified language is plain text.
IsQualifiedName(String) Returns true if the given name is qualified.
IsSimpleIdentifier(String) Returns true if the specified string is a legal simple identifier for the active language. A simple identifier typically starts with an alpha character, and can include numbers and the underscore character. Parens, brackets, and internal whitespace around member access operators (e.g., “A . B . C” instead of “A.B.C”) are not included in this evaluation.
IsString(CaretLocation) Returns true if the specified CaretLocation is a string.
IsTrailingIdentifierChar(Char) Returns true if the given character qualifies as a character that can follow the first character of an identifier.
IsVisualJSharpLanguage(String) Returns true if the specified language is Visual JSharp.
IsXAMLLanguage(String) Returns true if the specified language is XAML.
IsXMLLanguage(String) Returns true if the specified language is XML.
LoadProject(Project) Loads a project and returns its instance (as a ProjectElement) from the given EnvDTE.Project reference.
NeedChangeLanguage Returns true if the current language should be changed. For example, if the given element is an ASP code embedding, html script definition, or the element is inside a web handler file, web event handler, or inside a code nugget, this function will return true.
Parse(LanguageElement, RegionDirective, TextStringCollection, CompilerDirective, TextDocument, SourceRange) Parses the specified source range of the given text document with the given context, and returns the LanguageElement that specifies it. Nodes parsed in the specified range will be appended to the end of the context’s nodes. Does not trigger the BeforeParse or AfterParse events, nor does this method call BindToCode – the calling client code must do that (this allows the calling code to bind only the nodes within the parse range, and also append any trailing nodes to the end of the newly-parsed nodes).
Parse(LanguageElement, TextDocument, SourceRange) Parses the specified source range of the given text document with the given context and returns the LanguageElement that specifies it.
Parse(ParserContext) Parses the specified source range of the given text document with the given context, and returns the LanguageElement that specifies it. Nodes parsed in the specified range will be appended to the end of the context’s nodes. Does not trigger the BeforeParse or AfterParse events, nor does this method call BindToCode – the calling client code must do that (this allows the calling code to bind only the nodes within the parse range, and also append any trailing nodes to the end of the newly-parsed nodes).
Parse(String) Parses the specified source file on disk and returns the LanguageElement that specifies it.
Parse(TextDocument) Parses the specified text document and returns the LanguageElement that specifies it.
ParseActiveDocument Parses the active text document and returns the LanguageElement that specifies it.
ParseDocument(TextDocument) Parses the specified text document.
ParseExpression(String) Parses an expression from the given string.
ParseString(String, String) Parses the specified string and returns the LanguageElement that specifies it.
ParseTypeReferenceExpression( String, Int32, Int32, String) Parses an expression from the given string.
RemoveKeywordEscapeCharacters- FromIdentifier( String) Removes keyword escape characters (like ‘@’ in C#, or ‘[]’   in VB) from an identifier name.
SupportsAutoImplementedProperty- AccessorVisibility Returns true if the given language supports a visibility keyword for auto-implemented properties.
SupportsDecoupledForeachDeclaration( String) Returns true if the given language supports a decoupled declaration of the ‘foreach’ iteration variable.
SupportsFileBuildAction(String) Returns true if the build action for a source file can be checked for the given language.
SupportsImplicitPointers Returns true if the active language supports implicit pointer declarations, e.g. return true for C# or VB languages. C++ language requires explicit pointers.
SupportsMacroses(String) Returns true if the given language supports macros.
SupportsMultiLineComments(String) Returns true if the given language supports multi-line comments.
SupportsNestedLanguages(String) Returns true if the given language supports nested languages.
SupportsNestedNamespaceSearch(String) Returns true if the given language supports searching of the nested namespaces.
SupportsObjectCreationFromMethod( String) Returns true if the given language supports creation of new objects using a method declaration.
SupportsOutParameters(String) Returns true if the given language supports out parameters.
SupportsParenslessCalls(String) Returns true if the given language supports method calls without parens (e.g. Visual Basic).
SupportsPartialClasses Returns true if the active language supports partial classes.
SupportsPopulatingAnArrayWith- InitialValues(IElement) Returns true if the language of the given element supports populating an array with initial values. For example, Visual Basic version 10 supports it.
SupportsPrototypesAndImplementations( String) Returns true if the given language supports prototypes and implementations (e.g. C++).
SupportsRootMembers(String) Returns true if members can be placed directly to the file or namespace (e.g. C++).
SupportsRootNamespace(String) Returns true if the given language supports the root namespace.
SupportsTypes(String) Returns true if the given language supports type declarations.
ToFileExt(String) Returns a file extension based on the specified language ID. Illegal characters are removed or converted to legal characters. If the specified language ID is empty, this method returns an empty string.
TypesMatch(String, String) Returns true if the specified types are equivalent. This method converts the specified types to simple equivalents if they exist in the active language (e.g., “System.Boolean” becomes “bool” in C#).

Properties:

Property Name Description
Active Returns the language ID of the active source file.
ActiveExtension Returns the active DXCore LanguageExtensionBase instance, or null if no language extension is available for the active programming language.
ActiveParser Returns the active language parser, or null if no parser is available for the active programming language.
AllKnownLanguages Returns a list of all known languages registered in the IDE.
ClassInstanceKeyword Returns the keyword for accessing the current instance of the class in a method (e.g. ‘this’ for C#).
DisabledLanguages Returns the list of language ID’s with disabled parsing.
IsBasic Returns true if the active file contains Visual Basic source code.
IsCaseSensitive Returns true if the active file contains a case-sensitive language.
IsCPlusPlus Returns true if the active file contains C/C++ source code.
IsCSharp Returns true if the active file contains CSharp source code.
IsHtml Returns true if the active file has an HTML language id.
IsHTML_XML Returns true if the active file has an HTML/XML language id.
IsHtmlOrXml Returns true if the active file has an HTML/XML language id or HTML language id.
IsJavaScript Returns true if the active file contains JavaScript source code.
IsNativeCPlusPlus Returns true if the active file is inside a native C++ project.
IsPlainText Returns true if the active file contains plain text.
IsVisualJSharp Returns true if Visual JSharp is the language used in the active file.
IsXAML Returns true if the active file has XAML language ID.
IsXML Returns true if the active file has XML language ID.
LineContinuationCharacter Gets line continuation character for the active language (e.g., “_” in VB). Returns an empty string if the active language does not support the line continuation character.
MemberAccessOperator Gets the member access operator (e.g., “.” in C# and VB) for the active language. Returns an empty string if the active language does not support a member access operator.
PointerAccessOperator Gets the character for accessing the members of a struct, class or an interface via a pointer.
StatementTerminator Gets the statement terminator for the active language. For example, in C#, statements are terminated with a semi-colon.
SupportedFileExtensions Gets supported file extensions for the active language.
SupportsCLRSettings Determines whether or not the active language supports CLR settings.
SupportsConstantDeclarations Determines whether or not the active language supports constant declarations.
SupportsTernaryExpressions Determines whether or not the active language supports ternary expressions.
SupportsVisibilitySections Determines whether or not the active language supports visibility sections.
SupportsWithStatement Determines whether or not the active language supports ‘with’ statements.
TypeAccessOperator Returns the character for accessing the nested elements of a type.
—–
Products: DXCore
Versions: 10.2 and up
VS IDEs: any
Updated: Sep/24/2011
ID: D075

Similar Posts: