private string ExpressionToString(UtilityTraceConditionalExpression expression)
 {
     if (expression is UtilityCategoryComparison categoryComparison)
     {
         return($"`{categoryComparison.Category.Name}` {categoryComparison.ComparisonOperator}");
     }
     else if (expression is UtilityNetworkAttributeComparison attributeComparison)
     {
         // Check if attribute domain is a coded value domain.
         if (attributeComparison.NetworkAttribute.Domain is CodedValueDomain domain)
         {
             // Get the coded value using the the attribute comparison value and attribute data type.
             UtilityNetworkAttributeDataType dataType = attributeComparison.NetworkAttribute.DataType;
             object     attributeValue = ConvertToDataType(attributeComparison.Value, attributeComparison.NetworkAttribute.DataType);
             CodedValue codedValue     = domain.CodedValues.FirstOrDefault(value => ConvertToDataType(value.Code, dataType).Equals(attributeValue));
             return($"`{attributeComparison.NetworkAttribute.Name}` {attributeComparison.ComparisonOperator} `{codedValue?.Name}`");
         }
         else
         {
             return($"`{attributeComparison.NetworkAttribute.Name}` {attributeComparison.ComparisonOperator} `{attributeComparison.OtherNetworkAttribute?.Name ?? attributeComparison.Value}`");
         }
     }
     else if (expression is UtilityTraceAndCondition andCondition)
     {
         return($"({ExpressionToString(andCondition.LeftExpression)}) AND\n ({ExpressionToString(andCondition.RightExpression)})");
     }
     else if (expression is UtilityTraceOrCondition orCondition)
     {
         return($"({ExpressionToString(orCondition.LeftExpression)}) OR\n ({ExpressionToString(orCondition.RightExpression)})");
     }
     else
     {
         return(null);
     }
 }
        private object ConvertToDataType(object otherValue, UtilityNetworkAttributeDataType dataType)
        {
            switch (dataType)
            {
            case UtilityNetworkAttributeDataType.Boolean:
                return(Convert.ToBoolean(otherValue));

            case UtilityNetworkAttributeDataType.Double:
                return(Convert.ToDouble(otherValue));

            case UtilityNetworkAttributeDataType.Float:
                return(Convert.ToSingle(otherValue));

            case UtilityNetworkAttributeDataType.Integer:
                return(Convert.ToInt32(otherValue));
            }
            throw new NotSupportedException();
        }