示例#1
0
            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.)");
                }
            }
示例#2
0
        public PProfInfo.Label CreateNewLabelInfo(PProfSampleLabel labelItems)
        {
            var labelItem = new PProfProto.Label();

            labelItem.Key = ProtoConstants.StringTableIndex.Unresolved;

            switch (labelItems.ValueKind)
            {
            case PProfSampleLabel.Kind.Number:
                labelItem.Num     = labelItems.NumberValue;
                labelItem.NumUnit = ProtoConstants.StringTableIndex.Unresolved;
                labelItem.Str     = ProtoConstants.StringTableIndex.Unset;
                break;

            case PProfSampleLabel.Kind.String:
                labelItem.Num     = ProtoConstants.NumericValue.UnsetInt64;
                labelItem.NumUnit = ProtoConstants.StringTableIndex.Unset;
                labelItem.Str     = ProtoConstants.StringTableIndex.Unresolved;
                break;

            case PProfSampleLabel.Kind.Unknown:
            default:
                throw new InvalidOperationException($"Cannot create a {nameof(PProfProto)}.{nameof(PProfProto.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.)");
            }

            var labelInfo = new PProfInfo.Label(
                labelItems,
                this,
                labelItem);

            return(labelInfo);
        }