From f27240c65091b5f2977f8a4b5edcfe731a144542 Mon Sep 17 00:00:00 2001 From: Jay Cho Date: Sun, 19 Jul 2026 20:05:06 +0900 Subject: [PATCH 1/2] Refactor: Replace Convert.ChangeType boxing with direct casts in ContactsRecord Get/Set (Fixes #7667) Co-Authored-By: Claude Fable 5 --- .../Tizen.Pims.Contacts/ContactsRecord.cs | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/ContactsRecord.cs b/src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/ContactsRecord.cs index da6bcffc7b6..b56f2dc228e 100644 --- a/src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/ContactsRecord.cs +++ b/src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/ContactsRecord.cs @@ -201,7 +201,6 @@ public ContactsRecord Clone() /// 4 public T Get(uint propertyId) { - object parsedValue = null; if (typeof(T) == typeof(string)) { string val; @@ -211,7 +210,7 @@ public T Get(uint propertyId) Log.Error(Globals.LogTag, $"Get String Failed with error {error}"); throw ContactsErrorFactory.CheckAndCreateException(error); } - parsedValue = Convert.ChangeType(val, typeof(T)); + return (T)(object)val; } else if (typeof(T) == typeof(int)) { @@ -222,7 +221,7 @@ public T Get(uint propertyId) Log.Error(Globals.LogTag, $"Get Int Failed with error {error}"); throw ContactsErrorFactory.CheckAndCreateException(error); } - parsedValue = Convert.ChangeType(val, typeof(T)); + return (T)(object)val; } else if (typeof(T) == typeof(bool)) { @@ -233,7 +232,7 @@ public T Get(uint propertyId) Log.Error(Globals.LogTag, $"Get Bool Failed with error {error}"); throw ContactsErrorFactory.CheckAndCreateException(error); } - parsedValue = Convert.ChangeType(val, typeof(T)); + return (T)(object)val; } else if (typeof(T) == typeof(long)) { @@ -244,7 +243,7 @@ public T Get(uint propertyId) Log.Error(Globals.LogTag, $"Get Long Failed with error {error}"); throw ContactsErrorFactory.CheckAndCreateException(error); } - parsedValue = Convert.ChangeType(val, typeof(T)); + return (T)(object)val; } else if (typeof(T) == typeof(double)) { @@ -255,14 +254,13 @@ public T Get(uint propertyId) Log.Error(Globals.LogTag, $"Get Long Failed with error {error}"); throw ContactsErrorFactory.CheckAndCreateException(error); } - parsedValue = Convert.ChangeType(val, typeof(T)); + return (T)(object)val; } else { Log.Error(Globals.LogTag, "Not Supported Data Type"); throw ContactsErrorFactory.CheckAndCreateException((int)ContactsError.NotSupported); } - return (T)parsedValue; } /// @@ -278,7 +276,7 @@ public void Set(uint propertyId, T value) { if (typeof(T) == typeof(string)) { - string val = Convert.ToString(value); + string val = (string)(object)value ?? string.Empty; int error = Interop.Record.SetStr(_recordHandle, propertyId, val); if ((int)ContactsError.None != error) { @@ -288,7 +286,7 @@ public void Set(uint propertyId, T value) } else if (typeof(T) == typeof(int)) { - int val = Convert.ToInt32(value); + int val = (int)(object)value; int error = Interop.Record.SetInt(_recordHandle, propertyId, val); if ((int)ContactsError.None != error) { @@ -298,7 +296,7 @@ public void Set(uint propertyId, T value) } else if (typeof(T) == typeof(bool)) { - bool val = Convert.ToBoolean(value); + bool val = (bool)(object)value; int error = Interop.Record.SetBool(_recordHandle, propertyId, val); if ((int)ContactsError.None != error) { @@ -308,7 +306,7 @@ public void Set(uint propertyId, T value) } else if (typeof(T) == typeof(long)) { - long val = Convert.ToInt64(value); + long val = (long)(object)value; int error = Interop.Record.SetLli(_recordHandle, propertyId, val); if ((int)ContactsError.None != error) { @@ -318,7 +316,7 @@ public void Set(uint propertyId, T value) } else if (typeof(T) == typeof(double)) { - double val = Convert.ToDouble(value); + double val = (double)(object)value; int error = Interop.Record.SetDouble(_recordHandle, propertyId, val); if ((int)ContactsError.None != error) { From 3aa053e35a648607357618ff9c72164f7a05bd15 Mon Sep 17 00:00:00 2001 From: Jay Cho Date: Sat, 25 Jul 2026 11:54:02 +0900 Subject: [PATCH 2/2] Address review feedback Fix copy-paste log messages in the double branches of Get/Set and use 'as' cast for the string path in Set Applied-Human-Comments: 3610427947 Applied-AI-Comments: 3611527170 --- .../Tizen.Pims.Contacts/ContactsRecord.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/ContactsRecord.cs b/src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/ContactsRecord.cs index b56f2dc228e..41da79c66f9 100644 --- a/src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/ContactsRecord.cs +++ b/src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/ContactsRecord.cs @@ -251,7 +251,7 @@ public T Get(uint propertyId) int error = Interop.Record.GetDouble(_recordHandle, propertyId, out val); if ((int)ContactsError.None != error) { - Log.Error(Globals.LogTag, $"Get Long Failed with error {error}"); + Log.Error(Globals.LogTag, $"Get Double Failed with error {error}"); throw ContactsErrorFactory.CheckAndCreateException(error); } return (T)(object)val; @@ -276,7 +276,7 @@ public void Set(uint propertyId, T value) { if (typeof(T) == typeof(string)) { - string val = (string)(object)value ?? string.Empty; + string val = value as string ?? string.Empty; int error = Interop.Record.SetStr(_recordHandle, propertyId, val); if ((int)ContactsError.None != error) { @@ -320,7 +320,7 @@ public void Set(uint propertyId, T value) int error = Interop.Record.SetDouble(_recordHandle, propertyId, val); if ((int)ContactsError.None != error) { - Log.Error(Globals.LogTag, $"Get Long Failed with error {error}"); + Log.Error(Globals.LogTag, $"Set Double Failed with error {error}"); throw ContactsErrorFactory.CheckAndCreateException(error); } }