Typedef in C # for multiple source files

I am writing a C wrapper that would like to use typedef aquivalent to define some types that must be valid in a fairly large number of source files. These "types" are just different aliases for [u] int16 / 32 / 64_t, but they are useful for distinguishing functional parameters.

It can be used using MyId=System.Int32;, but it should be updated in every file, as far as I can see ... Is there a better way?

+3
source share
2 answers

One alternative approach is to use a structure with an implicit conversion to a base type.

public struct MyHandle
{
    private int _handle;

    internal MyHandle(int handle)
    {
        _handle = handle;
    }

    public static implicit operator int(MyHandle handle)
    {
        return handle._handle;
    }
}

(int ) , . int, . int Handle, , .

+4

, UIt32 , , , .

0

Source: https://habr.com/ru/post/1744368/


All Articles