I chanced upon this code written by the Solution Architect for an MS CRM project and I am lost for words. Am I going crazy or is this code OK?
string returnedOptionSetStringValue=string.Empty;
int returnedInt = 0;
Utils.RetrieveOptionSetLabelOrValue(CRMAccess.xrmService, Contact.EntityLogicalName, "new_status", optionSetValue.Value, string.Empty, ref returnedOptionSetStringValue, ref returnedInt, CRMAccess.tracerService);
The method within the Utils class is as follows
public static void RetrieveOptionSetLabelOrValue(IOrganizationService CrmWebService, string EntityName, string AttributeName, int OptionSetValue, string optionSetText, ref string returnedText, ref int returnedNumber, ITracingService tracerService)
{
string returnLabel = string.Empty;
tracerService.Trace("starting in function ");
OptionMetadataCollection optionsSetLabels = null;
tracerService.Trace("in retrieve option set label with values:" + OptionSetValue + " and text " + optionSetText);
optionsSetLabels = RetrieveOptionSetMetaDataCollection(ref CrmWebService, EntityName, AttributeName);
foreach (OptionMetadata optionMetdaData in optionsSetLabels)
{
tracerService.Trace("now in loop with " + optionMetdaData.Label.UserLocalizedLabel.Label + " and " + optionMetdaData.Value.Value);
//we have number we need text from optionset
if (OptionSetValue != 0)
{
if (optionMetdaData.Value == OptionSetValue)
{
returnedText = optionMetdaData.Label.UserLocalizedLabel.Label;
break;
}
}
//we have text we need number from optionset
else if (optionSetText != String.Empty)
{
if (optionMetdaData.Label.UserLocalizedLabel.Label == optionSetText)
{
returnedNumber = optionMetdaData.Value.Value;
break;
}
}
}
}
ref
for a method like this. Honestly, I have not seen a proper real use forref
. – Kanini Apr 30 '13 at 10:01