Share via


How to: Create Custom Data Generators

Custom data generators are components that the Data Generator feature uses to generate data in data generation plans. Although the Data Generator feature supplies several preset generators, you might want to create custom generators to suit your particular needs.

This topic describes how to create a custom data generator using typical extensibility. Typical extensibility is the recommended method to use most of the time. You can also use other methods to create custom data generators, including declarative extensibility, aggregation extensibility, and base extensibility. For more information, see An Overview of Data Generator Extensibility.

To create a custom data generator

  1. Create a class library project.

  2. In Solution Explorer, right-click the project, and then click Add Reference.

    The Add Reference dialog box appears.

  3. Click the .NET tab. In the Component Name list, click Microsoft.VisualStudio.TeamSystem.Data, and then click OK.

  4. (Optional, Visual Basic only) In Solution Explorer, click the Show All Files button, and expand the References node to verify the new reference.

  5. At the top of the Code window, before the class declaration, add the following line of code:

    Imports Microsoft.Data.Schema.DataGenerator
    
    using Microsoft.Data.Schema.DataGenerator;
    
  6. Rename the class from Class1 to the name that you want.

    Warning

    By default, the name that you give your class is the name that will appear in the list in the Generator column in the Column Details window. You should specify a name that does not conflict with either the name of a standard generator or the name of another custom generator. For more information, see Considerations for Custom Data Generators.

    Public Class YourGeneratorName
    
    End Class
    
    public class YourGeneratorName
    {
    }
    
  7. Specify that your class inherits from Generator, as shown in the following example:

    Public Class YourGeneratorName
        Inherits Generator
    
    End Class
    
    public class YourGeneratorName: Generator
    {
    }
    
  8. (Optional) Add the GeneratorStylesAttribute to the class declaration.

    Important noteImportant Note:

    If you want your custom data generator to be the default data generator for a type of column, it must produce unique values, and you must add the GeneratorStylesAttribute to the class. For more information, see How to: Change the Default Generator for a Column Type.

    <GeneratorStyles(DesignerStyles:=GeneratorDesignerStyles.CanProduceUniqueValues)> _
    Public Class TestGenerator
        Inherits Generator
    
    End Class
    
    [GeneratorStyles(DesignerStyles = GeneratorDesignerStyles.CanProduceUniqueValues)]
    public class TestGenerator:Generator
    {
    }
    
  9. (Optional) Add the GeneratorAttribute to the class declaration.

    Warning

    Add this attribute to the class declaration only if you want to specify a custom designer type for your custom data generator. If you do not want to specify a custom designer type, omit this attribute, and the default designer will be used automatically.

    <Generator(GetType(CustomDesignerType))> _
    Public Class TestGenerator
        Inherits Generator
    
    End Class
    
    [Generator(typeof(CustomDesignerType))]
    public class TestGenerator:Generator
    {
    }
    
  10. Add at least one output property. For more information, see How to: Add Output Properties to a Data Generator.

  11. If needed, add input properties. For more information, see How to: Add Input Properties to a Data Generator.

  12. Implement the OnGenerateNextValues() method to generate appropriate values for each output property. For more information, see Walkthrough: Creating a Custom Data Generator.

  13. Sign the assembly with a strong name. For more information, see Walkthrough: Creating a Custom Data Generator.

  14. Build the solution.

  15. Register the new generator with Visual Studio. For more information, see How to: Register a Custom Generator and Walkthrough: Creating a Custom Data Generator.

See Also

Tasks

Walkthrough: Creating a Custom Data Generator

Other Resources

Creating Custom Data Generators