浏览代码

code coalesce

vpenades 2 年之前
父节点
当前提交
dfba11737b

+ 1 - 1
build/SharpGLTF.CodeGen/CodeGen/EmitCSharp.cs

@@ -248,7 +248,7 @@ namespace SharpGLTF.CodeGen
 
         private Object _GetConstantRuntimeValue(SchemaType type, Object value)
         {
-            if (value == null) throw new ArgumentNullException();
+            if (value == null) throw new ArgumentNullException(nameof(value));
 
             switch (type)
             {

+ 5 - 5
examples/SharpGLTF.Runtime.MonoGame/LoaderContext.BasicEffect.cs

@@ -181,12 +181,12 @@ namespace SharpGLTF.Runtime
 
         private Texture2D UseDiffuseTexture(GLTFMATERIAL srcMaterial)
         {
-            var diffuse = srcMaterial.FindChannel("Diffuse");
-
-            if (diffuse == null) diffuse = srcMaterial.FindChannel("BaseColor");
-            if (diffuse == null) return null;
+            var diffuse = srcMaterial.FindChannel("Diffuse")
+                ?? srcMaterial.FindChannel("BaseColor");
 
-            return UseTexture(diffuse, null);
+            return diffuse == null
+                ? null
+                : UseTexture(diffuse, null);
         }
 
         #endregion

+ 1 - 1
examples/SharpGLTF.Runtime.MonoGame/LoaderContext.cs

@@ -102,7 +102,7 @@ namespace SharpGLTF.Runtime
 
         private void _WriteMeshPrimitive(MeshPrimitiveReader srcPrim, SRCMATERIAL srcMaterial)
         {
-            if (srcMaterial == null) srcMaterial = GetDefaultMaterial();
+            srcMaterial ??= GetDefaultMaterial();
 
             var effect = _MatFactory.GetMaterial(srcMaterial, srcPrim.IsSkinned);
 

+ 2 - 2
examples/SharpGLTF.Runtime.MonoGame/MeshPrimitiveReader.cs

@@ -305,14 +305,14 @@ namespace SharpGLTF.Runtime
 
         void VertexNormalsFactory.IMeshPrimitive.SetVertexNormal(int idx, XYZ normal)
         {
-            if (_Normals == null) _Normals = new XYZ[VertexCount];
+            _Normals ??= new XYZ[VertexCount];
             if (!(_Normals is XYZ[])) return; // if it's not a plain array, it's a glTF source, so we prevent writing existing normals.            
             _Normals[idx] = normal;
         }
 
         void VertexTangentsFactory.IMeshPrimitive.SetVertexTangent(int idx, XYZW tangent)
         {
-            if (_Tangents == null) _Tangents = new XYZW[VertexCount];
+            _Tangents ??= new XYZW[VertexCount];
             if (!(_Tangents is XYZW[])) return; // if it's not a plain array, it's a glTF source, so we prevent writing existing tangents.            
             _Tangents[idx] = tangent;
         }        

+ 1 - 1
examples/SharpGLTF.Runtime.MonoGame/SharpGLTF.Runtime.MonoGame.csproj

@@ -3,7 +3,7 @@
   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
     <RootNamespace>SharpGLTF.Runtime</RootNamespace>
-    <LangVersion>7.3</LangVersion>
+    <LangVersion>8</LangVersion>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
   </PropertyGroup>
 

+ 2 - 4
src/SharpGLTF.Core/Schema2/gltf.Accessors.cs

@@ -120,10 +120,8 @@ namespace SharpGLTF.Schema2
         internal KeyValuePair<IntegerArray, MemoryAccessor>? _GetSparseMemoryAccessor()
         {
             return this._sparse == null
-                ?
-                (KeyValuePair<IntegerArray, MemoryAccessor>?)null
-                :
-                this._sparse._CreateMemoryAccessors(this);
+                ? (KeyValuePair<IntegerArray, MemoryAccessor>?)null
+                : this._sparse._CreateMemoryAccessors(this);
         }
 
         protected override IEnumerable<ExtraProperties> GetLogicalChildren()

+ 1 - 1
src/SharpGLTF.Core/Schema2/gltf.Buffer.cs

@@ -173,7 +173,7 @@ namespace SharpGLTF.Schema2
         /// <returns>A <see cref="Buffer"/> instance.</returns>
         public Buffer UseBuffer(Byte[] content)
         {
-            Guard.IsFalse(content == null, nameof(content));
+            Guard.NotNull(content, nameof(content));
 
             foreach (var b in this.LogicalBuffers)
             {