Example #1
0
 internal static bool TryGetTupleFieldValues(this DkmClrValue tuple, int cardinality, ArrayBuilder <string> values, DkmInspectionContext inspectionContext)
 {
     while (true)
     {
         var type = tuple.Type.GetLmrType();
         int n    = Math.Min(cardinality, TupleFieldRestPosition - 1);
         for (int index = 0; index < n; index++)
         {
             var fieldName = GetTupleFieldName(index);
             var fieldInfo = type.GetTupleField(fieldName);
             if (fieldInfo == null)
             {
                 return(false);
             }
             var value = tuple.GetFieldValue(fieldName, inspectionContext);
             var str   = value.GetValueString(inspectionContext, Formatter.NoFormatSpecifiers);
             values.Add(str);
         }
         cardinality -= n;
         if (cardinality == 0)
         {
             return(true);
         }
         var restInfo = type.GetTupleField(TypeHelpers.TupleFieldRestName);
         if (restInfo == null)
         {
             return(false);
         }
         tuple = tuple.GetFieldValue(TupleFieldRestName, inspectionContext);
     }
 }
Example #2
0
        internal static DkmClrValue GetNullableValue(this DkmClrValue value, DkmInspectionContext inspectionContext)
        {
            Debug.Assert(value.Type.GetLmrType().IsNullable());

            var hasValue = value.GetFieldValue(InternalWellKnownMemberNames.NullableHasValue, inspectionContext);

            if (object.Equals(hasValue.HostObjectValue, false))
            {
                return(null);
            }

            return(value.GetFieldValue(InternalWellKnownMemberNames.NullableValue, inspectionContext));
        }
Example #3
0
        private static DkmClrValue GetValueAndFullName(
            IDkmClrFullNameProvider fullNameProvider,
            DkmInspectionContext inspectionContext,
            DkmClrValue value,
            Field field,
            string parentFullName,
            out string fullName)
        {
            var parent = field.Parent;

            if (parent != null)
            {
                value = GetValueAndFullName(
                    fullNameProvider,
                    inspectionContext,
                    value,
                    parent,
                    parentFullName,
                    out parentFullName);
            }
            var fieldName = field.FieldInfo.Name;

            fullName = (parentFullName == null) ?
                       null :
                       fullNameProvider.GetClrMemberName(
                inspectionContext,
                parentFullName,
                clrType: field.DeclaringTypeAndInfo.ClrType,
                customTypeInfo: null,
                memberName: fieldName,
                requiresExplicitCast: false,
                isStatic: false);
            return(value.GetFieldValue(fieldName, inspectionContext));
        }
Example #4
0
        private string GetUnderlyingStringImpl(
            DkmClrValue value,
            DkmInspectionContext inspectionContext
            )
        {
            Debug.Assert(!value.IsError());

            if (value.IsNull)
            {
                return(null);
            }

            var lmrType = value.Type.GetLmrType();

            if (lmrType.IsEnum || lmrType.IsArray || lmrType.IsPointer)
            {
                return(null);
            }

            if (lmrType.IsNullable())
            {
                var nullableValue = value.GetNullableValue(inspectionContext);
                return(nullableValue != null
                  ? GetUnderlyingStringImpl(nullableValue, inspectionContext)
                  : null);
            }

            if (lmrType.IsString())
            {
                return((string)value.HostObjectValue);
            }
            else if (!IsPredefinedType(lmrType))
            {
                // Check for special cased non-primitives that have underlying strings
                if (lmrType.IsType("System.Data.SqlTypes", "SqlString"))
                {
                    var fieldValue = value.GetFieldValue(
                        InternalWellKnownMemberNames.SqlStringValue,
                        inspectionContext
                        );
                    return(fieldValue.HostObjectValue as string);
                }
                else if (lmrType.IsOrInheritsFrom("System.Xml.Linq", "XNode"))
                {
                    return(value.EvaluateToString(inspectionContext));
                }
            }

            return(null);
        }
Example #5
0
        private string GetUnderlyingStringImpl(DkmClrValue value)
        {
            if (value.IsNull)
            {
                return(null);
            }

            var lmrType = value.Type.GetLmrType();

            if (lmrType.IsEnum || lmrType.IsArray || lmrType.IsPointer)
            {
                return(null);
            }

            if (lmrType.IsNullable())
            {
                var nullableValue = value.GetNullableValue();
                return(nullableValue != null?GetUnderlyingStringImpl(nullableValue) : null);
            }

            if (lmrType.IsString())
            {
                return((string)value.HostObjectValue);
            }
            else if (!IsPredefinedType(lmrType))
            {
                // Check for special cased non-primitives that have underlying strings
                if (string.Equals(lmrType.FullName, "System.Data.SqlTypes.SqlString", StringComparison.Ordinal))
                {
                    var fieldValue = value.GetFieldValue(InternalWellKnownMemberNames.SqlStringValue);
                    return(fieldValue.HostObjectValue as string);
                }

                do
                {
                    if (string.Equals(lmrType.FullName, "System.Xml.Linq.XNode", StringComparison.Ordinal))
                    {
                        return(value.EvaluateToString());
                    }

                    lmrType = lmrType.BaseType;
                }while (lmrType != null);
            }

            return(null);
        }
Example #6
0
        internal string FormatPrimitive(DkmClrValue value, ObjectDisplayOptions options)
        {
            Debug.Assert(value != null);

            object obj;

            if (value.Type.GetLmrType().IsDateTime())
            {
                DkmClrValue dateDataValue = value.GetFieldValue(DateTimeUtilities.DateTimeDateDataFieldName);
                Debug.Assert(dateDataValue.HostObjectValue != null);

                obj = DateTimeUtilities.ToDateTime((ulong)dateDataValue.HostObjectValue);
            }
            else
            {
                Debug.Assert(value.HostObjectValue != null);
                obj = value.HostObjectValue;
            }

            return(FormatPrimitiveObject(obj, options));
        }
