Example #1
0
        internal static Script Add(
            ObjectTextDumper objectTextDumper,
            Type objectType,
            ClassDumpData classDumpData,
            DumpScript _dumpScript)
        {
            if (objectTextDumper == null)
            {
                throw new ArgumentNullException(nameof(objectTextDumper));
            }
            if (objectType == null)
            {
                throw new ArgumentNullException(nameof(objectType));
            }
            if (_dumpScript == null)
            {
                throw new ArgumentNullException(nameof(_dumpScript));
            }

            var lookup = new ScriptLookup(objectType, classDumpData, objectTextDumper);
            var script = _dumpScript.GetScriptAction();

            _sync.EnterWriteLock();

            _cache[lookup] = script;
            _buildingNow.Remove(lookup);

            _sync.ExitWriteLock();

            return(script);
        }
Example #2
0
        internal static bool TryFind(
            ObjectTextDumper objectTextDumper,
            object obj,
            ClassDumpData classDumpData,
            out Script script)
        {
            if (objectTextDumper == null)
            {
                throw new ArgumentNullException(nameof(objectTextDumper));
            }
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            script = null;

            var lookup = new ScriptLookup(obj.GetType(), classDumpData, objectTextDumper);

            _sync.EnterReadLock();

            var found = _cache.TryGetValue(lookup, out script);

            if (!found)
            {
                found = _buildingNow.Contains(lookup);
            }

            _sync.ExitReadLock();
            return(found);
        }
Example #3
0
            public override int GetHashCode()
            {
                var hashCode = Constants.HashInitializer;

                unchecked
                {
                    hashCode = Constants.HashMultiplier * hashCode + ObjectType.GetHashCode();
                    hashCode = Constants.HashMultiplier * hashCode + ClassDumpData.GetHashCode();
                    hashCode = Constants.HashMultiplier * hashCode + PropertiesBindingFlags.GetHashCode();
                    hashCode = Constants.HashMultiplier * hashCode + FieldsBindingFlags.GetHashCode();
                }

                return(hashCode);
            }
Example #4
0
            public ScriptLookup(
                Type objectType,
                ClassDumpData classDumpData,
                ObjectTextDumper objectTextDumper)
            {
                if (objectTextDumper is null)
                {
                    throw new ArgumentNullException(nameof(objectTextDumper));
                }

                ObjectType             = objectType ?? throw new ArgumentNullException(nameof(objectType));
                ClassDumpData          = classDumpData;
                PropertiesBindingFlags = objectTextDumper.PropertiesBindingFlags;
                FieldsBindingFlags     = objectTextDumper.FieldsBindingFlags;
            }
Example #5
0
        internal static void BuildingScriptFor(
            ObjectTextDumper objectTextDumper,
            Type objectType,
            ClassDumpData classDumpData)
        {
            if (objectType == null)
            {
                throw new ArgumentNullException(nameof(objectType));
            }

            _sync.EnterWriteLock();

            _buildingNow.Add(new ScriptLookup(objectType, classDumpData, objectTextDumper));

            _sync.ExitWriteLock();
        }
Example #6
0
        private DumpState(
            ObjectTextDumper dumper,
            object instance,
            Type type,
            ClassDumpData classDumpData,
            DumpAttribute instanceDumpAttribute,
            DumpScript dumpScript,
            bool isTopLevelClass)
        {
            _dumper               = dumper ?? throw new ArgumentNullException(nameof(dumper));
            _isTopLevelClass      = isTopLevelClass;
            Instance              = instance ?? throw new ArgumentNullException(nameof(instance));
            InstanceType          = instance.GetType();
            CurrentType           = type ?? throw new ArgumentNullException(nameof(type));
            ClassDumpData         = classDumpData;
            InstanceDumpAttribute = instanceDumpAttribute ?? throw new ArgumentNullException(nameof(instanceDumpAttribute));
            DumpScript            = dumpScript;

            if (_isTopLevelClass)
            {
                var defaultProperty = DefaultProperty;

                if (!defaultProperty.IsNullOrWhiteSpace())
                {
                    var pi = CurrentType.GetProperty(defaultProperty);

                    Enumerator = pi != null
                                    ? (new MemberInfo[] { pi }).AsEnumerable().GetEnumerator()
                                    : (new MemberInfo[] { }).AsEnumerable().GetEnumerator();
                    return;
                }
            }

            Enumerator = CurrentType.GetProperties(_dumper.PropertiesBindingFlags | BindingFlags.DeclaredOnly)
                         .Union <MemberInfo>(
                CurrentType.GetFields(_dumper.FieldsBindingFlags | BindingFlags.DeclaredOnly))
                         .Where(mi => !mi.Name.StartsWith("<", StringComparison.Ordinal))
                         .OrderBy(p => p, ServiceResolver
                                  .Default
                                  .GetInstance <IMemberInfoComparer>()
                                  .SetMetadata(ClassDumpData.Metadata))
                         .GetEnumerator();
        }
Example #7
0
        public DumpState(
            ObjectTextDumper dumper,
            object instance,
            ClassDumpData classDumpData,
            bool buildScript)
            : this(dumper, instance, instance.GetType(), classDumpData, classDumpData.DumpAttribute, null, true)
        {
            if (dumper == null)
            {
                throw new ArgumentNullException(nameof(dumper));
            }
            if (instance == null)
            {
                throw new ArgumentNullException(nameof(instance));
            }

            // let's not create script if we don't need it or are not doing anything here.
            if (buildScript && CurrentType != typeof(object))
            {
                DumpScript = new DumpScript(instance.GetType());
            }

            DecrementMaxDepth();
        }