Пример #1
0
 /// <summary>
 /// Gets the locale name with the specified index.
 /// </summary>
 /// <param name="index">Zero-based index of the locale name.</param>
 /// <returns>The locale name.</returns>
 internal string GetLocaleName(uint index)
 {
     if (_localizedStrings == null)
     {
         return(String.Empty);
     }
     else
     {
         uint localeNameLength = this.GetLocaleNameLength(index);
         Debug.Assert(localeNameLength >= 0 && localeNameLength < UInt32.MaxValue);
         IntPtr localeNameWCHAR = Marshal.AllocCoTaskMem(2 * ((int)localeNameLength + 1));
         try
         {
             _localizedStrings.GetLocaleName(index, localeNameWCHAR, localeNameLength + 1);
             string localeName = Marshal.PtrToStringUni(localeNameWCHAR);
             return(localeName);
         }
         finally
         {
             Marshal.FreeCoTaskMem(localeNameWCHAR);
         }
     }
 }
Пример #2
0
        public static IReadOnlyList <DWriteLocalizedString> GetNames(this IDWriteLocalizedStrings strings)
        {
            if (strings == null)
            {
                throw new ArgumentNullException(nameof(strings));
            }

            var list = new List <DWriteLocalizedString>((int)strings.GetCount());

            for (var i = 0; i < list.Capacity; i++)
            {
                var name = new DWriteLocalizedString();
                strings.GetLocaleNameLength((uint)i, out var len).ThrowOnError();
                name.LocaleName = new string('\0', (int)len);
                strings.GetLocaleName((uint)i, name.LocaleName, len + 1);

                strings.GetStringLength((uint)i, out len).ThrowOnError();
                name.String = new string('\0', (int)len);
                strings.GetString((uint)i, name.String, len + 1);

                list.Add(name);
            }
            return(list);
        }