apple / apple/unityplugins

Use internal when exposing low-level types like IntPtr

Offen
#97 0 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @ryzngard Auf GitHub ansehen
bug
Vorherrschende Sprache
C#
Sterne
982
Forks
248
Ø Merge
6 T. 12 Std.
Gemergte PRs (30 T.)
2

Beschreibung

**Is your feature request related to a problem? Please describe.**

No, this is about hardening the API.

Exposing low-level types like `IntPtr` as `public` in user-facing code is bad practice for an interop library like this. It causes excessive, unnecessary information and APIs being exposed to users, which could lead to confusion and error-prone code being made with it.

---

**Describe the solution you'd like**

Refactor client-facing low-level members, constructors, etc. to be `internal` (or `protected internal` if necessary). For example, `NSArray` has a `public` constructor with an `IntPtr` parameter. Users do not need to know about this, and makes the API messier for those trying to simply interface with it. Using an `AssemblyInfo.cs` can allow `internal` members to be available to other Apple assemblies without having to expose unnecessary data to users.

---

**Describe alternatives you've considered**

There are none.

---

**Additional context**

https://docs.unity3d.com/2020.1/Documentation/Manual/ScriptCompilationAssemblyDefinitionFiles.html

Example `AssemblyInfo.cs` file:
```csharp
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Apple.Core.Tests")]
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.