Skip to content

Commit 029a53d

Browse files
author
Brian Macintosh
committed
Use .NET 4.0-compatible syntax
1 parent d6f2b2b commit 029a53d

File tree

7 files changed

+58
-22
lines changed

7 files changed

+58
-22
lines changed

UnityProjectBrowser/MainForm.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ void OnDatabaseCleared(object sender, ObjectDatabaseEventArgs e)
144144
/// </summary>
145145
private TreeNode GetTreeNode(string uniqueId, bool createPlaceholder)
146146
{
147-
if (m_treeNodes.TryGetValue(uniqueId, out TreeNode existingNode))
147+
TreeNode existingNode;
148+
if (m_treeNodes.TryGetValue(uniqueId, out existingNode))
148149
{
149150
return existingNode;
150151
}
@@ -263,7 +264,8 @@ private void AddObject(ProjectObject obj)
263264
}
264265

265266
// see if there is an existing node of any kind for this object
266-
m_treeNodes.TryGetValue(uniqueId, out TreeNode node);
267+
TreeNode node;
268+
m_treeNodes.TryGetValue(uniqueId, out node);
267269

268270
if (existingFolderNode != null) // there is a Windows folder node
269271
{
@@ -333,7 +335,8 @@ private void AddObject(ProjectObject obj)
333335
/// </summary>
334336
private void RemoveObject(ProjectObject obj)
335337
{
336-
if (m_treeNodes.TryGetValue(obj.UniqueId, out TreeNode existingNode))
338+
TreeNode existingNode;
339+
if (m_treeNodes.TryGetValue(obj.UniqueId, out existingNode))
337340
{
338341
existingNode.Remove();
339342
m_treeNodes.Remove(obj.UniqueId);
@@ -360,7 +363,8 @@ private void OnAllObjectsTreeViewSelectionChanged(object sender, TreeViewEventAr
360363
selectedItem.BackColor = SystemColors.ActiveBorder;
361364
selectedItem.ForeColor = SystemColors.HighlightText;
362365

363-
if (ObjectDatabase.TryGetObject(selectedItem.Name, out ProjectObject selectedObject))
366+
ProjectObject selectedObject;
367+
if (ObjectDatabase.TryGetObject(selectedItem.Name, out selectedObject))
364368
{
365369
// load the object into the inspect panel
366370
UnityObjectKey unityObjectKey;
@@ -388,7 +392,8 @@ private void ReloadRelationships()
388392
{
389393
TreeNode selectedItem = allObjectsTreeView.SelectedNode;
390394

391-
if (!ObjectDatabase.TryGetObject(selectedItem.Name, out ProjectObject selectedObject))
395+
ProjectObject selectedObject;
396+
if (!ObjectDatabase.TryGetObject(selectedItem.Name, out selectedObject))
392397
{
393398
relationshipsListView.Items.Clear();
394399
return;
@@ -450,7 +455,8 @@ private void ReloadRelationships()
450455
/// </summary>
451456
public void SetAllObjectsSelection(string uniqueId)
452457
{
453-
if (m_treeNodes.TryGetValue(uniqueId, out TreeNode selectedItemTreeNode))
458+
TreeNode selectedItemTreeNode;
459+
if (m_treeNodes.TryGetValue(uniqueId, out selectedItemTreeNode))
454460
{
455461
allObjectsTreeView.SelectedNode = selectedItemTreeNode;
456462
}
@@ -540,8 +546,9 @@ private void showInAllObjectsViewToolStripMenuItem_Click(object sender, EventArg
540546
/// </summary>
541547
private void openInExplorerToolStripMenuItem_Click(object sender, EventArgs e)
542548
{
549+
ProjectObject projectObject;
543550
if (allObjectsTreeView.SelectedNode != null
544-
&& ObjectDatabase.TryGetObject(allObjectsTreeView.SelectedNode.Name, out ProjectObject projectObject))
551+
&& ObjectDatabase.TryGetObject(allObjectsTreeView.SelectedNode.Name, out projectObject))
545552
{
546553
string objectPath = projectObject.GetFilePath();
547554
if (!string.IsNullOrEmpty(objectPath))
@@ -556,8 +563,9 @@ private void openInExplorerToolStripMenuItem_Click(object sender, EventArgs e)
556563
/// </summary>
557564
private void editToolStripMenuItem_Click(object sender, EventArgs e)
558565
{
566+
ProjectObject projectObject;
559567
if (allObjectsTreeView.SelectedNode != null
560-
&& ObjectDatabase.TryGetObject(allObjectsTreeView.SelectedNode.Name, out ProjectObject projectObject))
568+
&& ObjectDatabase.TryGetObject(allObjectsTreeView.SelectedNode.Name, out projectObject))
561569
{
562570
string objectPath = projectObject.GetFilePath();
563571
if (!string.IsNullOrEmpty(objectPath))
@@ -626,7 +634,8 @@ private void RebuildAllObjectsParents()
626634
{
627635
foreach (TreeNode node in m_treeNodes.Values)
628636
{
629-
if (ObjectDatabase.TryGetObject(node.Name, out ProjectObject nodeObject))
637+
ProjectObject nodeObject;
638+
if (ObjectDatabase.TryGetObject(node.Name, out nodeObject))
630639
{
631640
AddObject(nodeObject);
632641
}

UnityProjectBrowser/Parsers/UnityMetaParser.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public override void ParseFile(string absolutePath)
3131
{
3232
if (key.EndsWith("Importer", StringComparison.OrdinalIgnoreCase))
3333
{
34-
if (UnityClassIds.TryGetClassIdByImporterName(key, out int classId))
34+
int classId;
35+
if (UnityClassIds.TryGetClassIdByImporterName(key, out classId))
3536
{
3637
defaultFileId = classId * 100000;
3738
break;
@@ -69,7 +70,8 @@ public override void ParseFile(string absolutePath)
6970
if (rootNode.Children.TryGetValue("TextureImporter", out textureImporterNode))
7071
{
7172
YamlMappingNode textureImporterMappingNode = (YamlMappingNode)textureImporterNode;
72-
if (textureImporterMappingNode.Children.TryGetValue("fileIDToRecycleName", out YamlNode fileIDToRecycleNameNode))
73+
YamlNode fileIDToRecycleNameNode;
74+
if (textureImporterMappingNode.Children.TryGetValue("fileIDToRecycleName", out fileIDToRecycleNameNode))
7375
{
7476
YamlMappingNode fileIDToRecycleNameMappingNode = (YamlMappingNode)fileIDToRecycleNameNode;
7577
foreach (var kv in fileIDToRecycleNameMappingNode.Children)
@@ -82,7 +84,8 @@ public override void ParseFile(string absolutePath)
8284
}
8385
}
8486

85-
if (textureImporterMappingNode.Children.TryGetValue("spriteMode", out YamlNode spriteModeNode))
87+
YamlNode spriteModeNode;
88+
if (textureImporterMappingNode.Children.TryGetValue("spriteMode", out spriteModeNode))
8689
{
8790
YamlScalarNode spriteModeScalarNode = (YamlScalarNode)spriteModeNode;
8891
if (spriteModeScalarNode.Value == "1")

UnityProjectBrowser/Project/ObjectDatabase.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,17 @@ public static List<ProjectObject> AllObjects
116116
/// </summary>
117117
public static void AddPlaceholderObject(string uniqueId, ProjectObject obj)
118118
{
119+
if (obj == null)
120+
{
121+
throw new ArgumentNullException("obj");
122+
}
123+
119124
s_objectsLock.EnterWriteLock();
120125
try
121126
{
122127
if (!s_objects.ContainsKey(uniqueId))
123128
{
124-
s_objects.Add(uniqueId, obj ?? throw new ArgumentNullException("obj"));
129+
s_objects.Add(uniqueId, obj);
125130
}
126131
}
127132
finally
@@ -138,10 +143,15 @@ public static void AddObject(string uniqueId, ProjectObject obj)
138143
{
139144
Thread.Sleep(0);
140145

146+
if (obj == null)
147+
{
148+
throw new ArgumentNullException("obj");
149+
}
150+
141151
s_objectsLock.EnterWriteLock();
142152
try
143153
{
144-
s_objects[uniqueId] = obj ?? throw new ArgumentNullException("obj");
154+
s_objects[uniqueId] = obj;
145155
}
146156
finally
147157
{
@@ -189,7 +199,8 @@ public static void AddRelationship(string ownerUniqueId, ObjectRelationship rela
189199
s_relationshipsLock.EnterWriteLock();
190200
try
191201
{
192-
if (!s_relationships.TryGetValue(ownerUniqueId, out List<ObjectRelationship> relationships))
202+
List<ObjectRelationship> relationships;
203+
if (!s_relationships.TryGetValue(ownerUniqueId, out relationships))
193204
{
194205
relationships = new List<ObjectRelationship>();
195206
s_relationships.Add(ownerUniqueId, relationships);
@@ -210,7 +221,8 @@ public static void AddInverseRelationship(string ownerUniqueId, ObjectRelationsh
210221
s_inverseRelationshipsLock.EnterWriteLock();
211222
try
212223
{
213-
if (!s_inverseRelationships.TryGetValue(ownerUniqueId, out List<ObjectRelationship> relationships))
224+
List<ObjectRelationship> relationships;
225+
if (!s_inverseRelationships.TryGetValue(ownerUniqueId, out relationships))
214226
{
215227
relationships = new List<ObjectRelationship>();
216228
s_inverseRelationships.Add(ownerUniqueId, relationships);
@@ -276,7 +288,8 @@ public static string GetFolderUniqueId(string absolutePath)
276288
s_folderMappingsLock.EnterReadLock();
277289
try
278290
{
279-
if (s_folderMappings.TryGetValue(absolutePath, out string uniqueId))
291+
string uniqueId;
292+
if (s_folderMappings.TryGetValue(absolutePath, out uniqueId))
280293
{
281294
return uniqueId;
282295
}

UnityProjectBrowser/Structure/ObjectRelationship.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ public struct ObjectRelationship : IEquatable<ObjectRelationship>
2222

2323
public ObjectRelationship(string targetObjectId, string relationshipType)
2424
{
25-
TargetObjectId = targetObjectId ?? throw new ArgumentNullException("targetObjectId");
26-
RelationshipType = relationshipType ?? throw new ArgumentNullException("relationshipType");
25+
if (targetObjectId == null)
26+
{
27+
throw new ArgumentNullException("targetObjectId");
28+
}
29+
if (relationshipType == null)
30+
{
31+
throw new ArgumentNullException("relationshipType");
32+
}
33+
TargetObjectId = targetObjectId;
34+
RelationshipType = relationshipType;
2735
}
2836

2937
public override bool Equals(object obj)

UnityProjectBrowser/Structure/Unity/UnityComponent.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ public override string GetIconKey()
118118

119119
public override string ToString()
120120
{
121-
if (ObjectDatabase.TryGetObject(m_scriptKey, out ProjectObject scriptObject))
121+
ProjectObject scriptObject;
122+
if (ObjectDatabase.TryGetObject(m_scriptKey, out scriptObject))
122123
{
123124
return scriptObject.ToString();
124125
}

UnityProjectBrowser/Structure/Unity/UnityDefaultAsset.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public override string GetIconKey()
2424

2525
public override string ToString()
2626
{
27-
if (ObjectDatabase.TryGetObject(DocumentId, out ProjectObject documentAsset))
27+
ProjectObject documentAsset;
28+
if (ObjectDatabase.TryGetObject(DocumentId, out documentAsset))
2829
{
2930
return documentAsset.ToString();
3031
}

UnityProjectBrowser/Structure/UnityObject.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public override string GetParentId()
4848
/// </summary>
4949
public override string GetFilePath()
5050
{
51-
if (ObjectDatabase.TryGetObject(DocumentId, out ProjectObject document))
51+
ProjectObject document;
52+
if (ObjectDatabase.TryGetObject(DocumentId, out document))
5253
{
5354
return document.GetFilePath();
5455
}

0 commit comments

Comments
 (0)