forked from DynamoDS/Dynamo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.cs
More file actions
758 lines (657 loc) · 28.9 KB
/
Copy pathData.cs
File metadata and controls
758 lines (657 loc) · 28.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using System.Text;
using Autodesk.DesignScript.Geometry;
using Autodesk.DesignScript.Runtime;
using Dynamo.Events;
using Dynamo.Logging;
using Dynamo.Session;
using DynamoUnits;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace DSCore
{
public static class Data
{
/// <summary>
/// Parse converts an arbitrary JSON string to a value. It is the opposite of JSON.Stringify.
/// </summary>
/// <param name="json">A JSON string</param>
/// <returns name="result">The result type depends on the content of the input string. The result type can be a primitive value (e.g. string, boolean, double), a List, or a Dictionary.</returns>
public static object ParseJSON(string json)
{
return ToNative(JToken.Parse(json));
}
/// <summary>
/// Parse implementation for converting JToken types to native .NET objects.
/// </summary>
/// <param name="token">JToken to parse to N</param>
/// <returns></returns>
private static object ToNative(JToken token)
{
switch (token.Type)
{
case JTokenType.Object:
var obj = token as JObject;
var dynObj = DynamoJObjectToNative(obj);
if(dynObj != null)
{
return dynObj;
}
var dict = new Dictionary<string, object>();
foreach (var kv in obj)
{
dict[kv.Key] = ToNative(kv.Value);
}
return dict;
case JTokenType.Array:
var arr = token as JArray;
return arr.Select(ToNative);
case JTokenType.Null:
return null;
case JTokenType.Integer:
case JTokenType.Float:
case JTokenType.String:
case JTokenType.Boolean:
case JTokenType.Date:
case JTokenType.TimeSpan:
return (token as JValue).Value;
case JTokenType.Guid:
case JTokenType.Uri:
return (token as JValue).Value.ToString();
default:
return null;
}
}
/// <summary>
/// Parse implementation for converting JObject types to specific Dynamo objects (ie Geometry, Color, Images, etc)
/// </summary>
/// <param name="jObject"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
private static object DynamoJObjectToNative(JObject jObject)
{
if (jObject.ContainsKey("$typeid"))
{
var typeid = jObject["$typeid"].ToString();
switch (typeid)
{
//autodesk.math to abstract ProtoGeometry types
case "autodesk.math:vector3d-1.0.0":
return Vector.FromJson(jObject.ToString());
case "autodesk.math:matrix44d-1.0.0":
return CoordinateSystem.FromJson(jObject.ToString());
//autodesk.geometry to abstract ProtoGeometry types
case "autodesk.geometry:boundingbox3d-1.0.0":
return BoundingBox.FromJson(jObject.ToString());
case "dynamo.geometry:mesh-1.0.0":
return Mesh.FromJson(jObject.ToString());
//types supported by Geometry.FromJson
case "autodesk.math:point3d-1.0.0":
case "dynamo.geometry:sab-1.0.0":
case "dynamo.geometry:tsm-1.0.0":
case "dynamo.geometry:rectangle-1.0.0":
case "dynamo.geometry:cuboid-1.0.0":
case "dynamo.geometry:solid-1.0.0":
case string geoId when geoId.Contains("autodesk.geometry"):
return Geometry.FromJson(jObject.ToString());
//Dynamo types
case "dynamo.graphics:color-1.0.0":
try
{
return Color.ByARGB(
(int)jObject["A"],
(int)jObject["R"],
(int)jObject["G"],
(int)jObject["B"]);
}
catch {
throw new FormatException(string.Format(Properties.Resources.Exception_Deserialize_Bad_Format, typeof(Color).FullName));
}
#if _WINDOWS
case "dynamo.graphics:png-1.0.0":
jObject.TryGetValue(ImageFormat.Png.ToString(), out var value);
if (value != null)
{
try
{
var stream = Convert.FromBase64String(value.ToString());
Bitmap bitmap;
using (var ms = new MemoryStream(stream))
bitmap = new Bitmap(Bitmap.FromStream(ms));
return bitmap;
}
catch {
//Pass through to the next throw
}
}
throw new FormatException(string.Format(Properties.Resources.Exception_Deserialize_Bad_Format, "dynamo.graphics:png-1.0.0"));
#else
return null;
#endif
case "dynamo.data:location-1.0.0":
try
{
return DynamoUnits.Location.ByLatitudeAndLongitude(
(double)jObject["Latitude"],
(double)jObject["Longitude"],
(string)jObject["Name"]);
}
catch
{
throw new FormatException(string.Format(Properties.Resources.Exception_Deserialize_Bad_Format, typeof(DynamoUnits.Location).FullName));
}
default:
return null;
}
}
if (jObject.ContainsKey("typeid"))
{
var typeid = jObject["typeid"].ToString();
if (typeid == "autodesk.soliddef:model-1.0.0")
{
return Geometry.FromSolidDef(jObject.ToString());
}
}
return null;
}
/// <summary>
/// Stringify converts an arbitrary value or a list of arbitrary values to JSON. Replication can be used to apply the operation over a list, producing a list of JSON strings.
/// </summary>
/// <param name="values">A List of values</param>
/// <returns name="json">A JSON string where primitive types (e.g. double, int, boolean), Lists, and Dictionary's will be turned into the associated JSON type.</returns>
public static string StringifyJSON([ArbitraryDimensionArrayImport] object values)
{
var settings = new JsonSerializerSettings()
{
Converters = new JsonConverter[]
{
new DictConverter(),
new DesignScriptGeometryConverter(),
new ColorConveter(),
new LocationConverter(),
#if _WINDOWS
new PNGImageConverter(),
#endif
}
};
StringBuilder sb = new StringBuilder(256);
using (var writer = new StringWriter(sb, CultureInfo.InvariantCulture))
{
using (var jsonWriter = new MaxDepthJsonTextWriter(writer))
{
JsonSerializer.Create(settings).Serialize(jsonWriter, values);
}
return writer.ToString();
}
}
/// <summary>
/// Subclass of JsonTextWriter that limits a maximum supported object depth to prevent circular reference crashes when serializing arbitrary .NET objects types.
/// </summary>
private class MaxDepthJsonTextWriter : JsonTextWriter
{
private readonly int maxDepth = 15;
private int depth = 0;
public MaxDepthJsonTextWriter(TextWriter writer) : base(writer) { }
public override void WriteStartArray()
{
base.WriteStartArray();
depth++;
CheckDepth();
}
public override void WriteEndArray()
{
base.WriteEndArray();
depth--;
CheckDepth();
}
public override void WriteStartObject()
{
base.WriteStartObject();
depth++;
CheckDepth();
}
public override void WriteEndObject()
{
base.WriteEndObject();
depth--;
CheckDepth();
}
private void CheckDepth()
{
if (depth > maxDepth)
{
throw new JsonSerializationException(string.Format(Properties.Resources.Exception_Serialize_Depth_Unsupported, depth, maxDepth, Path));
}
}
}
#region Converters
/// <summary>
/// Ensures DesignScript.Builtin.Dictionary's, which deliberately don't implement IDictionary, are transformed into JSON objects.
/// </summary>
private class DictConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
object obj;
if (value is DesignScript.Builtin.Dictionary)
{
var dict = value as DesignScript.Builtin.Dictionary;
var rdict = new Dictionary<string, object>();
foreach (var key in dict.Keys)
{
rdict[key] = dict.ValueAtKey(key);
}
obj = rdict;
}
else
{
obj = value;
}
serializer.Serialize(writer, obj);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException("Unnecessary because CanRead is false. The type will skip the converter.");
}
public override bool CanRead
{
get { return false; }
}
public override bool CanConvert(Type objectType)
{
return objectType == typeof(DesignScript.Builtin.Dictionary);
}
}
private class DesignScriptGeometryConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
string serializedValue;
switch(value)
{
case Geometry item:
var geoString = item.ToJson();
if (!string.IsNullOrEmpty(geoString))
{
writer.WriteRawValue(geoString);
return;
}
break;
case BoundingBox item:
writer.WriteRawValue(item.ToJson());
return;
case CoordinateSystem item:
writer.WriteRawValue(item.ToJson());
return;
case Mesh item:
writer.WriteRawValue(item.ToJson());
return;
case Vector item:
writer.WriteRawValue(item.ToJson());
return;
}
throw new NotSupportedException(Properties.Resources.Exception_Serialize_DesignScript_Unsupported);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException("Unnecessary because CanRead is false. The type will skip the converter.");
}
public override bool CanRead
{
get { return false; }
}
public override bool CanConvert(Type objectType)
{
return typeof(DesignScriptEntity).IsAssignableFrom(objectType);
}
}
private class ColorConveter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var jobject = JObject.FromObject(value);
jobject.Add("$typeid", "dynamo.graphics:color-1.0.0");
jobject.WriteTo(writer);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException("Unnecessary because CanRead is false. The type will skip the converter.");
}
public override bool CanRead
{
get { return false; }
}
public override bool CanConvert(Type objectType)
{
return typeof(DSCore.Color) == objectType;
}
}
private class LocationConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var jobject = JObject.FromObject(value);
jobject.Add("$typeid", "dynamo.data:location-1.0.0");
jobject.WriteTo(writer);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException("Unnecessary because CanRead is false. The type will skip the converter.");
}
public override bool CanRead
{
get { return false; }
}
public override bool CanConvert(Type objectType)
{
return typeof(DynamoUnits.Location) == objectType;
}
}
#if NET6_0_OR_GREATER
[SupportedOSPlatform("windows")]
#endif
private class PNGImageConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var image = value as Bitmap;
string serializedValue;
var stream = new MemoryStream();
image?.Save(stream, ImageFormat.Png);
serializedValue = Convert.ToBase64String(stream.ToArray());
writer.WriteStartObject();
writer.WritePropertyName("$typeid");
writer.WriteValue("dynamo.graphics:png-1.0.0");
writer.WritePropertyName(ImageFormat.Png.ToString());
writer.WriteValue(serializedValue);
writer.WriteEndObject();
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
throw new NotImplementedException("Unnecessary because CanRead is false. The type will skip the converter.");
}
public override bool CanRead
{
get { return false; }
}
public override bool CanConvert(Type objectType)
{
return typeof(Bitmap).IsAssignableFrom(objectType);
}
}
#endregion
#region Remember node functions
/// <summary>
/// Helper function to determine if object can be cached or if it is null, "null" string, or empty list.
/// </summary>
/// <param name="inputObject">Object to check</param>
/// <returns></returns>
[IsVisibleInDynamoLibrary(false)]
public static bool CanObjectBeCached(object inputObject)
{
if (inputObject == null
|| (inputObject is string inputString && inputString == "null")
|| (inputObject is ArrayList inputArray && inputArray.Count == 0))
{
return false;
}
return true;
}
/// <summary>
/// Function to handle caching for the Data.Remember node
/// </summary>
/// <param name="inputObject">Object to cache</param>
/// <param name = "cachedJson" >Optional existing cache json</param >
/// <returns></returns>
[IsVisibleInDynamoLibrary(false)]
public static Dictionary<string, object> Remember([ArbitraryDimensionArrayImport] object inputObject, string cachedJson)
{
//Handle the case where the node has no inputs or the input value is null
if (!CanObjectBeCached(inputObject))
{
//If a previous cache exists, de-serialize and return
if (cachedJson != "")
{
object cachedObject = null;
try
{
cachedObject = ParseJSON(cachedJson);
}
catch(Exception ex)
{
dynamoLogger?.Log("Remember failed to deserialize with this exception: " + ex.Message);
throw new NotSupportedException(Properties.Resources.Exception_Deserialize_Unsupported_Cache);
}
return new Dictionary<string, object>
{
{ ">", cachedObject },
{ "Cache", cachedJson }
};
}
//Else pass through the empty inputs and cacheJson
return new Dictionary<string, object>
{
{ ">", inputObject },
{ "Cache", cachedJson }
};
}
//Try to serialize the inputs and return
string newCachedJson;
try
{
newCachedJson = StringifyJSON(inputObject);
}
catch(Exception ex)
{
dynamoLogger?.Log("Remember failed to serialize with this exception: " + ex.Message);
throw new NotSupportedException(string.Format(Properties.Resources.Exception_Serialize_Unsupported_Type, inputObject.GetType().FullName));
}
return new Dictionary<string, object>
{
{ ">", inputObject },
{ "Cache", newCachedJson }
};
}
internal static DynamoLogger dynamoLogger = ExecutionEvents.ActiveSession?.GetParameterValue(ParameterKeys.Logger) as DynamoLogger;
#endregion
#region Input Output Node
public class DataNodeDynamoType
{
public Type Type { get; private set; }
public string Name { get; private set; }
public int Level { get; private set; }
public bool IsLastChild { get; private set; }
public DataNodeDynamoType(Type type, string name = null)
{
Type = type;
Name = name ?? type.Name;
Level = 0;
IsLastChild = false;
}
public DataNodeDynamoType(Type type, int level, bool isLastChild = false, string name = null)
: this(type, name)
{
Level = level;
IsLastChild = isLastChild;
}
}
/// <summary>
/// A static list for all Dynamo supported data types
/// </summary>
/// <returns>The list containing the supported data types</returns>
public static List<DataNodeDynamoType> GetDataNodeDynamoTypeList()
{
var typeList = new List<DataNodeDynamoType>();
typeList.Add(new DataNodeDynamoType(typeof(bool)));
typeList.Add(new DataNodeDynamoType(typeof(BoundingBox)));
typeList.Add(new DataNodeDynamoType(typeof(CoordinateSystem)));
// Subtypes of Curve
var crv = new DataNodeDynamoType(typeof(Curve));
typeList.Add(crv);
typeList.Add(new DataNodeDynamoType(typeof(Arc), 1));
typeList.Add(new DataNodeDynamoType(typeof(Circle), 1));
typeList.Add(new DataNodeDynamoType(typeof(Ellipse), 1));
typeList.Add(new DataNodeDynamoType(typeof(EllipseArc), 1));
typeList.Add(new DataNodeDynamoType(typeof(Helix), 1));
typeList.Add(new DataNodeDynamoType(typeof(Line), 1));
typeList.Add(new DataNodeDynamoType(typeof(NurbsCurve), 1));
var polyCurve = new DataNodeDynamoType(typeof(PolyCurve), 1);
var polygon = new DataNodeDynamoType(typeof(Polygon), 2); // polygon is subtype of polyCurve
var rectangle = new DataNodeDynamoType(typeof(Autodesk.DesignScript.Geometry.Rectangle), 3, true); // rectangle is subtype of polygon
typeList.Add(polyCurve);
typeList.Add(polygon);
typeList.Add(rectangle);
typeList.Add(new DataNodeDynamoType(typeof(System.DateTime)));
typeList.Add(new DataNodeDynamoType(typeof(double), "Number"));
typeList.Add(new DataNodeDynamoType(typeof(long), "Integer"));
typeList.Add(new DataNodeDynamoType(typeof(Location)));
typeList.Add(new DataNodeDynamoType(typeof(Mesh)));
typeList.Add(new DataNodeDynamoType(typeof(Plane)));
typeList.Add(new DataNodeDynamoType(typeof(Autodesk.DesignScript.Geometry.Point)));
// Subtypes of Solid
var solid = new DataNodeDynamoType(typeof(Solid));
var cone = new DataNodeDynamoType(typeof(Cone), 1); // cone is subtype of solid
var cylinder = new DataNodeDynamoType(typeof(Cylinder), 2); // cylinder is subtype of cone
var cuboid = new DataNodeDynamoType(typeof(Cuboid), 1); // cuboid is subtype of solid
var sphere = new DataNodeDynamoType(typeof(Sphere), 1, true); // sphere is subtype of solid
typeList.Add(solid);
typeList.Add(cone);
typeList.Add(cylinder);
typeList.Add(cuboid);
typeList.Add(sphere);
typeList.Add(new DataNodeDynamoType(typeof(string)));
// Subtypes of Surface
var surface = new DataNodeDynamoType(typeof(Surface));
var nurbsSrf = new DataNodeDynamoType(typeof(NurbsSurface), 1); // nurbsSrf is subtype of surface
var polySrf = new DataNodeDynamoType(typeof(PolySurface), 1, true); // polySrf is subtype of surface
typeList.Add(surface);
typeList.Add(nurbsSrf);
typeList.Add(polySrf);
typeList.Add(new DataNodeDynamoType(typeof(System.TimeSpan)));
typeList.Add(new DataNodeDynamoType(typeof(UV)));
typeList.Add(new DataNodeDynamoType(typeof(Vector)));
return typeList;
}
[IsVisibleInDynamoLibrary(false)]
public static Dictionary<string, object> IsSupportedDataNodeType([ArbitraryDimensionArrayImport] object inputValue,
string typeString, bool isList, bool isAutoMode, string playerValue)
{
if (inputValue == null)
{
throw new ArgumentNullException(Properties.Resources.DefineDataNullExceptionMessage);
}
// If the playerValue is not empty, then we assume it was set by the player.
// In that case, we need to parse it to get the actual value replace the inputValue.
if (!string.IsNullOrEmpty(playerValue))
{
try
{
inputValue = ParseJSON(playerValue);
}
catch (Exception ex)
{
dynamoLogger?.Log("A Player value failed to deserialize with this exception: " + ex.Message);
throw new NotSupportedException(Properties.Resources.Exception_Deserialize_Unsupported_Cache);
}
}
object result; // Tuple<IsValid: bool, UpdateList: bool, InputType: DataNodeDynamoType>
var type = GetDataNodeDynamoTypeList().First(x => x.Type.ToString().Equals(typeString));
if (isAutoMode)
{
// If running in AutoMode, then we would propagate the actual Type and List value and validate against them
// List logic
bool updateList = false;
var assertList = inputValue is ArrayList;
if (assertList != isList)
{
updateList = true;
}
// Type logic
if (type == null || !IsSupportedDataNodeDynamoType(inputValue, type.Type, assertList))
{
var valueType = assertList ? (inputValue as ArrayList)[0].GetType() : inputValue.GetType();
var inputType = GetDataNodeDynamoTypeList().FirstOrDefault(x => x.Type == valueType, null);
result = (IsValid: false, UpdateList: updateList, InputType: inputType);
}
else
{
result = (IsValid: true, UpdateList: updateList, InputType: type);
}
return new Dictionary<string, object>
{
{ ">", inputValue },
{ "Validation", result }
};
}
else
{
// If we are in 'Manual mode' then we just validate and throw as needed
var isSupportedType = IsSupportedDataNodeDynamoType(inputValue, type.Type, isList);
if (!isSupportedType)
{
throw new ArgumentException(string.Format(Properties.Resources.DefineDataUnexpectedInputExceptionMessage,
inputValue.GetType().FullName, type.Type.FullName));
}
result = (IsValid: isSupportedType, UpdateList: false, InputType: type);
return new Dictionary<string, object>
{
{ ">", inputValue },
{ "Validation", result }
};
}
}
/// <summary>
/// Function to validate input type against supported Dynamo input types
/// </summary>
/// <param name="inputValue">The incoming data to validate</param>
/// <param name="type">The input type provided by the user. It has to match the inputValue type</param>
/// <param name="isList">The value of this boolean decides if the input is a single object or a list</param>
/// <returns></returns>
[IsVisibleInDynamoLibrary(false)]
public static bool IsSupportedDataNodeDynamoType([ArbitraryDimensionArrayImport] object inputValue, Type type, bool isList)
{
if (inputValue == null || type == null)
{
return false;
}
if (!isList)
{
if (inputValue is ArrayList) return false;
return IsItemOfType(inputValue, type);
}
else
{
if (!(inputValue is ArrayList arrayList)) return false;
foreach (var item in arrayList)
{
if (!IsItemOfType(item, type))
{
return false;
}
}
return true;
}
}
/// <summary>
/// This method checks if an item is of a required Dynamo DataType
/// 'IsInstanceOfType' recursively checks for upward inheritance
/// </summary>
/// <param name="item">The item to check the data type for</param>
/// <param name="dataType">The DataType to check against</param>
/// <returns>A true or false result based on the check validation</returns>
private static bool IsItemOfType(object item, Type dataType)
{
if (dataType.IsInstanceOfType(item)) return true;
return false;
}
#endregion
}
}