Example #1
0
        public override QsValue GetIndexedItem(QsParameter[] indices)
        {
            var pi = InstanceType.GetProperty("Item"
                                              , System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public
                                              );



            var r = Root.QsParametersToNativeValues(pi.GetGetMethod(), indices);

            return(Root.NativeToQsConvert(pi.GetValue(_NativeObject, r)));
        }
Example #2
0
        public override void SetIndexedItem(QsParameter[] indices, QsValue value)
        {
            var pi = InstanceType.GetProperty("Item"
                                              , System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public
                                              );
            var gs = pi.GetSetMethod();

            var r = Root.QsParametersToNativeValues(gs, indices);

            var nativeValue = Root.QsToNativeConvert(pi.PropertyType, value);

            pi.SetValue(_NativeObject, nativeValue, r);
        }
Example #3
0
        public void DumpProperty()
        {
            // should we dump it at all?
            if (!CurrentProperty.CanRead() || CurrentPropertyDumpAttribute.Skip == ShouldDump.Skip)
            {
                return;
            }

            var pi = CurrentProperty as PropertyInfo;

            // can't dump indexers
            if (pi != null && pi.GetIndexParameters().Length > 0)
            {
                return;
            }

            if (pi != null && pi.IsVirtual())
            {
                // for virtual properties dump the instance value at the the least derived class level that declares the property for first time.
                if (CurrentType.BaseType.GetProperty(CurrentProperty.Name, _dumper.PropertiesBindingFlags) != null)
                {
                    return;
                }

                pi = InstanceType.GetProperty(CurrentProperty.Name, _dumper.PropertiesBindingFlags);
            }

            var    fi    = CurrentProperty as FieldInfo;
            Type   type  = null;
            object value = null;

            try
            {
                if (pi != null)
                {
                    type  = pi.PropertyType;
                    value = pi.GetValue(Instance, null);
                }
                else
                {
                    type  = fi.FieldType;
                    value = fi.GetValue(Instance);
                }
            }
            catch (Exception x)
            {
                // this should not happen but...
                value = $"<{x.Message}>";
            }

            var dontDumpNulls = CurrentPropertyDumpAttribute.DumpNullValues == ShouldDump.Skip ||
                                CurrentPropertyDumpAttribute.DumpNullValues == ShouldDump.Default && DumpNullValues == ShouldDump.Skip;

            if (IsInDumpingMode)
            {
                // should we dump a null value of the current property
                if (value == null && dontDumpNulls)
                {
                    return;
                }

                // write the property header
                _dumper.Writer.WriteLine();
                _dumper.Writer.Write(
                    CurrentPropertyDumpAttribute.LabelFormat,
                    CurrentProperty.Name);

                if (!(DumpedPropertyCustom(value, type) ||                                           // dump the property value using caller's customization (see ValueFormat="ToString", DumpClass, DumpMethod) if any.
                      _dumper.Writer.DumpedBasicValue(value, CurrentPropertyDumpAttribute) ||
                      _dumper.Writer.DumpedBasicNullable(value, CurrentPropertyDumpAttribute) ||
                      _dumper.Writer.Dumped(value as Delegate) ||
                      _dumper.Writer.Dumped(value as MemberInfo) ||
                      DumpedCollection(value, CurrentProperty, CurrentPropertyDumpAttribute)))
                {
                    // dump a property representing an associated class or struct object
                    var currentPropertyDumpAttribute = !CurrentPropertyDumpAttribute.IsDefaultAttribute() ? CurrentPropertyDumpAttribute : null;

                    _dumper.DumpObject(value, null, currentPropertyDumpAttribute, this);
                }
            }
            else
            {
                // write the property header
                DumpScript.BeginDumpProperty(CurrentProperty, CurrentPropertyDumpAttribute);

                if (!DumpedPropertyCustom(value, type))                                             // dump the property value using caller's customization (see ValueFormat="ToString", DumpClass, DumpMethod) if any.
                {
                    DumpScript.AddDumpPropertyOrCollectionValue(CurrentProperty, CurrentPropertyDumpAttribute);
                }

                DumpScript.EndDumpProperty(CurrentProperty, dontDumpNulls);
            }
        }