Esempio n. 1
0
        internal void WriteObjectType(BinaryWriter writer, long lengthStartPosition, object obj, ExtendedType typeSupport, int currentDepth, string path)
        {
            // write each element
            var fields = obj.GetFields(FieldOptions.AllWritable).OrderBy(x => x.Name);

            var rootPath  = path;
            var localPath = string.Empty;
            var index     = 0;

            foreach (var field in fields)
            {
                localPath = $"{rootPath}.{field.ReflectedType.Name}.{field.Name}";
                var fieldExtendedType = new ExtendedType(field.Type);
                var fieldValue        = obj.GetFieldValue(field);
                fieldExtendedType.SetConcreteTypeFromInstance(fieldValue);

                if (fieldExtendedType.IsDelegate)
                {
                    continue;
                }

                // check for ignore attributes
                if (IgnoreObjectName(field.Name, localPath, field.CustomAttributes))
                {
                    continue;
                }
                // also check the property for ignore, if this is a auto-backing property
                if (field.BackedProperty != null && IgnoreObjectName(field.BackedProperty.Name, $"{rootPath}.{field.ReflectedType.Name}.{field.BackedPropertyName}", field.BackedProperty.CustomAttributes))
                {
                    continue;
                }

                WriteObject(writer, fieldValue, fieldExtendedType, currentDepth, localPath, index);
                index++;
            }
        }