Hello,
I want to set default values in C# by nullable value in some common function which will set value based on field value otherwise it will default value as NULL. I want to set default values for GUID, Entityreference, DateTime, Optionsetvalue and String.
Please suggest how to set default values by null checking .
public object SetAttributeValue(string attributeType, object attributevalue, bool isFormattedValue )
{
object value = null;
bool IsFalse = false;
bool isAliasedValue = objEntity[attribute] is AliasedValue ? !IsFalse : IsFalse;
switch (attributeType)
{
case "EntityReference":
// Need code to set default value for entity reference where i will pass entity reference value and need to extract guid and return guid else set default guid.
break;
case "Guid":
//Need to check if AttributeValue has value otherwise set default guid if it NUll
break;
case "DateTime":
// value= Convert.ToDateTime(attributevalue) ? null : (Convert.ToDateTime(attributevalue));
value = Convert.ToDateTime(attributevalue) : Convert.ToString(attributevalue);
break;
case "OptionSetValue":
value = (Convert.ToInt32(attributevalue)) == 0 ? null : new OptionSetValue(Convert.ToInt32(attributevalue));
break;
default:
value = string.IsNullOrWhiteSpace(Convert.ToString(attributevalue)) ? null : (Convert.ToString(attributevalue));
break;
}
return value;
*This post is locked for comments