VitaliiTsilnyk / NGettext

A cross-platform .NET implementation of the GNU/Gettext library.
MIT License
215 stars 45 forks source link

Question: Why does 'ReadUInt16' have the `CLSCompliant(false)` attribute? #21

Closed kruncher closed 7 years ago

kruncher commented 7 years ago

When used in Unity I am seeing the following warning:

BigEndianBinaryReader.ReadUInt16()' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant

What is the purpose of the attribute in this scenario?

// This method does not have the attribute:
public override short ReadInt16()
{
    this._FillBuffer(2);
    return (short)(this._Buffer[1] | this._Buffer[0] << 8);
}

// This method does:
[CLSCompliant(false)]
public override ushort ReadUInt16()
{
    this._FillBuffer(2);
    return (ushort)(this._Buffer[1] | this._Buffer[0] << 8);
}
VitaliiTsilnyk commented 7 years ago

NGettext library by itself is CLS-compliant. Which means it can be used in project written in any language that .NET Framework supports (for example even the ones that don't have unsigned integers). Because of that you can even use NGettext from PowerShell if you want to.

The attribute can be used to mark some part of the code as non-CLS-compliant so it won't be included in the library's public interface for systems that require CLS compliance.

Getting the warning you got means that you're trying to inline NGettext assembly/code into your assembly. I guess you can add those warnings to ignore list and it will be perfectly fine, it's just a note for developers to ensure that they didn't forget to properly configure their assembly.

kruncher commented 7 years ago

Thank you for the detailed information! this is very interesting.

Due to limitations with the environment that I am working within it is necessary to inline NGettext and place it within an "Internal" namespace to avoid conflicts with other packages that also include a NGettext assembly.

Since C# is the only language that the Unity game engine actively supports then I assume that there will be no issue if I just comment out those CLSCompliant attributes.

Thanks again for the info!