Using Microsoft's UITypeEditors With The OOTB List<T> Editor

19 ביולי 2011

This post is a sequel to a previous post – The TFS Build Definition List<T> OOTB UITypeEditor.

In my previous post I showed how easy and cheep it is to use the TFS’s build definition OOTB “List<T>” editor.
We even saw that if we use enum’s or Boolean's the “List<T>” editor’s properties grid gives us drop-down editors for them, but what if we want to use more advanced editors; such as the “ServerFileBrowserEditor” to select a project from the source control or the “PlatformConfigurationListEditor” editor to choose in which configurations and platforms I want to compile the project or any other editor?

Well it seems to be extremely easy as well. All we need to do is take the same object we were using before:

   1: using System.Collections.Generic;

   2: using System.ComponentModel;

   3: using System.Drawing.Design;

   4: using BuildDemosC.Common.Enums;

   5: using Microsoft.TeamFoundation.Build.Workflow.Activities;

   6:  

   7: namespace BuildDemosC.CustomTypes

   8: {

   9:     public class DevEnvCompilationItem

  10:     {

  11:         [Category("Properties")]

  12:         public string Project { get; set; }

  13:  

  14:         [DisplayName("Compiler Name")]

  15:         [Category("Properties")]

  16:         public DevEnvType CompilerName { get; set; }

  17:  

  18:         #region Methods

  19:  

  20:         public override string ToString()

  21:         {

  22:             return string.IsNullOrEmpty(Project) ? "New" : Project + "=>" + CompilerName;

  23:         }

  24:  

  25:         #endregion

  26:  

  27:     }

  28: }

and add the “Editor” attribute with the editor we want to use over the property we want to use it with:

   1: using System.Collections.Generic;

   2: using System.ComponentModel;

   3: using System.Drawing.Design;

   4: using BuildDemosC.Common.Enums;

   5: using Microsoft.TeamFoundation.Build.Workflow.Activities;

   6:  

   7: namespace BuildDemosC.CustomTypes

   8: {

   9:     public class DevEnvCompilationItem

  10:     {

  11:         [Editor("Microsoft.TeamFoundation.Build.Controls.ServerFileBrowserEditor, Microsoft.TeamFoundation.Build.Controls", typeof(UITypeEditor))]

  12:         [Category("Properties")]

  13:         public string Project { get; set; }

  14:  

  15:         [DisplayName("Compiler Name")]

  16:         [Category("Properties")]

  17:         public DevEnvType CompilerName { get; set; }

  18:  

  19:         #region Methods

  20:  

  21:         public override string ToString()

  22:         {

  23:             return string.IsNullOrEmpty(Project) ? "New" : Project + "=>" + CompilerName;

  24:         }

  25:  

  26:         #endregion

  27:  

  28:     }

  29: }

After we check-in our changes, open a new instance of visual studio (So it will load the new dll files) and go to the build definition this is what will see when we came to edit our object list:

image

Easy, elegant, cheep! 🙂

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

3 תגובות

  1. Kumar25 ביולי 2011 ב 16:08

    Thank you.

    What type of project is this?
    Is this a code activity project or a usual library?

    I'm unable to refer the class from template

    הגב
  2. Kumar25 ביולי 2011 ב 17:01

    Also,
    Can you please attach your code?

    הגב
  3. Oshry Horn15 באוגוסט 2011 ב 11:39

    Hi Kumar,

    1) This is a simple class library project.

    2) in order to refer to the class from the template you must do the following: Take the project's dll/'s and add it/them to the folder in the source control to which the build controller you're using is referring as its assemblies directory.

    3) I have already added the code; it is posted above.

    הגב