1 #region Copyright notice and license 2 // Protocol Buffers - Google's data interchange format 3 // Copyright 2008 Google Inc. All rights reserved. 4 // 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file or at 7 // https://developers.google.com/open-source/licenses/bsd 8 #endregion 9 10 using System.Collections.Generic; 11 using System.Collections.ObjectModel; 12 13 namespace Google.Protobuf.Reflection 14 { 15 /// <summary> 16 /// Internal class containing utility methods when working with descriptors. 17 /// </summary> 18 internal static class DescriptorUtil 19 { 20 /// <summary> 21 /// Equivalent to Func[TInput, int, TOutput] but usable in .NET 2.0. Only used to convert 22 /// arrays. 23 /// </summary> IndexedConverter(TInput element, int index)24 internal delegate TOutput IndexedConverter<TInput, TOutput>(TInput element, int index); 25 26 /// <summary> 27 /// Converts the given array into a read-only list, applying the specified conversion to 28 /// each input element. 29 /// </summary> ConvertAndMakeReadOnly(IList<TInput> input, IndexedConverter<TInput, TOutput> converter)30 internal static IList<TOutput> ConvertAndMakeReadOnly<TInput, TOutput> 31 (IList<TInput> input, IndexedConverter<TInput, TOutput> converter) 32 { 33 TOutput[] array = new TOutput[input.Count]; 34 for (int i = 0; i < array.Length; i++) 35 { 36 array[i] = converter(input[i], i); 37 } 38 return new ReadOnlyCollection<TOutput>(array); 39 } 40 } 41 }