Ejemplo n.º 1
0
 private void RegisterPropertyAttributes(string propName)
 {
     // Properties that are added after view model instantiation must be manually set so that
     // their values will be included in the updates to the client.
     foreach (var metaProp in RuntimeProperties.Where(x => x.Name.StartsWith(propName + "__")))
         Set(metaProp.Value, metaProp.Name);
 }
Ejemplo n.º 2
0
        private void RemoveExistingProperty(string propName)
        {
            RuntimeProperties.Where(x => x.Name == propName || x.Name.Contains(propName + "__"))
               .ToList()
               .ForEach(x => RuntimeProperties.Remove(x));

            _propertyValues.TryRemove(propName, out object value);
        }
Ejemplo n.º 3
0
    public void PinnableBlittableTest()
    {
        Assert.True(RuntimeProperties.IsPinnable("g"));
        Assert.False(RuntimeProperties.IsBlittable("g"));


        Assert.True(RuntimeProperties.IsPinnable(new int[] { 1, 2, 3 }));
        Assert.False(RuntimeProperties.IsBlittable(new int[] { 1, 2, 3 }));
    }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a runtime observable property.
        /// </summary>
        /// <param name="propertyName">Property name.</param>
        private ReactiveProperty <T> AddProperty <T>(Type propertyType, ReactiveProperty <T> property)
        {
            if (_propertyValues.ContainsKey(property.Name))
            {
                throw new InvalidOperationException($"{property.Name} already exists.");
            }

            property.Subscribe(_ => Changed(property.Name));
            RuntimeProperties.Add(property);
            Set(property, property.Name);
            return(property);
        }
Ejemplo n.º 5
0
    public void NilTest()
    {
        string s = "foo";

        Assert.False(RuntimeProperties.IsDefault(s));

        string s2 = null;

        Assert.True(RuntimeProperties.IsDefault(s2));

        Assert.True(RuntimeProperties.IsDefault(default(int)));
    }
Ejemplo n.º 6
0
    public void PinnableTest()
    {
        string s = "foo";

        Assert.True(RuntimeProperties.IsPinnable(s));

        string[] rg = { "foo", "bar" };
        Assert.False(RuntimeProperties.IsPinnable(rg));

        var rg2 = new[] { 1, 2, 3 };

        Assert.True(RuntimeProperties.IsPinnable(rg2));

        Assert.True(RuntimeProperties.IsPinnable(1));

        Assert.False(RuntimeProperties.IsPinnable(new List <int> {
            1, 2, 3
        }));
    }
Ejemplo n.º 7
0
        /// <summary>
        /// Constructor to create a wrapper for a view model that doesn't inherit from BaseVM.
        /// </summary>
        /// <param name="vm">View model instance.</param>
        internal BaseVM(INotifyPropertyChanged vm) : base()
        {
            _vmInstance         = vm;
            vm.PropertyChanged += OnPropertyChanged;
            _changedProperties  = _propertyDictionaries.Dequeue();

            if (vm is IReactiveProperties && (vm as IReactiveProperties).RuntimeProperties != null)
            {
                var runtimeProperties = (vm as IReactiveProperties).RuntimeProperties.Where(prop => !string.IsNullOrWhiteSpace(prop.Name)).ToList();
                runtimeProperties.ForEach(prop =>
                {
                    prop.PropertyChanged += OnPropertyChanged;
                    RuntimeProperties.Add(prop);
                    Set(prop, prop.Name);
                });
                Disposed += (sender, e) => runtimeProperties.ForEach(prop => prop.PropertyChanged -= OnPropertyChanged);
                IgnoredProperties.Add(nameof(IReactiveProperties.RuntimeProperties));
            }

            if (vm is IPushUpdates)
            {
                (vm as IPushUpdates).RequestPushUpdates += (sender, e) => RequestPushUpdates?.Invoke(this, e);
            }

            if (vm is IDisposable)
            {
                Disposed += (sender, e) =>
                {
                    vm.PropertyChanged -= OnPropertyChanged;
                    (vm as IDisposable).Dispose();
                }
            }
            ;

            if (vm is IBaseVMAccessor)
            {
                (vm as IBaseVMAccessor).OnInitialized?.Invoke(this);
            }
        }
Ejemplo n.º 8
0
 protected BaseClrStructure(MemberInfo member) : this(RuntimeProperties.ResolveHandle(member))
 {
 }
Ejemplo n.º 9
0
 public void SizeTest2(object value)
 {
     Assert.AreEqual(RuntimeProperties.GetRawObjDataSize(value), Mem.SizeOf(value, SizeOfOptions.Data));
 }
Ejemplo n.º 10
0
 public void BlankTest()
 {
     Assert.True(RuntimeProperties.IsEmpty(Array.Empty <int>()));
 }
Ejemplo n.º 11
0
 public void BoxedTest()
 {
     Assert.True(RuntimeProperties.IsBoxed((object)1));
 }
