Ejemplo n.º 1
0
        public override IValuePresentation PresentValue(IValueRole <TValue> valueRole,
                                                        IMetadataTypeLite instanceType,
                                                        IPresentationOptions options,
                                                        IUserDataHolder dataHolder,
                                                        CancellationToken token)
        {
            var extraDetail  = (ExtraDetailValueReferenceDecorator <TValue>)valueRole.ValueReference;
            var presentation = extraDetail.UnderlyingValueReference.ToValue(ValueServices).GetValuePresentation(options, token);

            if (presentation.ResultKind == ValueResultKind.Success)
            {
                var presentationBuilder = PresentationBuilder.New(presentation.Value.ToArray())
                                          .Add(ValuePresentationPart.Space)
                                          .SpecialSymbol("(").Default(extraDetail.ExtraDetail).SpecialSymbol(")");
                return(SimplePresentation.CreateSuccess(presentationBuilder.Result(), presentation.Flags,
                                                        presentation.Type, presentation.PrimitiveValue));
            }

            return(presentation);
        }
Ejemplo n.º 2
0
        public override IValuePresentation PresentValue(IObjectValueRole <TValue> valueRole,
                                                        IMetadataTypeLite instanceType,
                                                        IPresentationOptions options, IUserDataHolder dataHolder,
                                                        CancellationToken token)
        {
            var showName     = (valueRole.ValueReference as CalculatedValueReferenceDecorator <TValue>)?.AllowNameInValue ?? true;
            var showTypeName = (valueRole.ValueReference as CalculatedValueReferenceDecorator <TValue>)
                               ?.AllowDefaultTypePresentation ?? true;

            var nameValuePresentation = valueRole.GetInstancePropertyReference("name")?.ToValue(ValueServices)
                                        ?.GetValuePresentation(options);
            var propertyTypeReference         = valueRole.GetInstancePropertyReference("propertyType");
            var propertyTypeValuePresentation = propertyTypeReference?.ToValue(ValueServices)?.GetValuePresentation(options);

            var propertyTypeEnumValueObject = propertyTypeReference?.AsObjectSafe(options)?.GetEnumValue(options);
            var propertyType = (SerializedPropertyKind)Enum.ToObject(typeof(SerializedPropertyKind),
                                                                     propertyTypeEnumValueObject ?? SerializedPropertyKind.Generic);

            int?   arraySize        = null;
            string arrayElementType = null;
            string genericType      = null;

            if (propertyType == SerializedPropertyKind.Generic)
            {
                if (Util.TryEvaluatePrimitiveProperty(valueRole, "isArray", options, out bool isArray) && isArray)
                {
                    arraySize = valueRole.GetInstancePropertyReference("arraySize")?.AsPrimitiveSafe(options)
                                ?.GetPrimitive <int>();
                    arrayElementType =
                        valueRole.GetInstancePropertyReference("arrayElementType")?.AsStringSafe(options)?.GetString();
                }
                else if (Util.TryEvaluatePrimitiveProperty(valueRole, "isFixedBuffer", options,
                                                           out bool isFixedBuffer) &&
                         isFixedBuffer)
                {
                    arraySize = valueRole.GetInstancePropertyReference("fixedBufferSize")?.AsPrimitiveSafe(options)
                                ?.GetPrimitive <int>();
                    arrayElementType =
                        valueRole.GetInstancePropertyReference("arrayElementType")?.AsStringSafe(options)?.GetString();
                }
                else
                {
                    genericType = valueRole.GetInstancePropertyReference("type")?.AsStringSafe(options)?.GetString();
                }
            }

            var valuePresentation = GetValuePresentation(valueRole, propertyType, options, out var extraDetail);

            var parts = PresentationBuilder.New();

            parts.OpenBrace();

            if (showName && nameValuePresentation != null)
            {
                parts.Comment("name: ").Add(nameValuePresentation.Value.ToArray())
                .Add(ValuePresentationPart.Space);
            }

            parts.Comment("propertyType: ");
            if (propertyType == SerializedPropertyKind.Generic && arraySize != null && arrayElementType != null)
            {
                parts.Default($"{arrayElementType}[{arraySize}]");
            }
            else if (genericType != null)
            {
                parts.Default(genericType);
            }
            else if (propertyTypeValuePresentation != null)
            {
                parts.Add(propertyTypeValuePresentation.Value.ToArray());
            }
            else
            {
                parts.Comment("(Unknown)");
            }

            if (valuePresentation != null)
            {
                parts.Add(ValuePresentationPart.Space)
                .Comment("value: ").Add(valuePresentation.Value.ToArray());
                if (!string.IsNullOrEmpty(extraDetail))
                {
                    parts.Add(ValuePresentationPart.Space).SpecialSymbol("(").Default(extraDetail).SpecialSymbol(")");
                }
            }

            parts.ClosedBrace();

            // Hide the default type presentation if we've been asked to
            var flags = !showTypeName ? ValueFlags.IsDefaultTypePresentation : 0;

            return(SimplePresentation.Create(parts.Result(), ValueResultKind.Success, ValueFlags.None | flags,
                                             instanceType));
        }
Ejemplo n.º 3
0
 public IValuePresentation GetValuePresentation(IPresentationOptions options,
                                                CancellationToken token = new CancellationToken())
 {
     return(SimplePresentation.Create(PresentationBuilder.New().Error(myMessage), myResultKind,
                                      ValueFlags.NoChildren, DeclaredType));
 }