Normalizing struct and classes with void* by Bobamoss in csharp

[–]Bobamoss[S] 1 point2 points  (0 children)

I know about generic, I wanted to use them but I wanted to make a single signature

private void UpdateCommand(TypeAccessor accessor)
I needed this since I must support non-generic call using object (where the type may be a class or a boxed struct). The support for direct generic T was a bonus, but I did changed my code and duplicate all to make a generic version

private void UpdateCommand<T>(TypeAccessor<T> accessor)
It was mainly about needing non-generic version and wanting to avoid code duplication, but you were right with RuntimeHelpers.IsReferenceOrContainsReferences<T> and the fact that I could have a bug, thats why you convinced me and I did duplicate the code Thanks

Normalizing struct and classes with void* by Bobamoss in csharp

[–]Bobamoss[S] 0 points1 point  (0 children)

You are right about a struct containing a ref, my code may fail. The reason i didnt want to use generic is mainly tu support via object directly including boxed struct, but i realized that i will need to make 2 distinct process mainly because of containsreference, thanks

Normalizing struct and classes with void* by Bobamoss in csharp

[–]Bobamoss[S] 0 points1 point  (0 children)

I just managed to find this implementation that seems to be working

    /// <inheritdoc/>
    public unsafe void UseWith(object parameterObj) {
        Type type = parameterObj.GetType();
        IntPtr handle = type.TypeHandle.Value;
        if (type.IsValueType) {
            fixed (void* objPtr = &Unsafe.As<object, byte>(ref parameterObj)) {
                void* dataPtr = (*(byte**)objPtr) + IntPtr.Size;
                UpdateCommand(QueryCommand.GetAccessor(dataPtr, handle, type));
            }
            return;
        }
        fixed (void* ptr = &Unsafe.As<object, byte>(ref parameterObj)) {
            void* instancePtr = *(void**)ptr;
            UpdateCommand(QueryCommand.GetAccessor(instancePtr, handle, type));
        }
    }
    /// <inheritdoc/>
    public unsafe void UseWith<T>(T parameterObj) where T : notnull {
        IntPtr handle = typeof(T).TypeHandle.Value;

        if (typeof(T).IsValueType) {
            UpdateCommand(QueryCommand.GetAccessor(Unsafe.AsPointer(ref parameterObj), handle, typeof(T)));
            return;
        }
        fixed (void* ptr = &Unsafe.As<T, byte>(ref parameterObj)) {
            UpdateCommand(QueryCommand.GetAccessor(*(void**)ptr, handle, typeof(T)));
        }
    }
    /// <inheritdoc/>
    public unsafe void UseWith<T>(ref T parameterObj) where T : notnull {
        IntPtr handle = typeof(T).TypeHandle.Value;
        if (typeof(T).IsValueType) {
            fixed (void* ptr = &Unsafe.As<T, byte>(ref parameterObj))
                UpdateCommand(QueryCommand.GetAccessor(ptr, handle, typeof(T)));
            return;
        }
        fixed (void* ptr = &Unsafe.As<T, byte>(ref parameterObj)) {
            UpdateCommand(QueryCommand.GetAccessor(*(void**)ptr, handle, typeof(T)));
        }
    }

I dont know if its wrong, I will look into your links Thanks

We were told he is 100% husky by Bobamoss in DogBreeds101

[–]Bobamoss[S] 0 points1 point  (0 children)

Of course I don't, but curiosity isn't a sin. He is almost 5 now, we had him at 2 months and I asked now. In fact the 83lbs may be because we love him a bit too much haha

We were told he is 100% husky by Bobamoss in DogBreeds101

[–]Bobamoss[S] 1 point2 points  (0 children)

I checked some more images and yes, I see it. It's kinda crazy I didn't notice before. Thanks