@@ -17,8 +17,10 @@ public class JsonUtility : JsonUtilityShared<FigmaGeneration>
1717 [ RuntimeInitializeOnLoadMethod ( RuntimeInitializeLoadType . SubsystemRegistration ) ]
1818 public static void Initialize ( )
1919 {
20- JsonSerializerSettings settings = new JsonSerializerSettings ( ) ;
21- settings . NullValueHandling = NullValueHandling . Ignore ;
20+ JsonSerializerSettings settings = new ( )
21+ {
22+ NullValueHandling = NullValueHandling . Ignore
23+ } ;
2224 settings . Converters . Add ( new EffectArrayConverter ( ) ) ;
2325 settings . Converters . Add ( new PaintArrayConverter ( ) ) ;
2426 settings . Converters . Add ( new LayoutGridArrayConverter ( ) ) ;
@@ -35,10 +37,7 @@ public static void Initialize()
3537 public abstract class ArrayConverter < T , U > : JsonConverter
3638 {
3739 #region Methods
38- public override bool CanConvert ( Type objectType )
39- {
40- return objectType == typeof ( T [ ] ) ;
41- }
40+ public override bool CanConvert ( Type objectType ) => objectType == typeof ( T [ ] ) ;
4241 public override object ReadJson ( JsonReader reader , Type objectType , object existingValue , JsonSerializer serializer )
4342 {
4443 JArray array = JArray . Load ( reader ) ;
@@ -53,10 +52,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
5352 foreach ( T node in array ) serializer . Serialize ( writer , node ) ;
5453 writer . WriteEndArray ( ) ;
5554 }
56- protected U GetValue ( JObject obj , string name = "type" )
57- {
58- return ( U ) Enum . Parse ( typeof ( U ) , obj [ name ] . Value < string > ( ) ) ;
59- }
55+ protected U GetValue ( JObject obj , string name = "type" ) => ( U ) Enum . Parse ( typeof ( U ) , obj [ name ] . Value < string > ( ) ) ;
6056 protected abstract T ToObject ( JObject obj , JsonSerializer serializer ) ;
6157 #endregion
6258 }
@@ -66,19 +62,14 @@ public class EffectArrayConverter : ArrayConverter<Effect, EffectType>
6662 #region Methods
6763 protected override Effect ToObject ( JObject obj , JsonSerializer serializer )
6864 {
69- switch ( GetValue ( obj ) )
65+ return GetValue ( obj ) switch
7066 {
71- case EffectType . INNER_SHADOW :
72- case EffectType . DROP_SHADOW :
73- return obj . ToObject < ShadowEffect > ( serializer ) ;
74-
75- case EffectType . LAYER_BLUR :
76- case EffectType . BACKGROUND_BLUR :
77- return obj . ToObject < BlurEffect > ( serializer ) ;
78-
79- default :
80- throw new NotSupportedException ( ) ;
81- }
67+ EffectType . INNER_SHADOW => obj . ToObject < ShadowEffect > ( serializer ) ,
68+ EffectType . DROP_SHADOW => obj . ToObject < ShadowEffect > ( serializer ) ,
69+ EffectType . LAYER_BLUR => obj . ToObject < BlurEffect > ( serializer ) ,
70+ EffectType . BACKGROUND_BLUR => obj . ToObject < BlurEffect > ( serializer ) ,
71+ _ => throw new NotSupportedException ( )
72+ } ;
8273 }
8374 #endregion
8475 }
@@ -88,24 +79,17 @@ public class PaintArrayConverter : ArrayConverter<Paint, PaintType>
8879 #region Methods
8980 protected override Paint ToObject ( JObject obj , JsonSerializer serializer )
9081 {
91- switch ( GetValue ( obj ) )
82+ return GetValue ( obj ) switch
9283 {
93- case PaintType . SOLID :
94- return obj . ToObject < SolidPaint > ( serializer ) ;
95-
96- case PaintType . GRADIENT_LINEAR :
97- case PaintType . GRADIENT_RADIAL :
98- case PaintType . GRADIENT_ANGULAR :
99- case PaintType . GRADIENT_DIAMOND :
100- return obj . ToObject < GradientPaint > ( serializer ) ;
101-
102- case PaintType . IMAGE :
103- case PaintType . EMOJI :
104- return obj . ToObject < ImagePaint > ( serializer ) ;
105-
106- default :
107- throw new ArgumentOutOfRangeException ( ) ;
108- }
84+ PaintType . SOLID => obj . ToObject < SolidPaint > ( serializer ) ,
85+ PaintType . GRADIENT_LINEAR => obj . ToObject < GradientPaint > ( serializer ) ,
86+ PaintType . GRADIENT_RADIAL => obj . ToObject < GradientPaint > ( serializer ) ,
87+ PaintType . GRADIENT_ANGULAR => obj . ToObject < GradientPaint > ( serializer ) ,
88+ PaintType . GRADIENT_DIAMOND => obj . ToObject < GradientPaint > ( serializer ) ,
89+ PaintType . IMAGE => obj . ToObject < ImagePaint > ( serializer ) ,
90+ PaintType . EMOJI => obj . ToObject < ImagePaint > ( serializer ) ,
91+ _ => throw new ArgumentOutOfRangeException ( )
92+ } ;
10993 }
11094 #endregion
11195 }
@@ -115,18 +99,13 @@ public class LayoutGridArrayConverter : ArrayConverter<LayoutGrid, Pattern>
11599 #region Methods
116100 protected override LayoutGrid ToObject ( JObject obj , JsonSerializer serializer )
117101 {
118- switch ( GetValue ( obj , "pattern" ) )
102+ return GetValue ( obj , "pattern" ) switch
119103 {
120- case Pattern . COLUMNS :
121- case Pattern . ROWS :
122- return obj . ToObject < RowsColsLayoutGrid > ( serializer ) ;
123-
124- case Pattern . GRID :
125- return obj . ToObject < GridLayoutGrid > ( serializer ) ;
126-
127- default :
128- throw new NotSupportedException ( ) ;
129- }
104+ Pattern . COLUMNS => obj . ToObject < RowsColsLayoutGrid > ( serializer ) ,
105+ Pattern . ROWS => obj . ToObject < RowsColsLayoutGrid > ( serializer ) ,
106+ Pattern . GRID => obj . ToObject < GridLayoutGrid > ( serializer ) ,
107+ _ => throw new NotSupportedException ( )
108+ } ;
130109 }
131110 #endregion
132111 }
@@ -136,56 +115,38 @@ public class ExportSettingsArrayConverter : ArrayConverter<ExportSettings, Forma
136115 #region Methods
137116 protected override ExportSettings ToObject ( JObject obj , JsonSerializer serializer )
138117 {
139- switch ( GetValue ( obj , "format" ) )
118+ return GetValue ( obj , "format" ) switch
140119 {
141- case Format . JPG :
142- case Format . PNG :
143- return obj . ToObject < ExportSettingsImage > ( serializer ) ;
144-
145- case Format . SVG :
146- return obj . ToObject < ExportSettingsSVG > ( serializer ) ;
147-
148- case Format . PDF :
149- return obj . ToObject < ExportSettingsPDF > ( serializer ) ;
150-
151- default :
152- throw new NotSupportedException ( ) ;
153- }
120+ Format . JPG => obj . ToObject < ExportSettingsImage > ( serializer ) ,
121+ Format . PNG => obj . ToObject < ExportSettingsImage > ( serializer ) ,
122+ Format . SVG => obj . ToObject < ExportSettingsSVG > ( serializer ) ,
123+ Format . PDF => obj . ToObject < ExportSettingsPDF > ( serializer ) ,
124+ _ => throw new NotSupportedException ( )
125+ } ;
154126 }
155127 #endregion
156128 }
157129
158130 public class TransitionConverter : JsonConverter
159131 {
160132 #region Methods
161- public override bool CanConvert ( Type objectType )
162- {
163- return objectType == typeof ( Transition ) ;
164- }
133+ public override bool CanConvert ( Type objectType ) => objectType == typeof ( Transition ) ;
165134 public override object ReadJson ( JsonReader reader , Type objectType , object existingValue , JsonSerializer serializer )
166135 {
167136 JObject obj = JObject . Load ( reader ) ;
168- switch ( ( TransitionType ) Enum . Parse ( typeof ( TransitionType ) , obj [ "type" ] . Value < string > ( ) ) )
137+ return ( TransitionType ) Enum . Parse ( typeof ( TransitionType ) , obj [ "type" ] ! . Value < string > ( ) ) switch
169138 {
170- case TransitionType . DISSOLVE :
171- case TransitionType . SMART_ANIMATE :
172- return obj . ToObject < SimpleTransition > ( serializer ) ;
173-
174- case TransitionType . MOVE_IN :
175- case TransitionType . MOVE_OUT :
176- case TransitionType . PUSH :
177- case TransitionType . SLIDE_IN :
178- case TransitionType . SLIDE_OUT :
179- return obj . ToObject < DirectionalTransition > ( serializer ) ;
180-
181- default :
182- throw new NotSupportedException ( ) ;
183- }
184- }
185- public override void WriteJson ( JsonWriter writer , object value , JsonSerializer serializer )
186- {
187- throw new NotImplementedException ( ) ;
139+ TransitionType . DISSOLVE => obj . ToObject < SimpleTransition > ( serializer ) ,
140+ TransitionType . SMART_ANIMATE => obj . ToObject < SimpleTransition > ( serializer ) ,
141+ TransitionType . MOVE_IN => obj . ToObject < DirectionalTransition > ( serializer ) ,
142+ TransitionType . MOVE_OUT => obj . ToObject < DirectionalTransition > ( serializer ) ,
143+ TransitionType . PUSH => obj . ToObject < DirectionalTransition > ( serializer ) ,
144+ TransitionType . SLIDE_IN => obj . ToObject < DirectionalTransition > ( serializer ) ,
145+ TransitionType . SLIDE_OUT => obj . ToObject < DirectionalTransition > ( serializer ) ,
146+ _ => throw new NotSupportedException ( )
147+ } ;
188148 }
149+ public override void WriteJson ( JsonWriter writer , object value , JsonSerializer serializer ) => throw new NotImplementedException ( ) ;
189150 #endregion
190151 }
191152
@@ -194,17 +155,12 @@ public class BaseNodeArrayConverter : ArrayConverter<BaseNode, NodeType>
194155 #region Methods
195156 protected override BaseNode ToObject ( JObject obj , JsonSerializer serializer )
196157 {
197- switch ( GetValue ( obj ) )
158+ return GetValue ( obj ) switch
198159 {
199- case NodeType . DOCUMENT :
200- return obj . ToObject < DocumentNode > ( serializer ) ;
201-
202- case NodeType . CANVAS :
203- return obj . ToObject < CanvasNode > ( serializer ) ;
204-
205- default :
206- throw new ArgumentOutOfRangeException ( ) ;
207- }
160+ NodeType . DOCUMENT => obj . ToObject < DocumentNode > ( serializer ) ,
161+ NodeType . CANVAS => obj . ToObject < CanvasNode > ( serializer ) ,
162+ _ => throw new ArgumentOutOfRangeException ( )
163+ } ;
208164 }
209165 #endregion
210166 }
@@ -214,53 +170,24 @@ public class SceneNodeArrayConverter : ArrayConverter<SceneNode, NodeType>
214170 #region Methods
215171 protected override SceneNode ToObject ( JObject obj , JsonSerializer serializer )
216172 {
217- switch ( GetValue ( obj ) )
173+ return GetValue ( obj ) switch
218174 {
219- case NodeType . SLICE :
220- return obj . ToObject < SliceNode > ( serializer ) ;
221-
222- case NodeType . FRAME :
223- return obj . ToObject < FrameNode > ( serializer ) ;
224-
225- case NodeType . GROUP :
226- return obj . ToObject < GroupNode > ( serializer ) ;
227-
228- case NodeType . COMPONENT_SET :
229- return obj . ToObject < ComponentSetNode > ( serializer ) ;
230-
231- case NodeType . COMPONENT :
232- return obj . ToObject < ComponentNode > ( serializer ) ;
233-
234- case NodeType . INSTANCE :
235- return obj . ToObject < InstanceNode > ( serializer ) ;
236-
237- case NodeType . BOOLEAN_OPERATION :
238- return obj . ToObject < BooleanOperationNode > ( serializer ) ;
239-
240- case NodeType . VECTOR :
241- return obj . ToObject < VectorNode > ( serializer ) ;
242-
243- case NodeType . STAR :
244- return obj . ToObject < StarNode > ( serializer ) ;
245-
246- case NodeType . LINE :
247- return obj . ToObject < LineNode > ( serializer ) ;
248-
249- case NodeType . ELLIPSE :
250- return obj . ToObject < EllipseNode > ( serializer ) ;
251-
252- case NodeType . REGULAR_POLYGON :
253- return obj . ToObject < RegularPolygonNode > ( serializer ) ;
254-
255- case NodeType . RECTANGLE :
256- return obj . ToObject < RectangleNode > ( serializer ) ;
257-
258- case NodeType . TEXT :
259- return obj . ToObject < TextNode > ( serializer ) ;
260-
261- default :
262- throw new ArgumentOutOfRangeException ( ) ;
263- }
175+ NodeType . SLICE => obj . ToObject < SliceNode > ( serializer ) ,
176+ NodeType . FRAME => obj . ToObject < FrameNode > ( serializer ) ,
177+ NodeType . GROUP => obj . ToObject < GroupNode > ( serializer ) ,
178+ NodeType . COMPONENT_SET => obj . ToObject < ComponentSetNode > ( serializer ) ,
179+ NodeType . COMPONENT => obj . ToObject < ComponentNode > ( serializer ) ,
180+ NodeType . INSTANCE => obj . ToObject < InstanceNode > ( serializer ) ,
181+ NodeType . BOOLEAN_OPERATION => obj . ToObject < BooleanOperationNode > ( serializer ) ,
182+ NodeType . VECTOR => obj . ToObject < VectorNode > ( serializer ) ,
183+ NodeType . STAR => obj . ToObject < StarNode > ( serializer ) ,
184+ NodeType . LINE => obj . ToObject < LineNode > ( serializer ) ,
185+ NodeType . ELLIPSE => obj . ToObject < EllipseNode > ( serializer ) ,
186+ NodeType . REGULAR_POLYGON => obj . ToObject < RegularPolygonNode > ( serializer ) ,
187+ NodeType . RECTANGLE => obj . ToObject < RectangleNode > ( serializer ) ,
188+ NodeType . TEXT => obj . ToObject < TextNode > ( serializer ) ,
189+ _ => throw new ArgumentOutOfRangeException ( )
190+ } ;
264191 }
265192 #endregion
266193 }
0 commit comments