public PProfSampleLabel(string key, long num, string numUnit) { _valueKind = PProfSampleLabel.Kind.Number; _key = key; _numValue = num; _strValueOrNumUnit = numUnit; }
public PProfSampleLabel(string key, string str) { _valueKind = PProfSampleLabel.Kind.String; _key = key; _numValue = 0; _strValueOrNumUnit = str; }
public Label(PProfSampleLabel labelItems, PProfItemCache builderCache, PProfProto.Label item) { Validate.NotNull(builderCache, nameof(builderCache)); Validate.NotNull(item, nameof(item)); this.Item = item; _valueKind = labelItems.ValueKind; _keyInfo = builderCache.GetOrCreateStringInfo(labelItems.Key ?? string.Empty); switch (labelItems.ValueKind) { case PProfSampleLabel.Kind.Number: _numValue = labelItems.NumberValue; _strValueOrNumUnitInfo = builderCache.GetOrCreateStringInfo(labelItems.NumberUnit ?? string.Empty); break; case PProfSampleLabel.Kind.String: _numValue = ProtoConstants.NumericValue.UnsetInt64; _strValueOrNumUnitInfo = builderCache.GetOrCreateStringInfo(labelItems.StringValue ?? string.Empty); break; case PProfSampleLabel.Kind.Unknown: default: throw new InvalidOperationException($"Cannot create a {nameof(PProfInfo)}.{nameof(Label)}," + $" because the {nameof(PProfSampleLabel.ValueKind)} of the" + $" specified {nameof(PProfSampleLabel)} is {labelItems.ValueKind}." + $" Either {PProfSampleLabel.Kind.Number} or {PProfSampleLabel.Kind.String} was expected." + $" (Did you use the default ctor for {nameof(PProfSampleLabel)}?" + " If so, use a different ctor overload.)"); } }
internal static void ValidateValueKind(PProfSampleLabel.Kind actualValueKind, PProfSampleLabel.Kind expectedValueKind) { if (actualValueKind == expectedValueKind) { return; } switch (actualValueKind) { case PProfSampleLabel.Kind.Number: case PProfSampleLabel.Kind.String: throw new InvalidOperationException($"Cannot perform this operation because the expected {nameof(ValueKind)} of this" + $" instance was {expectedValueKind}, but the actual {nameof(ValueKind)} is {actualValueKind}."); case PProfSampleLabel.Kind.Unknown: default: throw new InvalidOperationException($"Cannot perform this operation because the expected {nameof(ValueKind)} of this" + $" instance was {expectedValueKind}, but the actual {nameof(ValueKind)} is {actualValueKind}." + $" (Did you use the default ctor for {nameof(PProfSampleLabel)}?" + " If so, use a different ctor overload.)"); } }