Search Results for

    Show / Hide Table of Contents

    Class Codepage

    Represents a code page in the sense of a System.Text.Encoding object, using a mechanism that allows basic manipulations on a system where support for the code page may not be installed.

    Normally the Codepage object is constructed from an Encoding object, but for persistence it can be constructed from a string.

    If the code page is supported by the local machine you can use the Encoding property to retrieve the corresponding .NET encoding object. If you access this property for a code page that is not supported on this machine this will result in a UnsupportedCodepageException.

    Using this mechanism as opposed to directly using the Encoding class means that we can still work with files for which a code page is not supported on a certain machine (at least as long as no code page conversion operations are needed). This may be a common use case when a file is converted on one system and then edited on another.

    Use the IsValid and IsSupported properties to determine if the codepage has been set and if it is supported on this system.

    Inheritance
    System.Object
    Codepage
    Implements
    System.ICloneable
    Inherited Members
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: Sdl.Core.Globalization
    Assembly: Sdl.Core.Globalization.dll
    Syntax
    public class Codepage : ICloneable

    Constructors

    Codepage()

    Constructs an invalid code page object (does not set a code page name).

    Declaration
    public Codepage()

    Codepage(Codepage)

    Create a deep clone of the other object.

    Declaration
    protected Codepage(Codepage other)
    Parameters
    Type Name Description
    Codepage other

    Codepage to clone.

    Codepage(String)

    Construction from a code page name.

    See the Name property for information about what is considered to be a valid code page name.

    Declaration
    public Codepage(string codepageName)
    Parameters
    Type Name Description
    System.String codepageName

    A valid codepage name.

    Remarks

    This constructor is typically used only in (de-)serialization. If possible a new code page object should be created from an existing encoding object instead.

    Codepage(Encoding)

    Initializes a new instance of the Codepage class from an existing .NET Encoding.

    Declaration
    public Codepage(Encoding encoding)
    Parameters
    Type Name Description
    System.Text.Encoding encoding

    An existing .NET Encoding.

    Properties

    Encoding

    Returns the .NET Encoding that corresponds to this code page.

    If the code page is null this property returns null.

    If the encoding is not supported on this system an UnsupportedCodepageException is thrown.

    Declaration
    public Encoding Encoding { get; set; }
    Property Value
    Type Description
    System.Text.Encoding
    Exceptions
    Type Condition
    UnsupportedCodepageException

    IsSupported

    True if the code page is supported on this system.

    Declaration
    public bool IsSupported { get; }
    Property Value
    Type Description
    System.Boolean

    IsValid

    True if a code page name has been set.

    Declaration
    public bool IsValid { get; }
    Property Value
    Type Description
    System.Boolean
    Remarks

    This does not mean that the actual code page string is valid. Since the code page name could represent a code page that is not supported on this particular system there is no safe way we can determine if the name is a valid encoding name or not. Thus anything else than null or an empty string for a name must be considered a "valid" code page name. To test if a codepage is supported on this system, use the IsSupported property.

    Name

    The IANA preferred name of the code page, e.g. windows-1252 or iso-8859-1.

    Declaration
    public string Name { get; set; }
    Property Value
    Type Description
    System.String
    Remarks

    This corresponds to the Encoding.WebName property for code pages supported by the machine.

    Methods

    Clone()

    Return a deep clone of this object.

    Declaration
    public object Clone()
    Returns
    Type Description
    System.Object

    A deep clone of this object.

    Equals(Object)

    Case-sensitive comparison on whether the code page names are the same.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    System.Object obj

    Object to test equality against.

    Returns
    Type Description
    System.Boolean

    true if the code page names are the same.

    Overrides
    System.Object.Equals(System.Object)

    GetHashCode()

    Hash code based on the code page name, or 0 if none.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    System.Int32

    Hash code based on the code page name, or 0 if none.

    Overrides
    System.Object.GetHashCode()

    ToString()

    The code page name.

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String

    The code page name.

    Overrides
    System.Object.ToString()

    Implements

    System.ICloneable

    On this page

    • Constructors
      • Codepage()
      • Codepage(Codepage)
      • Codepage(String)
      • Codepage(Encoding)
    • Properties
      • Encoding
      • IsSupported
      • IsValid
      • Name
    • Methods
      • Clone()
      • Equals(Object)
      • GetHashCode()
      • ToString()
    • Implements
    Back to top Generated by DocFX