public ILogEvent AppendUnmanaged <T>(ref T value)
            where T : unmanaged
        {
            if (!PrepareAppend(sizeof(ArgumentType) + sizeof(UnmanagedArgHeader) + sizeof(T)))
            {
                return(this);
            }

            AppendArgumentType(ArgumentType.Unmanaged);
            *(UnmanagedArgHeader *)_dataPointer = new UnmanagedArgHeader(TypeUtil <T> .TypeHandle, sizeof(T));
            _dataPointer      += sizeof(UnmanagedArgHeader);
            *(T *)_dataPointer = value;
            _dataPointer      += sizeof(T);
            return(this);
        }
        public ILogEvent AppendUnmanaged <T>(T value, string format)
            where T : unmanaged
        {
            if (!PrepareAppend(sizeof(ArgumentType) + sizeof(byte) + sizeof(UnmanagedArgHeader) + sizeof(T)))
            {
                return(this);
            }

            AppendArgumentTypeWithFormat(ArgumentType.Unmanaged);
            AppendString(format);
            *(UnmanagedArgHeader *)_dataPointer = new UnmanagedArgHeader(TypeUtil <T> .TypeHandle, sizeof(T));
            _dataPointer      += sizeof(UnmanagedArgHeader);
            *(T *)_dataPointer = value;
            _dataPointer      += sizeof(T);
            return(this);
        }
Beispiel #3
0
        private void AppendUnmanagedInternal <T>(T arg) // T = unmanaged or Nullable<unmanaged>
        {
            if (!PrepareAppend(sizeof(ArgumentType) + sizeof(UnmanagedArgHeader) + Unsafe.SizeOf <T>()))
            {
                return;
            }

            // If T is a Nullable<unmanaged>, we copy it as-is and let the formatter deal with it.
            // We're already in a slower execution path at this point.

            AppendArgumentType(ArgumentType.Unmanaged);
            *(UnmanagedArgHeader *)_dataPointer = new UnmanagedArgHeader(TypeUtil <T> .TypeHandle, Unsafe.SizeOf <T>());
            _dataPointer += sizeof(UnmanagedArgHeader);
            IL.Push(_dataPointer);
            IL.Push(arg);
            Stobj(typeof(T));
            _dataPointer += Unsafe.SizeOf <T>();
        }
        public ILogEvent AppendUnmanaged <T>(T?value)
            where T : unmanaged
        {
            if (!PrepareAppend(sizeof(ArgumentType) + sizeof(UnmanagedArgHeader) + sizeof(T)))
            {
                return(this);
            }

            if (value == null)
            {
                AppendArgumentType(ArgumentType.Null);
                return(this);
            }

            AppendArgumentType(ArgumentType.Unmanaged);
            *(UnmanagedArgHeader *)_dataPointer = new UnmanagedArgHeader(TypeUtil <T> .TypeHandle, sizeof(T));
            _dataPointer      += sizeof(UnmanagedArgHeader);
            *(T *)_dataPointer = value.GetValueOrDefault();
            _dataPointer      += sizeof(T);
            return(this);
        }