MCPcopy Create free account
hub / github.com/NodeRT/NodeRT / ExternalTypesHelper

Class ExternalTypesHelper

src/NodeRTLib/ExternalTypesHelper.cs:25–157  ·  view source on GitHub ↗

a helper utility class used for fetching value types which are used by the types in the namespace but are not part of the current namespace

Source from the content-addressed store, hash-verified

23 // a helper utility class used for fetching value types which are used by the types in the namespace
24 // but are not part of the current namespace
25 class ExternalTypesHelper
26 {
27 static List<String> ExcludedExternalNamespaces = new List<string>()
28 {
29 "System",
30 "System.Collections",
31 "Platform",
32 "Windows.Foundation.Collections"
33 };
34
35 public static bool IsValueTypeNoEnumOrPrimitve(Type type)
36 {
37 return type.IsValueType && !type.IsEnum && !type.IsPrimitive && type.Namespace != "System";
38 }
39
40 public static void TestAndAddRecursive(Type type, String declaringTypeNamespace, List<Type> valueTypes, List<String> namespaces)
41 {
42 if (type.IsGenericType)
43 {
44 if (type.GetGenericArguments() != null)
45 {
46 foreach (var genericArg in type.GetGenericArguments())
47 {
48 TestAndAddRecursive(genericArg, declaringTypeNamespace, valueTypes, namespaces);
49 }
50 }
51 return;
52 }
53
54 if (IsValueTypeNoEnumOrPrimitve(type) && !valueTypes.Contains(type) &&
55 type.Namespace != "System" && type.Namespace != declaringTypeNamespace)
56 {
57 valueTypes.Add(type);
58 }
59
60 if (!IsValueTypeNoEnumOrPrimitve(type) && type.Namespace != declaringTypeNamespace)
61 {
62 if (!ExcludedExternalNamespaces.Contains(type.Namespace) && !namespaces.Contains(type.Namespace))
63 {
64 namespaces.Add(type.Namespace);
65 }
66 else if (type.Namespace == "System" && type.Name == "Uri" && !namespaces.Contains("Windows.Foundation")) // Uri is special..
67 {
68 namespaces.Add("Windows.Foundation");
69 }
70 }
71 }
72
73 public static void TestAndAddNamespaceRecursive(Type type, List<String> namespaces, String declaringTypeNamespace)
74 {
75 if (type.IsGenericType)
76 {
77 if (type.GetGenericArguments() != null)
78 {
79 foreach (var genericArg in type.GetGenericArguments())
80 {
81 TestAndAddNamespaceRecursive(genericArg, namespaces, declaringTypeNamespace);
82 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected