/// <summary> /// Handles changing between types /// </summary> /// <param name="propDetails">The cached details for the current property</param> /// <param name="newSelection">The new selection</param> protected void HandleTypeChange(CacheItem propDetails, string newSelection) { Type selectedType = Type.GetType(newSelection); if (selectedType != null && selectedType == propDetails.SelectedType) { return; } Undo.RegisterCompleteObjectUndo( propDetails.ReferenceInformation.Owner.targetObject, "Poco Info"); SerializedPoco poco = propDetails.ReferenceInformation.PocoInstance; System.Object oldItem = poco.Value; MethodInfo method = typeof(SerializedPoco).GetMethod("SerializePoco", BindingFlags.NonPublic | BindingFlags.Instance); string serialized = method.Invoke(poco, new object[] { false }) as string; propDetails.ClearPocoValue(); propDetails.SetType(newSelection); propDetails.ReferenceInformation.ResetInstanceData(); // If the new type is a POCO if (propDetails.Display == DisplayMode.SystemObjectDisplay) { InitializePoco(propDetails); if (oldItem != null && propDetails.SelectedType != null) { // Determine if the new type is a parent or descendant of the old // type so that we can transfer some of the properties if (propDetails.SelectedType.IsSubclassOf(oldItem.GetType()) || oldItem.GetType().IsSubclassOf(propDetails.SelectedType)) { MethodInfo deserialize = typeof(SerializedPoco).GetMethod("DeserializePoco", BindingFlags.NonPublic | BindingFlags.Instance); deserialize.Invoke(poco, new object[] { poco.Value, serialized }); propDetails.ReferenceInformation.Owner.ApplyModifiedProperties(); propDetails.ReferenceInformation.Owner.Update(); // Clear the cache to force a re-draw since there is something // that I am caching that prevents the update drawerCache.Clear(); } } } }