Здравствуйте, Dimsen, Вы писали:
D>Если я правильно догоняю, то здесь используется специальное вспомогательное поле, указывающее реальный тип объекта.
Нет. Поле указывает тип фабрики объектов. Реализация фабрики Ваше личное дело.
Я у себя тупо храню в каждом поле полное имя типа объекта (иногда вместе с именем сборки). Вот кусок кода, создающий объекты:
public object CreateInstance(TypeAccessor typeAccessor, InitContext context)
{
// Get the object type indicator field.
//
string objectTypeName = (string)context.DataSource.GetValue(context.SourceObject, "ReportDimType");
if (string.IsNullOrEmpty(objectTypeName))
{
context.ObjectMapper = ObjectMapper<ReportDimension>.Instance;
}
else
{
Type dimType;
string libFileName = (string)context.DataSource.GetValue(context.SourceObject, "LibFileName");
if (string.IsNullOrEmpty(libFileName))
{
dimType = FindType("Sopstk.Core.dll", objectTypeName);
if (null == dimType)
dimType = FindType("CBossReports.dll", objectTypeName);
}
else
dimType = FindType(libFileName, objectTypeName);
Debug.Assert(null != dimType && typeof(ReportDimension).IsAssignableFrom(dimType));
context.ObjectMapper = Map.GetObjectMapper(dimType ?? typeof(ReportDimension));
}
// Create an object instance.
// Do not call ObjectMapper.CreateInstance as it will lead to infinite recursion.
//
return context.ObjectMapper.TypeAccessor.CreateInstance(context);
}
... << RSDN@Home 1.2.0 alpha rev. 642>>