/// <summary> /// Overloaded ToString function for formatting the output on the console. /// </summary> /// <param name="healthStatistics"> Object of type HealthStatistics </param> /// <returns> /// Returns formatted string. /// </returns> public static string ToString(HealthStatistics healthStatistics) { var strBuilder = new StringBuilder(); strBuilder.Append(string.Format(CultureInfo.CurrentCulture, "{0, -21} : {1}", "HealthStateCountList", OutputFormatter.ToString(healthStatistics.HealthStateCountList.ToList()))); strBuilder.Append(Environment.NewLine); return(strBuilder.ToString()); }
/// <summary> /// Serializes the object to JSON. /// </summary> /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param> /// <param name="obj">The object to serialize to JSON.</param> internal static void Serialize(JsonWriter writer, HealthStatistics obj) { // Required properties are always serialized, optional properties are serialized when not null. writer.WriteStartObject(); if (obj.HealthStateCountList != null) { writer.WriteEnumerableProperty(obj.HealthStateCountList, "HealthStateCountList", EntityKindHealthStateCountConverter.Serialize); } writer.WriteEndObject(); }
internal static void AddToPSObject(PSObject itemPSObj, HealthStatistics healthStats) { if (healthStats == null || healthStats.HealthStateCountList.Count == 0) { return; } var healthStatisticsPropertyPSObj = new PSObject(healthStats); healthStatisticsPropertyPSObj.Members.Add( new PSCodeMethod( Constants.ToStringMethodName, typeof(OutputFormatter).GetMethod(Constants.FormatObjectMethodName))); itemPSObj.Properties.Add( new PSNoteProperty( Constants.HealthStatisticsPropertyName, healthStatisticsPropertyPSObj)); }