In this case, your type itself should be common.
class GridConfigurator<TData, TGrid> where TData : class { public DataGridForm<TData, TGrid> DataGrid { get; private set; } public DataGridForm<TData, TGrid> GridConfig<TData, TGrid>() { return DataGrid = new DataGridForm<TData, TGrid>(); } }
But I do not understand the purpose of this class. The GridConfig method has an unobvious side effect of setting the DataGrid property (which has a private setter). If I used this class, I would never have guessed that the value returned to me by GridConfig () is also set as a DataGrid property. In other words:
var configurator = new GridConfigurator(); var firstGrid = configurator.GridConfig(); var firstReference = configurator.DataGrid; var secondGrid = configurator.GridConfig(); var secondReference = configurator.DataGrid;
I would suggest that the following returns false:
object.ReferenceEquals(firstGrid, secondGrid);
But I would suggest that this will return true :
object.ReferenceEquals(firstReference, secondReference);
Because in no case in the above code I never assign the DataGrid property. It is not clear that the GridConfig () method would have such an effect.
Creating a closing type (GridConfigurator) also tends to hit the target of what you are trying to do. Why would anyone use this type if they can just use the direct link to the DataGridForm?
If the GridConfig method needs to do more than just assign a new instance of the DataGridForm by default, then make it a static factory class as follows:
static class GridConfigurator { public static DataGridForm<TData,TGrid> GridConfig<TData, TGrid>(...) where TData: class { var grid = new DataGridForm<TData,TGrid>();
I would also call the method something other than GridConfig. Like Configure () or Create ().