SIL.CoreImpl.PalasoWritingSystemManager.GetOrSet C# (CSharp) Method

GetOrSet() public method

Gets the specified writing system if it exists, otherwise it creates a writing system using the specified identifier and sets it.
public GetOrSet ( string identifier, IWritingSystem &ws ) : bool
identifier string The identifier.
ws IWritingSystem The writing system.
return bool
		public bool GetOrSet(string identifier, out IWritingSystem ws)
		{
			lock (m_syncRoot)
			{
				if (TryGet(identifier, out ws))
					return true;
				bool foundExisting;
				ws = Set(identifier, out foundExisting);
				return foundExisting;
			}
		}

Usage Example

        public void GetOrSetWorksRepeatedlyOnIdNeedingModification()
        {
            var            wsManager = new PalasoWritingSystemManager();
            IWritingSystem ws;

            Assert.That(wsManager.GetOrSet("x-kal", out ws), Is.False);
            Assert.That(ws.Id, Is.EqualTo("qaa-x-kal"));
            IWritingSystem ws2;

            Assert.That(wsManager.GetOrSet("x-kal", out ws2), Is.True);
            Assert.That(ws2, Is.EqualTo(ws));

            // By the way it should work the same for one where it does not have to modify the ID.
            Assert.That(wsManager.GetOrSet("fr", out ws), Is.False);
            Assert.That(wsManager.GetOrSet("fr", out ws), Is.True);
        }
All Usage Examples Of SIL.CoreImpl.PalasoWritingSystemManager::GetOrSet