Ejemplo n.º 12
0
    public static string Dump <T>(ref T value, DumpOptions options, InspectorOptions options2)
    {
        switch (options)
        {
        case DumpOptions.Info:
            //

            var addrTable = new ConsoleTable("Addresses", "");

            var addr = Mem.AddressOf(ref value);
            addrTable.AddRow("Address", addr);

            if (Mem.TryGetAddressOfHeap(value, out var heap))
            {
                addrTable.AddRow("Address (heap)", heap);
            }

            addrTable.Write(ConsoleTableFormat.Minimal);

            //

            var infoTable = new ConsoleTable("Sizes", "");

            infoTable.AddRow("Intrinsic", Mem.SizeOf <T>());
            infoTable.AddRow("Auto", Mem.SizeOf(value, SizeOfOptions.Auto));

            infoTable.Write(ConsoleTableFormat.Minimal);

            //

            var propTable = new ConsoleTable("Runtime info", "");

            propTable.AddRow("Pinnable", RuntimeProperties.IsPinnable(value));
            propTable.AddRow("Blittable", RuntimeProperties.IsBlittable(value));
            propTable.AddRow("Boxed", RuntimeProperties.IsBoxed(value));
            propTable.AddRow("Nil", RuntimeProperties.IsDefault(value));
            propTable.AddRow("Uninitialized", RuntimeProperties.IsNullMemory(value));


            propTable.AddRow("In GC heap", GCHeap.IsHeapPointer(Mem.AddressOfData(ref value)));

            return(propTable.ToMinimalString());

        case DumpOptions.Sizes:
            var layoutTable = new ConsoleTable("Size Type", "Value");

            var options1 = Enum.GetValues <SizeOfOptions>().ToList();

            options1.Remove(SizeOfOptions.Heap);


            foreach (var option in options1)
            {
                var sizeOf = Mem.SizeOf(value, option);

                if (sizeOf == Native.INVALID)
                {
                    continue;
                }

                layoutTable.AddRow(Enum.GetName(option), sizeOf);
            }

            var mt = value.GetMetaType();

            if (!mt.RuntimeType.IsValueType)
            {
                layoutTable.AddRow(nameof(SizeOfOptions.Heap), Mem.SizeOf(value, SizeOfOptions.Heap));
            }

            return(layoutTable.ToString());

        case DumpOptions.Layout:
            var layoutTable1 = new ConsoleTable();

            var flags = EnumHelper.GetSetFlags(options2);

            if (options2 == InspectorOptions.All)
            {
                flags.Remove(InspectorOptions.All);
            }

            layoutTable1.AddColumn(flags.Select(Enum.GetName));


            // Rewrite options

            options2 = default;

            foreach (var flag in flags)
            {
                options2 |= flag;
            }

            var mt1    = value.GetMetaType();
            var fields = mt1.Fields.Where(x => !x.IsStatic);

            int s = Mem.SizeOf(value, SizeOfOptions.Auto);
            var p = Mem.AddressOf(ref value);


            foreach (var metaField in fields)
            {
                var rowValues = new List <object>();


                if (options2.HasFlag(InspectorOptions.Offset))
                {
                    rowValues.Add($"{metaField.Offset:X}");
                }

                if (options2.HasFlag(InspectorOptions.Size))
                {
                    rowValues.Add(metaField.Size);
                }

                if (options2.HasFlag(InspectorOptions.Type))
                {
                    rowValues.Add(metaField.FieldType.Name);
                }

                if (options2.HasFlag(InspectorOptions.Name))
                {
                    rowValues.Add(metaField.Name);
                }

                if (options2.HasFlag(InspectorOptions.Address))
                {
                    var addr1 = Mem.AddressOfData(ref value) + metaField.Offset;
                    rowValues.Add(addr1.ToString());
                }

                if (options2.HasFlag(InspectorOptions.Value))
                {
                    object fieldVal;

                    if (!mt1.RuntimeType.IsConstructedGenericType)
                    {
                        fieldVal = metaField.Info.GetValue(value);
                    }
                    else
                    {
                        fieldVal = "?";
                    }

                    rowValues.Add($"{fieldVal}");
                }

                layoutTable1.AddRow(rowValues.ToArray());
            }


            if (value is string str)
            {
                for (int i = 1; i < str.Length; i++)
                {
                    char c          = str[i];
                    var  rowValues  = new List <object>();
                    int  offsetBase = (i * sizeof(char));

                    if (options2.HasFlag(InspectorOptions.Offset))
                    {
                        rowValues.Add($"{offsetBase + RuntimeProperties.StringOverhead - sizeof(char):X}");
                    }

                    if (options2.HasFlag(InspectorOptions.Size))
                    {
                        rowValues.Add(sizeof(char));
                    }

                    if (options2.HasFlag(InspectorOptions.Type))
                    {
                        rowValues.Add(nameof(Char));
                    }

                    if (options2.HasFlag(InspectorOptions.Name))
                    {
                        rowValues.Add($"Char #{i + 1}");
                    }

                    if (options2.HasFlag(InspectorOptions.Address))
                    {
                        if (Mem.TryGetAddressOfHeap(value, OffsetOptions.StringData, out var addr2))
                        {
                            addr2 += offsetBase;
                            rowValues.Add(addr2.ToString());
                        }
                    }

                    if (options2.HasFlag(InspectorOptions.Value))
                    {
                        rowValues.Add($"{c}");
                    }

                    layoutTable1.AddRow(rowValues.ToArray());
                }
            }


            return(layoutTable1.ToString());

        default:
            throw new ArgumentOutOfRangeException(nameof(options));
        }
    }