Browse Source

Code cleanup

vpenades 2 years ago
parent
commit
c5db79039f

+ 4 - 4
build/SharpGLTF.CodeGen/CodeGen/CodeEmitUtils.cs

@@ -71,13 +71,13 @@ namespace SharpGLTF.CodeGen
         {
         {
             while(true)
             while(true)
             {
             {
-                var indices = _FindDescriptionKeyword(description);
-                if (indices.start < 0) return description;
+                var (start, len) = _FindDescriptionKeyword(description);
+                if (start < 0) return description;
 
 
-                var block = description.Substring(indices.start , indices.len);
+                var block = description.Substring(start , len);
                 var name = block.Substring(2, block.Length - 4);
                 var name = block.Substring(2, block.Length - 4);
 
 
-                description = description.Replace(block, $"<see cref=\"{name}\"/>");
+                description = description.Replace(block, $"<see cref=\"{name}\"/>", StringComparison.Ordinal);
             }
             }
         }
         }
 
 

+ 11 - 13
build/SharpGLTF.CodeGen/CodeGen/EmitCSharp.cs

@@ -93,9 +93,9 @@ namespace SharpGLTF.CodeGen
 
 
         #region setup & declaration
         #region setup & declaration
 
 
-        private string _SanitizeName(string name)
+        private static string _SanitizeName(string name)
         {
         {
-            return name.Replace(" ", "");
+            return name.Replace(" ", string.Empty, StringComparison.OrdinalIgnoreCase);
         }
         }
 
 
         private _RuntimeType _UseType(SchemaType stype)
         private _RuntimeType _UseType(SchemaType stype)
@@ -149,7 +149,7 @@ namespace SharpGLTF.CodeGen
 
 
             foreach(var f in type.Fields)
             foreach(var f in type.Fields)
             {
             {
-                var runtimeName = _SanitizeName(f.PersistentName).Replace("@","at");
+                var runtimeName = _SanitizeName(f.PersistentName).Replace("@","at", StringComparison.Ordinal);
 
 
                 SetFieldName(f, $"_{runtimeName}");
                 SetFieldName(f, $"_{runtimeName}");
                 SetPropertyName(f, runtimeName);
                 SetPropertyName(f, runtimeName);
@@ -202,7 +202,7 @@ namespace SharpGLTF.CodeGen
                         var container = extra?.CollectionContainer;
                         var container = extra?.CollectionContainer;
                         if (string.IsNullOrWhiteSpace(container)) container = _DefaultCollectionContainer;
                         if (string.IsNullOrWhiteSpace(container)) container = _DefaultCollectionContainer;
 
 
-                        return container.Replace("TItem", _GetRuntimeName(arrayType.ItemType));
+                        return container.Replace("TItem", _GetRuntimeName(arrayType.ItemType), StringComparison.Ordinal);
                     }
                     }
 
 
                 case DictionaryType dictType:
                 case DictionaryType dictType:
@@ -252,10 +252,10 @@ namespace SharpGLTF.CodeGen
 
 
             switch (type)
             switch (type)
             {
             {
-                case StringType stype: if (value is string) return value;
+                case StringType _:
 
 
-                    return value == null
-                        ? null
+                    return value is string
+                        ? value
                         : Convert.ChangeType(value, typeof(string), System.Globalization.CultureInfo.InvariantCulture);
                         : Convert.ChangeType(value, typeof(string), System.Globalization.CultureInfo.InvariantCulture);
 
 
                 case BlittableType btype:
                 case BlittableType btype:
@@ -266,15 +266,13 @@ namespace SharpGLTF.CodeGen
 
 
                             var str = value as string;
                             var str = value as string;
 
 
-                            if (str.ToLowerInvariant() == "false") return false;
-                            if (str.ToLowerInvariant() == "true") return true;
+                            if (str.ToUpperInvariant() == "FALSE") return false;
+                            if (str.ToUpperInvariant() == "TRUE") return true;
                             throw new NotImplementedException();
                             throw new NotImplementedException();
                         }
                         }
 
 
-                        if (value is string) return value;
-
-                        return value == null
-                            ? null
+                        return value is string
+                            ? value
                             : Convert.ChangeType(value, btype.DataType.AsType(), System.Globalization.CultureInfo.InvariantCulture);
                             : Convert.ChangeType(value, btype.DataType.AsType(), System.Globalization.CultureInfo.InvariantCulture);
                     }
                     }
 
 

+ 3 - 1
build/SharpGLTF.CodeGen/SchemaReflection/SchemaTypes.cs

@@ -335,7 +335,7 @@ namespace SharpGLTF.SchemaReflection
 
 
             public bool Equals(FieldInfo x, FieldInfo y) { return Compare(x,y) == 0; }
             public bool Equals(FieldInfo x, FieldInfo y) { return Compare(x,y) == 0; }
 
 
-            public int GetHashCode(FieldInfo obj) { return obj._PersistentName.GetHashCode(); }
+            public int GetHashCode(FieldInfo obj) { return obj._PersistentName.GetHashCode(StringComparison.Ordinal); }
         }
         }
 
 
         private static readonly _Comparer _DefaultComparer = new _Comparer();
         private static readonly _Comparer _DefaultComparer = new _Comparer();
@@ -420,7 +420,9 @@ namespace SharpGLTF.SchemaReflection
 
 
         private readonly SchemaType _ReferencedType;
         private readonly SchemaType _ReferencedType;
 
 
+        #pragma warning disable CA1065 // Do not raise exceptions in unexpected locations
         public override string PersistentName => throw new NotImplementedException();
         public override string PersistentName => throw new NotImplementedException();
+        #pragma warning restore CA1065 // Do not raise exceptions in unexpected locations
 
 
         #endregion
         #endregion
     }
     }