Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.
This repository was archived by the owner on Aug 4, 2025. It is now read-only.

Consider whether to switch IsSetInfo to use a class instead of a struct #32

Description

@adamconnelly

The compiler generates an IsSetInfo struct containing a member for each optional field in the Thrift struct. At the moment it uses a C# struct rather than a class, to match what the official compiler does. The issue with this is that it breaks the guidelines for when to use a struct in C#.

Here's an example:

public class User
{
    private IsSetInfo isSet;
    private int? _Field1;

    /// <summary>
    /// Gets information about whether each optional field has been set.
    /// </summary>
    public IsSetInfo IsSet
    {
        get { return this.isSet; }
    }

    public int? Field1
    {
        get 
        {
            return _Field1;
        }

        set
        {
            this._Field1 = value;
            this.isSet.Field1 = true;
        }
    }

    /// <summary>
    /// Contains an entry for each optional field, indicating whether it has been
    /// set or not.
    /// </summary>
    public struct IsSetInfo
    {
        public bool Field1;
    }
}

Because of that, we should try to figure out why this decision was made, and if it makes sense to keep it as a struct, we should document the reason why. In case a struct was chosen for performance reasons, we should wait to make any changes until we have benchmarks in place so we can justify the change makes sense.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions