diff --git a/LibreMetaverse.Rendering.Meshmerizer/MeshmerizerR.cs b/LibreMetaverse.Rendering.Meshmerizer/MeshmerizerR.cs index 12ae9505..e846239d 100644 --- a/LibreMetaverse.Rendering.Meshmerizer/MeshmerizerR.cs +++ b/LibreMetaverse.Rendering.Meshmerizer/MeshmerizerR.cs @@ -411,9 +411,9 @@ namespace OpenMetaverse.Rendering string[] decreasingLOD = { "high_lod", "medium_lod", "low_lod", "lowest_lod" }; foreach (string partName in decreasingLOD) { - if (meshParts.ContainsKey(partName)) + if (meshParts.TryGetValue(partName, out var part)) { - meshBytes = meshParts[partName]; + meshBytes = part; break; } } @@ -447,9 +447,8 @@ namespace OpenMetaverse.Rendering OSDMap meshParts = UnpackMesh(meshData); if (meshParts != null) { - if (meshParts.ContainsKey(partName)) + if (meshParts.TryGetValue(partName, out var meshBytes)) { - byte[] meshBytes = meshParts[partName]; if (meshBytes != null) { ret = MeshSubMeshAsFacetedMesh(prim, meshBytes); @@ -633,18 +632,18 @@ namespace OpenMetaverse.Rendering // Normals byte[] norBytes = null; - if (subMeshMap.ContainsKey("Normal")) + if (subMeshMap.TryGetValue("Normal", out var normal)) { - norBytes = subMeshMap["Normal"]; + norBytes = normal; } // UV texture map Vector2 texPosMax = Vector2.Zero; Vector2 texPosMin = Vector2.Zero; byte[] texBytes = null; - if (subMeshMap.ContainsKey("TexCoord0")) + if (subMeshMap.TryGetValue("TexCoord0", out var texCoord0)) { - texBytes = subMeshMap["TexCoord0"]; + texBytes = texCoord0; texPosMax = ((OSDMap)subMeshMap["TexCoord0Domain"])["Max"]; texPosMin = ((OSDMap)subMeshMap["TexCoord0Domain"])["Min"]; } diff --git a/LibreMetaverse.Rendering.Simple/SimpleRenderer.cs b/LibreMetaverse.Rendering.Simple/SimpleRenderer.cs index 134de88b..0205c51f 100644 --- a/LibreMetaverse.Rendering.Simple/SimpleRenderer.cs +++ b/LibreMetaverse.Rendering.Simple/SimpleRenderer.cs @@ -38,12 +38,14 @@ namespace OpenMetaverse.Rendering Path path = GeneratePath(); Profile profile = GenerateProfile(); - SimpleMesh mesh = new SimpleMesh(); - mesh.Prim = prim; - mesh.Path = path; - mesh.Profile = profile; - mesh.Vertices = GenerateVertices(); - mesh.Indices = GenerateIndices(); + SimpleMesh mesh = new SimpleMesh + { + Prim = prim, + Path = path, + Profile = profile, + Vertices = GenerateVertices(), + Indices = GenerateIndices() + }; return mesh; } diff --git a/LibreMetaverse.Types/ExpiringCache.cs b/LibreMetaverse.Types/ExpiringCache.cs index 81030247..e828a057 100644 --- a/LibreMetaverse.Types/ExpiringCache.cs +++ b/LibreMetaverse.Types/ExpiringCache.cs @@ -214,9 +214,8 @@ namespace OpenMetaverse throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); try { - if (timedStorageIndex.ContainsKey(key)) + if (timedStorageIndex.TryGetValue(key, out var tkey)) { - var tkey = timedStorageIndex[key]; var o = timedStorage[tkey]; timedStorage.Remove(tkey); tkey.Accessed(); @@ -260,9 +259,8 @@ namespace OpenMetaverse throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms"); try { - if (timedStorageIndex.ContainsKey(key)) + if (timedStorageIndex.TryGetValue(key, out var tkey)) { - var tkey = timedStorageIndex[key]; o = timedStorage[tkey]; timedStorage.Remove(tkey); tkey.Accessed(); diff --git a/LibreMetaverse.Voice.Vivox/VoiceControl.cs b/LibreMetaverse.Voice.Vivox/VoiceControl.cs index 268fad8b..9b60a03c 100644 --- a/LibreMetaverse.Voice.Vivox/VoiceControl.cs +++ b/LibreMetaverse.Voice.Vivox/VoiceControl.cs @@ -570,8 +570,8 @@ namespace LibreMetaverse.Voice.Vivox /// Creates the session context if it does not exist. VoiceSession FindSession(string sessionHandle, bool make) { - if (_sessions.ContainsKey(sessionHandle)) - return _sessions[sessionHandle]; + if (_sessions.TryGetValue(sessionHandle, out var session)) + return session; if (!make) return null; @@ -895,10 +895,9 @@ namespace LibreMetaverse.Voice.Vivox _regionName = pMap["region_name"].AsString(); ReportConnectionState(ConnectionState.RegionCapAvailable); - if (pMap.ContainsKey("voice_credentials")) + if (pMap.TryGetValue("voice_credentials", out var credential)) { - var cred = - pMap["voice_credentials"] as OSDMap; + var cred = credential as OSDMap; if (cred.ContainsKey("channel_uri")) _spatialUri = cred["channel_uri"].AsString(); diff --git a/LibreMetaverse.Voice.Vivox/VoiceSession.cs b/LibreMetaverse.Voice.Vivox/VoiceSession.cs index 874eec34..b3607f45 100644 --- a/LibreMetaverse.Voice.Vivox/VoiceSession.cs +++ b/LibreMetaverse.Voice.Vivox/VoiceSession.cs @@ -138,7 +138,7 @@ namespace LibreMetaverse.Voice.Vivox /// private VoiceParticipant FindParticipant(string puri) { - return _knownParticipants.ContainsKey(puri) ? _knownParticipants[puri] : null; + return _knownParticipants.TryGetValue(puri, out var participant) ? participant : null; } public void Set3DPosition(VoicePosition speakerPosition, VoicePosition listenerPosition) diff --git a/LibreMetaverse/Assets/Archiving/AssetsArchiver.cs b/LibreMetaverse/Assets/Archiving/AssetsArchiver.cs index 9eff2d4f..4d513268 100644 --- a/LibreMetaverse/Assets/Archiving/AssetsArchiver.cs +++ b/LibreMetaverse/Assets/Archiving/AssetsArchiver.cs @@ -85,9 +85,9 @@ namespace OpenMetaverse.Assets string extension = string.Empty; - if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(asset.AssetType)) + if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.TryGetValue(asset.AssetType, out var value)) { - extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[asset.AssetType]; + extension = value; } xtw.WriteElementString("filename", uuid + extension); @@ -123,7 +123,7 @@ namespace OpenMetaverse.Assets string extension = string.Empty; - if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(asset.AssetType)) + if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.TryGetValue(asset.AssetType, out var value)) { extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[asset.AssetType]; } diff --git a/LibreMetaverse/Assets/Archiving/OarFile.cs b/LibreMetaverse/Assets/Archiving/OarFile.cs index 64e0496a..dd5f80ee 100644 --- a/LibreMetaverse/Assets/Archiving/OarFile.cs +++ b/LibreMetaverse/Assets/Archiving/OarFile.cs @@ -123,9 +123,8 @@ namespace OpenMetaverse.Assets UUID uuid; UUID.TryParse(filename.Remove(filename.Length - extension.Length), out uuid); - if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension)) + if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.TryGetValue(extension, out var assetType)) { - AssetType assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension]; Asset asset = null; switch (assetType) @@ -586,8 +585,8 @@ namespace OpenMetaverse.Assets return; } - if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(assetType)) - extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[assetType]; + if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.TryGetValue(assetType, out var value)) + extension = value; File.WriteAllBytes(Path.Combine(assetsPath, texture + extension), assetTexture.AssetData); remainingTextures.Remove(assetTexture.AssetID); @@ -608,8 +607,8 @@ namespace OpenMetaverse.Assets return; } - if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(assetType)) - extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[assetType]; + if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.TryGetValue(assetType, out var value)) + extension = value; File.WriteAllBytes(Path.Combine(assetsPath, texture + extension), asset.AssetData); remainingTextures.Remove(asset.AssetID); @@ -637,8 +636,8 @@ namespace OpenMetaverse.Assets { string extension = string.Empty; - if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(assetType)) - extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[assetType]; + if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.TryGetValue(assetType, out var value)) + extension = value; if (asset == null) { diff --git a/LibreMetaverse/Assets/AssetTypes/AssetPrim.cs b/LibreMetaverse/Assets/AssetTypes/AssetPrim.cs index efefc9c2..050b12ec 100644 --- a/LibreMetaverse/Assets/AssetTypes/AssetPrim.cs +++ b/LibreMetaverse/Assets/AssetTypes/AssetPrim.cs @@ -796,9 +796,9 @@ namespace OpenMetaverse.Assets { Serial = map["serial"].AsInteger(); - if (map.ContainsKey("items")) + if (map.TryGetValue("items", out var value)) { - OSDArray array = (OSDArray)map["items"]; + OSDArray array = (OSDArray)value; Items = new ItemBlock[array.Count]; for (int i = 0; i < array.Count; i++) diff --git a/LibreMetaverse/GroupManager.cs b/LibreMetaverse/GroupManager.cs index 74649d1e..fd8beedb 100644 --- a/LibreMetaverse/GroupManager.cs +++ b/LibreMetaverse/GroupManager.cs @@ -1974,9 +1974,9 @@ namespace OpenMetaverse OnlineStatus = member["last_login"], Powers = defaultPowers }; - if (member.ContainsKey("powers")) + if (member.TryGetValue("powers", out var power)) { - groupMember.Powers = (GroupPowers)(ulong)member["powers"]; + groupMember.Powers = (GroupPowers)(ulong)power; } groupMember.Title = titles[(int)member["title"]]; diff --git a/LibreMetaverse/ImportExport/ColladalLoader.cs b/LibreMetaverse/ImportExport/ColladalLoader.cs index 10d552fd..530cffe2 100644 --- a/LibreMetaverse/ImportExport/ColladalLoader.cs +++ b/LibreMetaverse/ImportExport/ColladalLoader.cs @@ -300,14 +300,14 @@ namespace OpenMetaverse.ImportExport foreach (var effect in tmpEffects) { - if (matEffect.ContainsKey(effect.ID)) + if (matEffect.TryGetValue(effect.ID, out var effectId)) { - effect.ID = matEffect[effect.ID]; + effect.ID = effectId; if (!string.IsNullOrEmpty(effect.Texture)) { - if (imgMap.ContainsKey(effect.Texture)) + if (imgMap.TryGetValue(effect.Texture, out var effectTexture)) { - effect.Texture = imgMap[effect.Texture]; + effect.Texture = effectTexture; } } Materials.Add(effect); @@ -630,9 +630,9 @@ namespace OpenMetaverse.ImportExport ModelFace face = new ModelFace {MaterialID = list.material}; if (face.MaterialID != null) { - if (MatSymTarget.ContainsKey(list.material)) + if (MatSymTarget.TryGetValue(list.material, out var value)) { - ModelMaterial mat = Materials.Find(m => m.ID == MatSymTarget[list.material]); + ModelMaterial mat = Materials.Find(m => m.ID == value); if (mat != null) { face.Material = mat; diff --git a/LibreMetaverse/ImportExport/Model.cs b/LibreMetaverse/ImportExport/Model.cs index ad82469f..d203156a 100644 --- a/LibreMetaverse/ImportExport/Model.cs +++ b/LibreMetaverse/ImportExport/Model.cs @@ -47,15 +47,15 @@ namespace OpenMetaverse.ImportExport public string MaterialID = string.Empty; public ModelMaterial Material = new ModelMaterial(); - Dictionary LookUp = new Dictionary(); + private readonly Dictionary LookUp = new Dictionary(); public void AddVertex(Vertex v) { int index; - if (LookUp.ContainsKey(v)) + if (LookUp.TryGetValue(v, out var value)) { - index = LookUp[v]; + index = value; } else { diff --git a/LibreMetaverse/ImportExport/ModelUploader.cs b/LibreMetaverse/ImportExport/ModelUploader.cs index c144f292..4c7c6771 100644 --- a/LibreMetaverse/ImportExport/ModelUploader.cs +++ b/LibreMetaverse/ImportExport/ModelUploader.cs @@ -103,9 +103,9 @@ namespace OpenMetaverse.ImportExport if (face.Material.TextureData != null) { int index; - if (ImgIndex.ContainsKey(face.Material.Texture)) + if (ImgIndex.TryGetValue(face.Material.Texture, out var value)) { - index = ImgIndex[face.Material.Texture]; + index = value; } else { diff --git a/LibreMetaverse/InventoryBase.cs b/LibreMetaverse/InventoryBase.cs index 186862c1..2eaa1b9b 100644 --- a/LibreMetaverse/InventoryBase.cs +++ b/LibreMetaverse/InventoryBase.cs @@ -336,9 +336,9 @@ namespace OpenMetaverse { Permissions = Permissions.FromOSD(permissions); } - if (data.ContainsKey("sale_info")) + if (data.TryGetValue("sale_info", out var saleInfo)) { - OSDMap sale = (OSDMap)data["sale_info"]; + OSDMap sale = (OSDMap)saleInfo; SalePrice = sale["sale_price"].AsInteger(); SaleType = (SaleType)sale["sale_type"].AsInteger(); } @@ -388,13 +388,13 @@ namespace OpenMetaverse InventoryType = type; } } - if (data.ContainsKey("flags")) + if (data.TryGetValue("flags", out var flags)) { - Flags = data["flags"]; + Flags = flags; } - if (data.ContainsKey("created_at")) + if (data.TryGetValue("created_at", out var createdAt)) { - CreationDate = Utils.UnixTimeToDateTime(data["created_at"]); + CreationDate = Utils.UnixTimeToDateTime(createdAt); } } @@ -847,14 +847,14 @@ namespace OpenMetaverse public static InventoryFolder FromOSD(OSD data) { var res = (OSDMap)data; - UUID folderId = res.ContainsKey("category_id") ? res["category_id"] : res["folder_id"]; + UUID folderId = res.TryGetValue("category_id", out var catId) ? catId : res["folder_id"]; var folder = new InventoryFolder(folderId) { UUID = res["category_id"].AsUUID(), Version = res.ContainsKey("version") ? res["version"].AsInteger() : VERSION_UNKNOWN, ParentUUID = res["parent_id"].AsUUID(), DescendentCount = res["descendents"], - OwnerID = res.ContainsKey("agent_id") ? res["agent_id"] : res["owner_id"], + OwnerID = res.TryGetValue("agent_id", out var agentId) ? agentId : res["owner_id"], PreferredType = (FolderType)(sbyte)res["type_default"].AsUInteger(), Name = res["name"] }; diff --git a/LibreMetaverse/InventoryManager.cs b/LibreMetaverse/InventoryManager.cs index 86ad564b..5ca1b353 100644 --- a/LibreMetaverse/InventoryManager.cs +++ b/LibreMetaverse/InventoryManager.cs @@ -3795,9 +3795,9 @@ namespace OpenMetaverse { List compileErrors = null; - if (contents.ContainsKey("errors")) + if (contents.TryGetValue("errors", out var content)) { - var errors = (OSDArray)contents["errors"]; + var errors = (OSDArray)content; compileErrors = new List(errors.Count); compileErrors.AddRange(errors.Select(t => t.AsString())); } diff --git a/LibreMetaverse/Messages/LindenMessages.cs b/LibreMetaverse/Messages/LindenMessages.cs index 4ba0046e..755a2ba6 100644 --- a/LibreMetaverse/Messages/LindenMessages.cs +++ b/LibreMetaverse/Messages/LindenMessages.cs @@ -564,9 +564,9 @@ namespace OpenMetaverse.Messages.Linden // DataExtended is optional, will not exist of parcel contains zero prims OSDArray dataExtendedArray; - if (map.ContainsKey("DataExtended")) + if (map.TryGetValue("DataExtended", out var value)) { - dataExtendedArray = (OSDArray)map["DataExtended"]; + dataExtendedArray = (OSDArray)value; } else { @@ -910,9 +910,9 @@ namespace OpenMetaverse.Messages.Linden AnyAVSounds = parcelDataMap["AnyAVSounds"].AsBoolean(); GroupAVSounds = parcelDataMap["GroupAVSounds"].AsBoolean(); - if (map.ContainsKey("MediaData")) // temporary, OpenSim doesn't send this block + if (map.TryGetValue("MediaData", out var value)) // temporary, OpenSim doesn't send this block { - OSDMap mediaDataMap = (OSDMap)((OSDArray)map["MediaData"])[0]; + OSDMap mediaDataMap = (OSDMap)((OSDArray)value)[0]; MediaDesc = mediaDataMap["MediaDesc"].AsString(); MediaHeight = mediaDataMap["MediaHeight"].AsInteger(); MediaWidth = mediaDataMap["MediaWidth"].AsInteger(); @@ -1680,9 +1680,9 @@ namespace OpenMetaverse.Messages.Linden // If request for current groups came very close to login // the Linden sim will not include the NewGroupData block, but // it will instead set all ListInProfile fields to false - if (map.ContainsKey("NewGroupData")) + if (map.TryGetValue("NewGroupData", out var value)) { - OSDArray newGroupArray = (OSDArray)map["NewGroupData"]; + OSDArray newGroupArray = (OSDArray)value; NewGroupDataBlock = new NewGroupData[newGroupArray.Count]; @@ -3521,9 +3521,9 @@ namespace OpenMetaverse.Messages.Linden block.Transition = infoMap["transition"].AsString(); - if (agentPermsMap.ContainsKey("mutes")) + if (agentPermsMap.TryGetValue("mutes", out var mutes)) { - OSDMap mutesMap = (OSDMap)agentPermsMap["mutes"]; + OSDMap mutesMap = (OSDMap)mutes; block.MuteText = mutesMap["text"].AsBoolean(); block.MuteVoice = mutesMap["voice"].AsBoolean(); } @@ -5282,9 +5282,9 @@ namespace OpenMetaverse.Messages.Linden { base.Deserialize(map); } - else if (map.ContainsKey("parcels")) + else if (map.TryGetValue("parcels", out var parcels)) { - OSDArray parcelsOSD = (OSDArray)map["parcels"]; + OSDArray parcelsOSD = (OSDArray)parcels; Parcels = new ParcelResourcesDetail[parcelsOSD.Count]; for (int i = 0; i < parcelsOSD.Count; i++) diff --git a/LibreMetaverse/ObjectManager.cs b/LibreMetaverse/ObjectManager.cs index 8f226dda..a509e139 100644 --- a/LibreMetaverse/ObjectManager.cs +++ b/LibreMetaverse/ObjectManager.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -3707,7 +3708,7 @@ namespace OpenMetaverse float seconds = interval / 1000f; // Iterate through all simulators - Simulator[] sims = Client.Network.Simulators.ToArray(); + var sims = Client.Network.Simulators.ToImmutableArray(); foreach (var sim in sims) { float adjSeconds = seconds * sim.Stats.Dilation; diff --git a/LibreMetaverse/ObservableDictionary.cs b/LibreMetaverse/ObservableDictionary.cs index 723527bc..2f1ea303 100644 --- a/LibreMetaverse/ObservableDictionary.cs +++ b/LibreMetaverse/ObservableDictionary.cs @@ -112,7 +112,7 @@ namespace OpenMetaverse private void FireChangeEvent(DictionaryEventAction action, DictionaryEntry entry) { - if(Delegates.ContainsKey(action)) + if(Delegates.TryGetValue(action, out var value)) { foreach(DictionaryChangeCallback handler in Delegates[action]) { diff --git a/LibreMetaverse/Primitives/ParticleSystem.cs b/LibreMetaverse/Primitives/ParticleSystem.cs index 0df8549c..1353ebe9 100644 --- a/LibreMetaverse/Primitives/ParticleSystem.cs +++ b/LibreMetaverse/Primitives/ParticleSystem.cs @@ -491,9 +491,9 @@ namespace OpenMetaverse partSys.PartEndScaleX = es.X; partSys.PartEndScaleY = es.Y; - if (map.ContainsKey("part_start_glow")) + if (map.TryGetValue("part_start_glow", out var startGlow)) { - partSys.PartStartGlow = map["part_start_glow"]; + partSys.PartStartGlow = startGlow; partSys.PartEndGlow = map["part_end_glow"]; } diff --git a/LibreMetaverse/ProtocolManager.cs b/LibreMetaverse/ProtocolManager.cs index 26cadd24..c6e5f2d1 100644 --- a/LibreMetaverse/ProtocolManager.cs +++ b/LibreMetaverse/ProtocolManager.cs @@ -648,9 +648,9 @@ namespace OpenMetaverse private int KeywordPosition(string keyword) { - if (KeywordPositions.ContainsKey(keyword)) + if (KeywordPositions.TryGetValue(keyword, out var position)) { - return KeywordPositions[keyword]; + return position; } int hash = 0; diff --git a/LibreMetaverse/Rendering/Rendering.cs b/LibreMetaverse/Rendering/Rendering.cs index 74c96766..b149131c 100644 --- a/LibreMetaverse/Rendering/Rendering.cs +++ b/LibreMetaverse/Rendering/Rendering.cs @@ -334,18 +334,18 @@ namespace OpenMetaverse.Rendering // Normals byte[] norBytes = null; - if (subMeshMap.ContainsKey("Normal")) + if (subMeshMap.TryGetValue("Normal", out var normal)) { - norBytes = subMeshMap["Normal"]; + norBytes = normal; } // UV texture map Vector2 texPosMax = Vector2.Zero; Vector2 texPosMin = Vector2.Zero; byte[] texBytes = null; - if (subMeshMap.ContainsKey("TexCoord0")) + if (subMeshMap.TryGetValue("TexCoord0", out var texCoord0)) { - texBytes = subMeshMap["TexCoord0"]; + texBytes = texCoord0; texPosMax = ((OSDMap)subMeshMap["TexCoord0Domain"])["Max"]; texPosMin = ((OSDMap)subMeshMap["TexCoord0Domain"])["Min"]; } diff --git a/LibreMetaverse/UserReport.cs b/LibreMetaverse/UserReport.cs index 17fc8aab..82f43536 100644 --- a/LibreMetaverse/UserReport.cs +++ b/LibreMetaverse/UserReport.cs @@ -103,9 +103,9 @@ namespace LibreMetaverse } OSD result = OSDParser.Deserialize(data); - if (result is OSDMap respMap && respMap.ContainsKey("categories")) + if (result is OSDMap respMap && respMap.TryGetValue("categories", out var value)) { - if (respMap["categories"] is OSDArray categories) + if (value is OSDArray categories) { reportCategories = categories.Cast().ToDictionary( row => row["description_localized"].AsString(), diff --git a/LibreMetaverse/UtilizationStatistics.cs b/LibreMetaverse/UtilizationStatistics.cs index 90fd3e2f..a10bfbaf 100644 --- a/LibreMetaverse/UtilizationStatistics.cs +++ b/LibreMetaverse/UtilizationStatistics.cs @@ -59,9 +59,9 @@ namespace OpenMetaverse.Stats { Stat stat; - if (m_StatsCollection.ContainsKey(key)) + if (m_StatsCollection.TryGetValue(key, out var value)) { - stat = m_StatsCollection[key]; + stat = value; } else { diff --git a/PrimMesher/ObjMesh.cs b/PrimMesher/ObjMesh.cs index f38d2204..4ec95498 100644 --- a/PrimMesher/ObjMesh.cs +++ b/PrimMesher/ObjMesh.cs @@ -146,7 +146,7 @@ namespace LibreMetaverse.PrimMesher var hash = hashInts(positionIndex, texCoordIndex, normalIndex); - if (viewerVertexLookup.ContainsKey(hash)) + if (viewerVertexLookup.TryGetValue(hash, out var value)) { vertIndices[vertexIndex - 1] = viewerVertexLookup[hash]; } diff --git a/Programs/GridProxy/GridProxy.cs b/Programs/GridProxy/GridProxy.cs index 649febff..5a8a08bf 100644 --- a/Programs/GridProxy/GridProxy.cs +++ b/Programs/GridProxy/GridProxy.cs @@ -552,14 +552,14 @@ namespace GridProxy headers[key.ToLower()] = val; } while (line != ""); - if (headers.ContainsKey("content-length")) + if (headers.TryGetValue("content-length", out var length)) { - contentLength = Convert.ToInt32(headers["content-length"]); + contentLength = Convert.ToInt32(length); } - if (headers.ContainsKey("content-type")) + if (headers.TryGetValue("content-type", out var type)) { - contentType = headers["content-type"]; + contentType = type; } // read the HTTP body into a buffer @@ -1322,10 +1322,10 @@ namespace GridProxy bool needsCopy = true; var length = simFacingSocket.EndReceiveFrom(ar, ref remoteEndPoint); - if (proxyHandlers.ContainsKey(remoteEndPoint)) + if (proxyHandlers.TryGetValue(remoteEndPoint, out var handler)) { // find the proxy responsible for forwarding this packet - SimProxy simProxy = (SimProxy)proxyHandlers[remoteEndPoint]; + SimProxy simProxy = handler; // interpret the packet according to the SL protocol int end = length - 1; @@ -1344,7 +1344,7 @@ namespace GridProxy simProxy.incomingSequence = packet.Header.Sequence; // check the packet for addresses that need proxying - if (incomingCheckers.ContainsKey(packet.Type)) + if (incomingCheckers.TryGetValue(packet.Type, out var checker)) { /* if (needsZero) { length = Helpers.ZeroDecode(packet.Header.Data, length, zeroBuffer); @@ -1352,7 +1352,7 @@ namespace GridProxy needsZero = false; } */ - Packet newPacket = ((AddressChecker)incomingCheckers[packet.Type])(packet); + Packet newPacket = ((AddressChecker)checker)(packet); SwapPacket(packet, newPacket); packet = newPacket; needsCopy = false; @@ -1496,9 +1496,9 @@ namespace GridProxy // ProxySim: return the proxy for the specified sim, creating it if it doesn't exist private IPEndPoint ProxySim(IPEndPoint simEndPoint) { - if (proxyEndPoints.ContainsKey(simEndPoint)) + if (proxyEndPoints.TryGetValue(simEndPoint, out var point)) // return the existing proxy - return (IPEndPoint)proxyEndPoints[simEndPoint]; + return point; else { // return a new proxy @@ -1683,7 +1683,7 @@ namespace GridProxy outgoingSequence = packet.Header.Sequence; // check the packet for addresses that need proxying - if (proxy.outgoingCheckers.ContainsKey(packet.Type)) + if (proxy.outgoingCheckers.TryGetValue(packet.Type, out var checker)) { /* if (packet.Header.Zerocoded) { length = Helpers.ZeroDecode(packet.Header.Data, length, zeroBuffer); @@ -1691,7 +1691,7 @@ namespace GridProxy needsZero = false; } */ - Packet newPacket = ((AddressChecker)proxy.outgoingCheckers[packet.Type])(packet); + Packet newPacket = ((AddressChecker)checker)(packet); SwapPacket(packet, newPacket); packet = newPacket; needsCopy = false; diff --git a/Programs/GridProxy/Plugins/Analyst.cs b/Programs/GridProxy/Plugins/Analyst.cs index bbfef403..29aac00c 100644 --- a/Programs/GridProxy/Plugins/Analyst.cs +++ b/Programs/GridProxy/Plugins/Analyst.cs @@ -206,7 +206,7 @@ public class Analyst : ProxyPlugin string[] valueArray = new string[words.Length - 4]; Array.Copy(words, 4, valueArray, 0, words.Length - 4); - string valueString = String.Join(" ", valueArray); + string valueString = string.Join(" ", valueArray); object value; try { @@ -218,11 +218,8 @@ public class Analyst : ProxyPlugin return; } - Dictionary fields; - if (modifiedPackets.ContainsKey(pType)) - fields = (Dictionary)modifiedPackets[pType]; - else - fields = new Dictionary(); + var fields = modifiedPackets.TryGetValue(pType, out var packet) + ? packet : new Dictionary(); fields[new BlockField(words[2], words[3])] = value; modifiedPackets[pType] = fields; @@ -626,11 +623,10 @@ public class Analyst : ProxyPlugin // Modify: modify a packet private Packet Modify(Packet packet, IPEndPoint endPoint, Direction direction) { - if (modifiedPackets.ContainsKey(packet.Type)) + if (modifiedPackets.TryGetValue(packet.Type, out var changes)) { try { - Dictionary changes = modifiedPackets[packet.Type]; Type packetClass = packet.GetType(); foreach (KeyValuePair change in changes) diff --git a/Programs/GridProxy/Plugins/ClientAO.cs b/Programs/GridProxy/Plugins/ClientAO.cs index ae5f5013..8bdfb777 100644 --- a/Programs/GridProxy/Plugins/ClientAO.cs +++ b/Programs/GridProxy/Plugins/ClientAO.cs @@ -652,9 +652,9 @@ public class ClientAO : ProxyPlugin //SayToUser("anim: " + animname); if (animname != "") { - if (currentFolderItems.ContainsKey(animname)) + if (currentFolderItems.TryGetValue(animname, out var item)) { - UUID over = currentFolderItems[animname].AssetUUID; + UUID over = item.AssetUUID; UUID orig = wetikonanims[((i + 1) / 2) - 1]; //put it in overrides animuid2name[over] = animname; diff --git a/Programs/examples/TestClient/Commands/Agent/PlayAnimationCommand.cs b/Programs/examples/TestClient/Commands/Agent/PlayAnimationCommand.cs index aa211298..0c3483bd 100644 --- a/Programs/examples/TestClient/Commands/Agent/PlayAnimationCommand.cs +++ b/Programs/examples/TestClient/Commands/Agent/PlayAnimationCommand.cs @@ -48,9 +48,9 @@ namespace OpenMetaverse.TestClient else if (arg.ToLower().Equals("show")) { Client.Self.SignaledAnimations.ForEach(delegate(KeyValuePair kvp) { - if (m_BuiltInAnimations.ContainsKey(kvp.Key)) + if (m_BuiltInAnimations.TryGetValue(kvp.Key, out var animation)) { - result.AppendFormat("The {0} System Animation is being played, sequence is {1}", m_BuiltInAnimations[kvp.Key], kvp.Value); + result.AppendFormat("The {0} System Animation is being played, sequence is {1}", animation, kvp.Value); } else { diff --git a/Programs/examples/TestClient/Commands/Prims/ImportCommand.cs b/Programs/examples/TestClient/Commands/Prims/ImportCommand.cs index e03496df..282f6213 100644 --- a/Programs/examples/TestClient/Commands/Prims/ImportCommand.cs +++ b/Programs/examples/TestClient/Commands/Prims/ImportCommand.cs @@ -72,8 +72,8 @@ namespace OpenMetaverse.TestClient { if (prim.ParentID == 0) { - if (linksets.ContainsKey(prim.LocalID)) - linksets[prim.LocalID].RootPrim = prim; + if (linksets.TryGetValue(prim.LocalID, out var linkset)) + linkset.RootPrim = prim; else linksets[prim.LocalID] = new Linkset(prim); }