Example #7
0
        internal static Expansion CreateExpansion(
            DkmInspectionContext inspectionContext,
            TypeAndCustomInfo declaredTypeAndInfo,
            DkmClrValue value,
            ExpansionFlags flags,
            Predicate <MemberInfo> predicate,
            ResultProvider resultProvider,
            bool isProxyType)
        {
            // For members of type DynamicProperty (part of Dynamic View expansion), we want
            // to expand the underlying value (not the members of the DynamicProperty type).
            var type              = value.Type;
            var runtimeType       = type.GetLmrType();
            var isDynamicProperty = runtimeType.IsDynamicProperty();

            if (isDynamicProperty)
            {
                Debug.Assert(!value.IsNull);
                value = value.GetFieldValue("value", inspectionContext);
            }

            // Primitives, enums, function pointers, IntPtr, UIntPtr and null values with a declared type that is an interface have no visible members.
            Debug.Assert(!runtimeType.IsInterface || value.IsNull);
            if (resultProvider.IsPrimitiveType(runtimeType) || runtimeType.IsEnum || runtimeType.IsInterface || runtimeType.IsFunctionPointer() ||
                runtimeType.IsIntPtr() || runtimeType.IsUIntPtr())
            {
                return(null);
            }

            // As in the old C# EE, DynamicProperty members are only expandable if they have a Dynamic View expansion.
            var dynamicViewExpansion = DynamicViewExpansion.CreateExpansion(inspectionContext, value, resultProvider);

            if (isDynamicProperty && (dynamicViewExpansion == null))
            {
                return(null);
            }

            var customTypeInfoMap = CustomTypeInfoTypeArgumentMap.Create(declaredTypeAndInfo);

            var expansions = ArrayBuilder <Expansion> .GetInstance();

            // Expand members. TODO: Ideally, this would be done lazily (https://github.com/dotnet/roslyn/issues/32800)
            // From the members, collect the fields and properties,
            // separated into static and instance members.
            var staticMembers = ArrayBuilder <MemberAndDeclarationInfo> .GetInstance();

            var instanceMembers = ArrayBuilder <MemberAndDeclarationInfo> .GetInstance();

            var appDomain = value.Type.AppDomain;

            var allMembers = ArrayBuilder <MemberAndDeclarationInfo> .GetInstance();

            var includeInherited         = (flags & ExpansionFlags.IncludeBaseMembers) == ExpansionFlags.IncludeBaseMembers;
            var hideNonPublic            = (inspectionContext.EvaluationFlags & DkmEvaluationFlags.HideNonPublicMembers) == DkmEvaluationFlags.HideNonPublicMembers;
            var includeCompilerGenerated = (inspectionContext.EvaluationFlags & DkmEvaluationFlags.ShowValueRaw) == DkmEvaluationFlags.ShowValueRaw;

            runtimeType.AppendTypeMembers(allMembers, predicate, declaredTypeAndInfo.Type, appDomain, includeInherited, hideNonPublic, isProxyType, includeCompilerGenerated);

            foreach (var member in allMembers)
            {
                if (member.IsStatic)
                {
                    staticMembers.Add(member);
                }
                else if (!value.IsNull)
                {
                    instanceMembers.Add(member);
                }
            }

            allMembers.Free();

            // Public and non-public instance members.
            Expansion publicInstanceExpansion;
            Expansion nonPublicInstanceExpansion;

            GetPublicAndNonPublicMembers(
                instanceMembers,
                customTypeInfoMap,
                isProxyType,
                out publicInstanceExpansion,
                out nonPublicInstanceExpansion);

            // Public and non-public static members.
            Expansion publicStaticExpansion;
            Expansion nonPublicStaticExpansion;

            GetPublicAndNonPublicMembers(
                staticMembers,
                customTypeInfoMap,
                isProxyType,
                out publicStaticExpansion,
                out nonPublicStaticExpansion);

            if (publicInstanceExpansion != null)
            {
                expansions.Add(publicInstanceExpansion);
            }

            if ((publicStaticExpansion != null) || (nonPublicStaticExpansion != null))
            {
                var staticExpansions = ArrayBuilder <Expansion> .GetInstance();

                if (publicStaticExpansion != null)
                {
                    staticExpansions.Add(publicStaticExpansion);
                }
                if (nonPublicStaticExpansion != null)
                {
                    staticExpansions.Add(nonPublicStaticExpansion);
                }
                Debug.Assert(staticExpansions.Count > 0);
                var staticMembersExpansion = new StaticMembersExpansion(
                    type,
                    AggregateExpansion.CreateExpansion(staticExpansions));
                staticExpansions.Free();
                expansions.Add(staticMembersExpansion);
            }

            instanceMembers.Free();
            staticMembers.Free();

            if (value.NativeComPointer != 0)
            {
                expansions.Add(NativeViewExpansion.Instance);
            }

            if (nonPublicInstanceExpansion != null)
            {
                expansions.Add(nonPublicInstanceExpansion);
            }

            // Include Results View if necessary.
            if ((flags & ExpansionFlags.IncludeResultsView) != 0)
            {
                var resultsViewExpansion = ResultsViewExpansion.CreateExpansion(inspectionContext, value, resultProvider);
                if (resultsViewExpansion != null)
                {
                    expansions.Add(resultsViewExpansion);
                }
            }

            if (dynamicViewExpansion != null)
            {
                expansions.Add(dynamicViewExpansion);
            }

            var result = AggregateExpansion.CreateExpansion(expansions);

            expansions.Free();
            return(result);
        }