How to: Create Custom Data Generators
Custom data generators are components that Data Generator can use to generate data in data generation plans. Although Data Generator 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 normal extensibility. Normal extensibility is the recommended method to use in most cases. 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 generator
Create a class library project.
In Solution Explorer, right-click the project, and click Add Reference.
The Add Reference dialog box appears.
Click the .NET tab, in the Component Name list, click Microsoft.VisualStudio.TeamSystem.Data, and then click OK.
(Optional, Visual Basic only) In Solution Explorer, click the Show All Files button, and expand the References node to verify the new reference.
At the top of the Code window, before the class declaration, add the following line of code:
Imports Microsoft.VisualStudio.TeamSystem.Data.DataGenerator
using Microsoft.VisualStudio.TeamSystem.Data.DataGenerator;
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 appears in the list in the Generator column in the Column Details window. You should specify a name that does not conflict with the name of a standard generator or of another custom generator. For more information, see Considerations for Custom Data Generators.
Public Class YourGeneratorName End Class
public class YourGeneratorName { }
Specify that your class inherits from Generator, as shown in the following example:
Public Class YourGeneratorName Inherits Generator End Class
public class YourGeneratorName: Generator { }
(Optional) Add the GeneratorStylesAttribute to the class declaration.
Important
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 { }
(Optional) Add the GeneratorAttribute to the class declaration.
Warning
You must add the GeneratorAttribute to the class 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, you can omit this attribute, and the default designer is used automatically.
<Generator(GetType(CustomDesignerType))> _ Public Class TestGenerator Inherits Generator End Class
[Generator(typeof(CustomDesignerType))] public class TestGenerator:Generator { }
Add at least one output property. For more information, see How to: Add Output Properties to a Data Generator.
If needed, add input properties. For more information, see How to: Add Input Properties to a Data Generator.
Implement the OnGenerateNextValues method to generate appropriate values for each output property. For more information, see Walkthrough: Creating a Custom Data Generator.
Sign the assembly with a strong name. For more information, see Walkthrough: Creating a Custom Data Generator.
Build the solution.
Register the new generator with Visual Studio. For more information, see How to: Register Custom Data Generators.
Security
For more information, see Security of Data Generators.