Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/Tizen.Pims.Contacts/Tizen.Pims.Contacts/ContactsRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ public ContactsRecord Clone()
/// <since_tizen> 4 </since_tizen>
public T Get<T>(uint propertyId)
{
object parsedValue = null;
if (typeof(T) == typeof(string))
{
string val;
Expand All @@ -211,7 +210,7 @@ public T Get<T>(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))
{
Expand All @@ -222,7 +221,7 @@ public T Get<T>(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))
{
Expand All @@ -233,7 +232,7 @@ public T Get<T>(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))
{
Expand All @@ -244,7 +243,7 @@ public T Get<T>(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))
{
Expand All @@ -255,14 +254,13 @@ public T Get<T>(uint propertyId)
Log.Error(Globals.LogTag, $"Get Long Failed with error {error}");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 [AI Review]
🟡 Suggestion: Pre-existing copy-paste in this double branch logs "Get Long Failed"; since this PR already rewrites these branches, it is worth fixing here (the Set double branch at line 323 has the same "Get Long" text).

Suggested change
Log.Error(Globals.LogTag, $"Get Long Failed with error {error}");
Log.Error(Globals.LogTag, $"Get Double Failed with error {error}");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 [AI Review]
Addressed in 3aa053e — the Get double branch now logs "Get Double Failed" and the Set double branch logs "Set Double Failed".

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;
}

/// <summary>
Expand All @@ -278,7 +276,7 @@ public void Set<T>(uint propertyId, T value)
{
if (typeof(T) == typeof(string))
{
string val = Convert.ToString(value);
string val = (string)(object)value ?? string.Empty;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since string is a reference type, you can use the as operator directly on the generic parameter value without needing to cast it to object first. This is more idiomatic and readable in C#.

                string val = value as string ?? string.Empty;

int error = Interop.Record.SetStr(_recordHandle, propertyId, val);
if ((int)ContactsError.None != error)
{
Expand All @@ -288,7 +286,7 @@ public void Set<T>(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)
{
Expand All @@ -298,7 +296,7 @@ public void Set<T>(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)
{
Expand All @@ -308,7 +306,7 @@ public void Set<T>(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)
{
Expand All @@ -318,7 +316,7 @@ public void Set<T>(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)
{
Expand Down
Loading