| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics.CodeAnalysis; |
| | | 5 | | |
| | | 6 | | namespace System.Text |
| | | 7 | | { |
| | | 8 | | public sealed class EncodingInfo |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Construct an <see cref="EncodingInfo"/> object. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <param name="provider">The <see cref="EncodingProvider"/> object which created this <see cref="EncodingInfo" |
| | | 14 | | /// <param name="codePage">The encoding codepage</param> |
| | | 15 | | /// <param name="name">The encoding name</param> |
| | | 16 | | /// <param name="displayName">The encoding display name</param> |
| | | 17 | | /// <returns></returns> |
| | 0 | 18 | | public EncodingInfo(EncodingProvider provider, int codePage, string name, string displayName) : this(codePage, n |
| | | 19 | | { |
| | 0 | 20 | | ArgumentNullException.ThrowIfNull(provider); |
| | 0 | 21 | | ArgumentNullException.ThrowIfNull(name); |
| | 0 | 22 | | ArgumentNullException.ThrowIfNull(displayName); |
| | | 23 | | |
| | 0 | 24 | | Provider = provider; |
| | 0 | 25 | | } |
| | | 26 | | |
| | 0 | 27 | | internal EncodingInfo(int codePage, string name, string displayName) |
| | | 28 | | { |
| | 0 | 29 | | CodePage = codePage; |
| | 0 | 30 | | Name = name; |
| | 0 | 31 | | DisplayName = displayName; |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Get the encoding codepage number |
| | | 36 | | /// </summary> |
| | | 37 | | /// <value>The codepage integer number</value> |
| | 0 | 38 | | public int CodePage { get; } |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Get the encoding name |
| | | 42 | | /// </summary> |
| | | 43 | | /// <value>The encoding name string</value> |
| | 0 | 44 | | public string Name { get; } |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Get the encoding display name |
| | | 48 | | /// </summary> |
| | | 49 | | /// <value>The encoding display name string</value> |
| | 0 | 50 | | public string DisplayName { get; } |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// Get the <see cref="Encoding"/> object match the information in the <see cref="EncodingInfo"/> object |
| | | 54 | | /// </summary> |
| | | 55 | | /// <returns>The <see cref="Encoding"/> object</returns> |
| | 0 | 56 | | public Encoding GetEncoding() => Provider?.GetEncoding(CodePage) ?? Encoding.GetEncoding(CodePage); |
| | | 57 | | |
| | | 58 | | /// <summary> |
| | | 59 | | /// Compare this <see cref="EncodingInfo"/> object to other object. |
| | | 60 | | /// </summary> |
| | | 61 | | /// <param name="value">The other object to compare with this object</param> |
| | | 62 | | /// <returns>True if the value object is EncodingInfo object and has a codepage equals to this EncodingInfo obje |
| | 0 | 63 | | public override bool Equals([NotNullWhen(true)] object? value) => value is EncodingInfo that && CodePage == that |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Get a hashcode representing the current EncodingInfo object. |
| | | 67 | | /// </summary> |
| | | 68 | | /// <returns>The integer value representing the hash code of the EncodingInfo object.</returns> |
| | | 69 | | public override int GetHashCode() |
| | | 70 | | { |
| | 0 | 71 | | return CodePage; |
| | | 72 | | } |
| | | 73 | | |
| | 0 | 74 | | internal EncodingProvider? Provider { get; } |
| | | 75 | | } |
| | | 76 | | } |
| | | 77 | | |