Is There a 'Standard' Set of ClassificationFormatDefinitions Available Anywhere? RRS feed

  • Question

  • The MEF language samples (such as Ook Language Integration and IronPython Integration) all seem to define their own ClassificationFormatDefinition derived classes and hard-code values like this.ForegroundColor.  That makes a lot of sense for a sample that's trying to demonstrate how (amongst other things) ClassificationFormatDefinitions classes are defined and used.

    However, I'm thinking that most language implementations would want to use the Visual Studio 'standard' ClassificationTypes like Comment, Keyword, String, etc. and would want to use the corresponding colours and fonts defined via Tools | Options | Environment | Fonts and Colors.

    Are suitable ClassificationTypes and ClassificationFormatDefinitions implemented somewhere within MEF or does each language implementation have to implement all that stuff?  Or, have I so failed to grasp how MEF works that my question doesn't even make sense?

    • Edited by Frank Boyne Sunday, October 17, 2010 6:26 AM fix typo
    Sunday, October 17, 2010 6:25 AM


  • Hi Frank,

    Your question makes perfect sense. I answered a similar post last night with the following:

    The standard classifications are defined by the PredefinedClassificationTypeNames class. For the OokLanguage sample you would simply plug these into your OokClassifier ctor as follows:

    internal OokClassifier(ITextBuffer buffer, ITagAggregator<OokTokenTag> ookTagAggregator, IClassificationTypeRegistryService typeService)
       _buffer = buffer;
       _aggregator = ookTagAggregator;
       _ookTypes =
    new Dictionary<OokTokenTypes, IClassificationType>();
       _ookTypes[OokTokenTypes.OokExclaimation] = typeService.GetClassificationType(PredefinedClassificationTypeNames.Comment);
    OokTokenTypes.OokPeriod] = typeService.GetClassificationType(PredefinedClassificationTypeNames.Literal);
    OokTokenTypes.OokQuestion] = typeService.GetClassificationType(PredefinedClassificationTypeNames.Keyword);

    You'll probably also want to remove the exports defining the various exports in the ClassificationFormat.cs. I noticed these don't show up in the Fonts and Colors dialog (due to the UserVisible attribute being set to false), but given you want to use the the standard classification types, these wouldn't be necessary. Ideally, this should have been worked into the IronPythonIntegration sample, but I suspect the sample author wanted to illustrate how to add new types. I haven't tried it, but I suspect all you need to do is swap out the custom classification types returned by the PyClassifier.GetClassificationType, to do something similar for the IronPythonIntegration sample.


    Ed Dore
    Tuesday, October 26, 2010 2:49 PM