protected override object ImportFromObject(ImportContext context, JsonReader reader)
{
Debug.Assert(context != null);
Debug.Assert(reader != null);
object obj;
if (_constructor != null)
{
ObjectConstructionResult result = _constructor.CreateObject(context, reader);
obj = result.Object;
reader = result.TailReader;
reader.MoveToContent();
reader.Read();
}
else
{
reader.Read();
obj = Activator.CreateInstance(OutputType);
}
INonObjectMemberImporter otherImporter = obj as INonObjectMemberImporter;
while (reader.TokenClass != JsonTokenClass.EndObject)
{
string memberName = reader.ReadMember();
PropertyDescriptor property = _properties.Find(memberName, true);
//
// Skip over the member value and continue with reading if
// the property was not found or if the property found cannot
// be set.
//
if (property == null || property.IsReadOnly)
{
if (otherImporter == null || !otherImporter.Import(context, memberName, reader))
reader.Skip();
continue;
}
//
// Check if the property defines a custom import scheme.
// If yes, ask it to import the value into the property
// and then continue with the next.
//
if (_importers != null)
{
int index = _properties.IndexOf(property);
IObjectMemberImporter importer = _importers[index];
if (importer != null)
{
importer.Import(context, reader, obj);
continue;
}
}
//
// Import from reader based on the property type and
// then set the value of the property.
//
property.SetValue(obj, context.Import(property.PropertyType, reader));
}
return ReadReturning(reader, obj);
}