Skip to content
Open
Changes from all commits
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
26 changes: 12 additions & 14 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,25 +243,24 @@ 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))
{
double val;
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);
}
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 = 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,11 +316,11 @@ 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)
{
Log.Error(Globals.LogTag, $"Get Long Failed with error {error}");
Log.Error(Globals.LogTag, $"Set Double Failed with error {error}");
throw ContactsErrorFactory.CheckAndCreateException(error);
}
}
Expand Down
Loading