Sunday, 15 August 2010

C# Creating properties at runtime -


I am I have a sound folder in which to do I have some sound files, at runtime, a class (SoundFileNames.c ) With their full path and file name. Preferably I would like it if I file "MySound.wav" said Will folder being so, I like this index can do: SoundFileNames.MySound, which will produce the C: .. \ MySound.wav. I do not know if this is the best solution, or even possible how can it be achieved? Any help is very appriciated

Thanks for visiting

A simple SoundPathProvider you desired behavior here You can use it as a template.

  using the system; Using System.IO; Using System.Linq; Nominator sound recorder {public class SoundPathProvider {private readonly string _sourcePath; Public SoundPathProvider (string source) {_sourcePath = sourcePath; } Public string GetSoundPath (string sound name) {var files = Directory.EnumerateFiles (_sourcepath); Var targetSound = files.FirstOrDefault (x = & gt; x.Split ('\\'). Last () == soundname); If (targetSound! = Null) Back Path Combine (_sourcepath, soundName); Throw a new exception (String.Format ( "sound" found in the {0} 'not' {1} ' ", soundName, _sourcePath)); }}}  

and the template unit test that can help you develop the functionality.

  using the system; Use of Microsoft Visual Studio Test Tools Unitatistics; Namespace SoundProvider {[TestClass] public class SoundPathProviderTests {[ExpectedException (typeof (Exceptions))] [TestMethod] public void SoundPathProvider_GetNonExistentSoundPath_ThrowsException () {var provider = new SoundPathProvider ( "C: \\ Temp \\ SoundProviderSource"); Var Sound Path = Provider GateSoundPath ("nonexistent sound."); } [TestMethod] public void SoundPathProvider_GetExistingSoundPath_ThrowsException () {var provider = new SoundPathProvider ( "C: \\ Temp \\ SoundProviderSource"); Var soundPath = provider.GetSoundPath ("SampleSound.wav"); Assert.AreEqual ("C: \\ Temp \\ SoundProviderSource \\ SampleSound.wav", soundPath); }}}  

No comments:

Post a Comment