{"id":231,"date":"2021-04-05T20:13:08","date_gmt":"2021-04-05T11:13:08","guid":{"rendered":"https:\/\/lumiria.com\/develop\/programming\/csharp\/231\/"},"modified":"2023-06-02T22:21:10","modified_gmt":"2023-06-02T13:21:10","slug":"deepcopy-readonly-classmember","status":"publish","type":"post","link":"https:\/\/lumiria.com\/develop\/deepcopy-readonly-classmember","title":{"rendered":"DeepCopy.Expression &#8211; \u8aad\u307f\u53d6\u308a\u5c02\u7528\u306e\u30af\u30e9\u30b9\u30e1\u30f3\u30d0\u3092\u6301\u3064\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30b3\u30d4\u30fc\u3059\u308b"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<ul>\n<li>2023\/5\/31\u3000\u5185\u5bb9\u3092\u4fee\u6b63<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<p>\u4f55\u56de\u304b\u306b\u5206\u3051\u3066 <a href=\"https:\/\/github.com\/lumiria\/DeepCopy.Expression\">DeepCopy.Expression<\/a> \u306e\u7d39\u4ecb\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u4eca\u56de\u306f\u3001DeepCopy.Expression \u304c\u8aad\u307f\u53d6\u308a\u5c02\u7528\u306e\u30e1\u30f3\u30d0\u3092\u6301\u3064\u30af\u30e9\u30b9\u306e\u30c7\u30a3\u30fc\u30d7\u30b3\u30d4\u30fc\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u3053\u3068\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>C#\u3067\u306f\u3001\u8aad\u307f\u53d6\u308a\u5c02\u7528\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3084\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u6301\u3064\u30af\u30e9\u30b9\u3092\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\uff0f\u30c7\u30b7\u30ea\u30a2\u30e9\u30a4\u30ba\u3092\u5229\u7528\u3057\u3066\u30c7\u30a3\u30fc\u30d7\u30b3\u30d4\u30fc\u3059\u308b\u5834\u5408\u306f\u3001\u5bfe\u8c61\u306e\u30af\u30e9\u30b9\u5074\u304c\u305d\u308c\u306b\u5bfe\u5fdc\u3059\u308b\u5b9f\u88c5\u306b\u306a\u3063\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a _name \u3068\u3044\u3046\u8aad\u307f\u53d6\u308a\u5c02\u7528\u30d5\u30a3\u30fc\u30eb\u30c9\u3068 Child \u3068 UniqueId \u3068\u3044\u3046\u8aad\u307f\u53d6\u308a\u5c02\u7528\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u6301\u3064\u30af\u30e9\u30b9\u3092\u7528\u610f\u3057\u307e\u3057\u305f\u3002<br>_name \u3068 Child \u306f\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u5f15\u6570\u306b\u3088\u3063\u3066\u5024\u304c\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u304c\u3001UniqueId  \u306f\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u5185\u90e8\u3067\u81ea\u52d5\u5272\u308a\u5f53\u3066\u3055\u308c\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code language-csharp\"><code>public sealed class Item\n{\n     private readonly string _name;\n\n     public Item(string name, Item? child = null)\n     {\n         _name = name;\n         Child = child;\n         UniqueId = Guid.NewGuid().ToString();\n     }\n\n     public string Name =&gt; _name;\n     public Item? Child { get; }\n     public string UniqueId { get; }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span id=\"i\">\u30b7\u30ea\u30a2\u30e9\u30a4\u30b6\u3067\u30c7\u30a3\u30fc\u30d7\u30b3\u30d4\u30fc<\/span><\/h2>\n\n\n\n<p>\u3053\u306e\u30af\u30e9\u30b9\u3092 JsonSerializer \u3092\u7528\u3044\u3066\u30c7\u30a3\u30fc\u30d7\u30b3\u30d4\u30fc\u3057\u305f\u5834\u5408\u306f\u6b21\u306e\u3088\u3046\u306a\u7d50\u679c\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code language-csharp\"><code>public sealed class Item\nvar item = new Item(\"foo\", new Item(\"bar\"));\n\nvar json = JsonSerializer.Serialize(item);\nvar cloned = JsonSerializer.Deserialize<Item>(json);\n\nConsole.WriteLine($\"[original] Name = {item.Name}, Child = {item.Child?.Name}, UniqueId = {item.UniqueId}\");\nConsole.WriteLine($\"[cloned]   Name = {cloned?.Name}, Child = {cloned?.Child?.Name}, UniqueId = {cloned?.UniqueId}\");\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">[original] Name = foo, Child = bar, UniqueId = 5e167a0c-2f56-457e-94f7-553492500c76\n[cloned]   Name = foo, Child = bar, UniqueId = 48fea065-6c9b-4c54-8150-9d621661f496<\/pre>\n\n\n\n<p>\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306e\u5f15\u6570\u3067\u521d\u671f\u5316\u3057\u3066\u3044\u308b _name \u3068 Child \u306f\u30b3\u30d4\u30fc\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001UniqueId \u306f\u5225\u306e\u5024\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3067\u521d\u671f\u5316\u3055\u308c\u306a\u3044\u30e1\u30f3\u30d0\u3082\u542b\u3081\u3066\u30c7\u30a3\u30fc\u30d7\u30b3\u30d4\u30fc\u3059\u308b\u306b\u306f\u3001\u5bfe\u8c61\u306e\u30e1\u30f3\u30d0\u306b init \u30a2\u30af\u30bb\u30b5\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3067\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code language-csharp\"><code>public sealed class Item\n{\n    private readonly string _name;\n\n    public Item(string name, Item? child = null)\n    {\n        _name = name;\n        Child = child;\n        UniqueId = Guid.NewGuid().ToString();\n    }\n\n    public string Name =&gt; _name;\n    public Item? Child { get; }\n    public string UniqueId { get; <strong>init<\/strong>; }\n}<\/code><\/pre>\n\n\n\n<p>\u3053\u308c\u3067\u518d\u5ea6\u30b7\u30ea\u30a2\u30e9\u30a4\u30b6\u3067\u30b3\u30d4\u30fc\u3059\u308b\u3068\u671f\u5f85\u3059\u308b\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[original] Name = foo, Child = bar, UniqueId = ea0b669a-c77e-4d0b-a899-5d1949b3201a\n[cloned]   Name = foo, Child = bar, UniqueId = ea0b669a-c77e-4d0b-a899-5d1949b3201a<\/pre>\n\n\n\n<p>\u3067\u306f\u3001\u6b21\u306b DeepCopy.Expression \u3067\u5143\u306e\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u30b3\u30d4\u30fc\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span id=\"DeepCopyExpression\">DeepCopy.Expression \u3067\u30b3\u30d4\u30fc<\/span><\/h2>\n\n\n\n<p>DeepCopy.Expression \u306f\u3001\u8aad\u307f\u53d6\u308a\u5c02\u7528\u306e\u30e1\u30f3\u30d0\u3082\u542b\u3081\u3066\u30c7\u30a3\u30fc\u30d7\u30b3\u30d4\u30fc\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code language-csharp\"><code>var item = new Item(\"foo\", new Item(\"bar\"));\nvar cloned = ObjectCloner.Clone(item);\n\nConsole.WriteLine($\"&#91;original] Name = {item.Name}, Child = {item.Child?.Name}, UniqueId = {item.UniqueId}\");\nConsole.WriteLine($\"&#91;cloned]   Name = {cloned?.Name}, Child = {cloned?.Child?.Name}, UniqueId = {cloned?.UniqueId}\");<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">[original] Name = foo, Child = bar, UniqueId = 2f8a9900-0485-4131-9a9d-b8ee2c388dfd\n[cloned]   Name = foo, Child = bar, UniqueId = 2f8a9900-0485-4131-9a9d-b8ee2c388dfd<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span id=\"i-2\">\u307e\u3068\u3081<\/span><\/h2>\n\n\n\n<p>DeepCopy.Expression \u3092\u4f7f\u3048\u3070\u3001\u8aad\u307f\u53d6\u308a\u5c02\u7528\u30e1\u30f3\u30d0\u3092\u6301\u3064\u30af\u30e9\u30b9\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3082\u3001\u5143\u306e\u30af\u30e9\u30b9\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u306a\u304f\u3001\u305d\u306e\u307e\u307e\u30c7\u30a3\u30fc\u30d7\u30b3\u30d4\u30fc\u3059\u308b\u4e8b\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f55\u56de\u304b\u306b\u5206\u3051\u3066 DeepCopy.Expression \u306e\u7d39\u4ecb\u3092\u66f8\u3044\u3066\u3044\u304d\u307e\u3059\u3002 \u4eca\u56de\u306f\u3001DeepCopy.Expression \u304c\u8aad\u307f\u53d6\u308a\u5c02\u7528\u306e\u30e1\u30f3\u30d0\u3092\u6301\u3064\u30af\u30e9\u30b9\u306e\u30c7\u30a3\u30fc\u30d7\u30b3\u30d4\u30fc\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u3053\u3068\u3064\u3044\u3066\u7d39\u4ecb\u3057\u307e\u3059\u3002 C&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[8],"tags":[11],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paPnUb-3J","_links":{"self":[{"href":"https:\/\/lumiria.com\/develop\/wp-json\/wp\/v2\/posts\/231"}],"collection":[{"href":"https:\/\/lumiria.com\/develop\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lumiria.com\/develop\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lumiria.com\/develop\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lumiria.com\/develop\/wp-json\/wp\/v2\/comments?post=231"}],"version-history":[{"count":34,"href":"https:\/\/lumiria.com\/develop\/wp-json\/wp\/v2\/posts\/231\/revisions"}],"predecessor-version":[{"id":419,"href":"https:\/\/lumiria.com\/develop\/wp-json\/wp\/v2\/posts\/231\/revisions\/419"}],"wp:attachment":[{"href":"https:\/\/lumiria.com\/develop\/wp-json\/wp\/v2\/media?parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lumiria.com\/develop\/wp-json\/wp\/v2\/categories?post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lumiria.com\/develop\/wp-json\/wp\/v2\/tags?post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}