WaveFrogger.Services.AudioService.SearchMusicAndSounds C# (CSharp) Method

SearchMusicAndSounds() private method

private SearchMusicAndSounds ( Type contentType ) : void
contentType System.Type
return void
        private void SearchMusicAndSounds(Type contentType)
        {
            // Search all fields
            FieldInfo[] fields = contentType.GetFields();
            foreach (FieldInfo field in fields)
            {
                if (field.FieldType == typeof(string))
                {
                    string fieldValue = (string)field.GetValue(null);
                    if (!string.IsNullOrEmpty(fieldValue)
                         && (Path.GetExtension(fieldValue) == ".wav" || Path.GetExtension(fieldValue) == ".mp3")
                        )
                    {
                        this.audioPaths.Add(field.Name, fieldValue);
                    }
                }
            }

            // Search child classes
            Type[] types = contentType.GetNestedTypes();
            foreach (Type type in types)
            {
                this.SearchMusicAndSounds(type);
            }
        }