{"id":365163,"date":"2024-05-21T02:32:19","date_gmt":"2024-05-21T02:32:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=365163"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T02:32:19","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=365163","title":{"rendered":"<span>\u0412\u043a\u043b\u044e\u0447\u0430\u0435\u043c Nullable reference types \u0432 Unity \u0437\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0438\u043d\u0443\u0442<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>? \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Nullable reference types<\/h2>\n<p><code>Nullable reference types<\/code> \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>null<\/code> \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u044b\u043c \u0442\u0438\u043f\u0430\u043c.<\/p>\n<h4>? \u041a\u0430\u043a\u0438\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0434\u0430\u0435\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f\u00a0\u0441\u0441\u044b\u043b\u043e\u0447\u043d\u044b\u0445 nullable-\u0442\u0438\u043f\u043e\u0432<\/h4>\n<ul>\n<li>\n<p>Design time \u0430\u043d\u0430\u043b\u0438\u0437<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0442\u043a\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u044b API<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 Null \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u043e\u043c IDE, \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f <code>System.NullReferenceException<\/code><\/p>\n<\/li>\n<\/ul>\n<h2>? \u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<ul>\n<li>\n<p>.NET Standard 2.1+<\/p>\n<\/li>\n<li>\n<p>Unity 2021+<\/p>\n<\/li>\n<\/ul>\n<h2>? \u041a\u0430\u043a \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437<\/h2>\n<h4>\u0414\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0431\u043e\u0440\u043e\u043a<\/h4>\n<hr\/>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u00a0<code>csc.rsp<\/code>\u00a0\u0440\u044f\u0434\u043e\u043c \u0441\u043e \u0441\u0431\u043e\u0440\u043a\u043e\u0439 <code>asmdef<\/code> :<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9db\/d2f\/c98\/9dbd2fc980986a890a66a60c740b2928.png\" width=\"276\" height=\"108\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9db\/d2f\/c98\/9dbd2fc980986a890a66a60c740b2928.png\"\/><\/figure>\n<p>\u0412 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435\u00a0<code>csc.rsp<\/code>\u00a0\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u00a0<code>nullable<\/code> :<\/p>\n<pre><code class=\"cs\">-nullable:enable<\/code><\/pre>\n<h4>\u0414\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 .cs \u0444\u0430\u0439\u043b\u043e\u0432<\/h4>\n<hr\/>\n<p>\u0412 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435\u00a0<code>.cs<\/code>\u00a0\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439\u00a0<code>#nullable<\/code> :<\/p>\n<pre><code class=\"cs\">#nullable enable  namespace Sandbox.Domain {     public struct User     {         public int Id { get; set; }         public string Nickname { get; set; }         public string? Phone { get; set; }     } }<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>Nullable<\/code> \u0442\u0438\u043f\u0430 \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435 <code>Phone<\/code>, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c.<\/p>\n<h2>? \u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438, \u043f\u043e\u0434\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e null-forgiving \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>!<\/code>.<\/p>\n<h4>Unity UI \u0431\u0438\u043d\u0434\u044b:<\/h4>\n<pre><code class=\"cs\">[SerializeField] private Image _image = null!;<\/code><\/pre>\n<h4>DI VContainer \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b:<\/h4>\n<pre><code class=\"cs\">namespace Sandbox.Domain {     private MoveController _moveController = null!;      [Inject]     public void Init(MoveController moveController)     {         _moveController = moveController;     } }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439:<\/p>\n<pre><code class=\"cs\">#nullable disable  using System;  namespace Sandbox.Server.Responses {     [Serializable]     public class UserResponse     {         public int Id;         public string Name;     } }<\/code><\/pre>\n<h2>? \u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p><a href=\"https:\/\/youtu.be\/NZ-rypeT8iw\" rel=\"noopener noreferrer nofollow\">Nullable reference types in Unity<\/a><br \/><a href=\"https:\/\/www.youtube.com\/watch?v=6cEh13Q3Haw\" rel=\"noopener noreferrer nofollow\">NullReferenceException = \u2665\u00a0<\/a><br \/><a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/nullable-references\" rel=\"noopener noreferrer nofollow\">Microsoft guide<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/786082\/\"> https:\/\/habr.com\/ru\/articles\/786082\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>? \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Nullable reference types<\/h2>\n<p><code>Nullable reference types<\/code> \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>null<\/code> \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u044b\u043c \u0442\u0438\u043f\u0430\u043c.<\/p>\n<h4>? \u041a\u0430\u043a\u0438\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0434\u0430\u0435\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f\u00a0\u0441\u0441\u044b\u043b\u043e\u0447\u043d\u044b\u0445 nullable-\u0442\u0438\u043f\u043e\u0432<\/h4>\n<ul>\n<li>\n<p>Design time \u0430\u043d\u0430\u043b\u0438\u0437<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0442\u043a\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u044b API<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 Null \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u043e\u043c IDE, \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f <code>System.NullReferenceException<\/code><\/p>\n<\/li>\n<\/ul>\n<h2>? \u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<ul>\n<li>\n<p>.NET Standard 2.1+<\/p>\n<\/li>\n<li>\n<p>Unity 2021+<\/p>\n<\/li>\n<\/ul>\n<h2>? \u041a\u0430\u043a \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437<\/h2>\n<h4>\u0414\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0431\u043e\u0440\u043e\u043a<\/h4>\n<hr\/>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u00a0<code>csc.rsp<\/code>\u00a0\u0440\u044f\u0434\u043e\u043c \u0441\u043e \u0441\u0431\u043e\u0440\u043a\u043e\u0439 <code>asmdef<\/code> :<\/p>\n<figure class=\"\"><\/figure>\n<p>\u0412 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435\u00a0<code>csc.rsp<\/code>\u00a0\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u00a0<code>nullable<\/code> :<\/p>\n<pre><code class=\"cs\">-nullable:enable<\/code><\/pre>\n<h4>\u0414\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 .cs \u0444\u0430\u0439\u043b\u043e\u0432<\/h4>\n<hr\/>\n<p>\u0412 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435\u00a0<code>.cs<\/code>\u00a0\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439\u00a0<code>#nullable<\/code> :<\/p>\n<pre><code class=\"cs\">#nullable enable  namespace Sandbox.Domain {     public struct User     {         public int Id { get; set; }         public string Nickname { get; set; }         public string? Phone { get; set; }     } }<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>Nullable<\/code> \u0442\u0438\u043f\u0430 \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435 <code>Phone<\/code>, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c.<\/p>\n<h2>? \u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438, \u043f\u043e\u0434\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e null-forgiving \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>!<\/code>.<\/p>\n<h4>Unity UI \u0431\u0438\u043d\u0434\u044b:<\/h4>\n<pre><code class=\"cs\">[SerializeField] private Image _image = null!;<\/code><\/pre>\n<h4>DI VContainer \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b:<\/h4>\n<pre><code class=\"cs\">namespace Sandbox.Domain {     private MoveController _moveController = null!;      [Inject]     public void Init(MoveController moveController)     {         _moveController = moveController;     } }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430, \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439:<\/p>\n<pre><code class=\"cs\">#nullable disable  using System;  namespace Sandbox.Server.Responses {     [Serializable]     public class UserResponse     {         public int Id;         public string Name;     } }<\/code><\/pre>\n<h2>? \u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p><a href=\"https:\/\/youtu.be\/NZ-rypeT8iw\" rel=\"noopener noreferrer nofollow\">Nullable reference types in Unity<\/a><br \/><a href=\"https:\/\/www.youtube.com\/watch?v=6cEh13Q3Haw\" rel=\"noopener noreferrer nofollow\">NullReferenceException = \u2665\u00a0<\/a><br \/><a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/nullable-references\" rel=\"noopener noreferrer nofollow\">Microsoft guide<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/786082\/\"> https:\/\/habr.com\/ru\/articles\/786082\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-365163","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/365163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=365163"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/365163\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=365163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=365163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=365163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}