// Load serialized data into object public void Load(object obj) { if (!PropertySchema.IsLoadable) { TypeRepo.LoadLazyObjectRef(); // skip reference if (LazyProperty != null) { LazyProperty.FieldInfoLoaded.SetValue(obj, true); } } else if (LazyProperty != null) { TypeRef typeRef = TypeRepo.LoadLazyObjectRef(); LazyProperty.SetTypeRef(obj, typeRef); } else { object valueObject = TypeRepo.LoadObjectRef(); // can throw System.ArgumentException, set to null if not Loadable? // Should we add exception handling or detect this earlier when we load the schema? // Don't set the property if it's already set to the default, some objects track property assignments if (TypeRepo.TypeSchema.IsPrimitive) { // todo: construct temp object and store default instead for speed? dynamic currentValue = PropertySchema.PropertyInfo.GetValue(obj); if ((dynamic)valueObject == currentValue) { return; } } PropertySchema.PropertyInfo.SetValue(obj, valueObject); } }