System.IO.Ports
Contains internal path helpers that are shared between many projects.
Returns true if the given character is a valid drive letter
Adds the extended path prefix (\\?\) if not already a device path, IF the path is not relative,
AND the path is more than 259 characters. (> MAX_PATH + null). This will also insert the extended
prefix if the path ends with a period or a space. Trailing periods and spaces are normally eaten
away from paths during normalization, but if we see such a path at this point it should be
normalized and has retained the final characters. (Typically from one of the *Info classes)
Adds the extended path prefix (\\?\) if not relative or already a device path.
Returns true if the path uses any of the DOS device path syntaxes. ("\\.\", "\\?\", or "\??\")
Returns true if the path is a device UNC (\\?\UNC\, \\.\UNC\)
Returns true if the path uses the canonical form of extended syntax ("\\?\" or "\??\"). If the
path matches exactly (cannot use alternate directory separators) Windows will skip normalization
and path length checks.
Gets the length of the root of the path (drive, share, etc.).
Returns true if the path specified is relative to the current drive or working directory.
Returns false if the path is fixed to a specific drive or UNC path. This method does no
validation of the path (URIs will be returned as relative as a result).
Handles paths that use the alternate directory separator. It is a frequent mistake to
assume that rooted paths (Path.IsPathRooted) are not relative. This isn't the case.
"C:a" is drive relative- meaning that it will be resolved against the current directory
for C: (rooted, but relative). "C:\a" is rooted and not relative (the current directory
will not be used to modify the path).
True if the given character is a directory separator.
Normalize separators in the given path. Converts forward slashes into back slashes and compresses slash runs, keeping initial 2 if present.
Also trims initial whitespace in front of "rooted" paths (see PathStartSkip).
This effectively replicates the behavior of the legacy NormalizePath when it was called with fullCheck=false and expandShortpaths=false.
The current NormalizePath gets directory separator normalization from Win32's GetFullPathName(), which will resolve relative paths and as
such can't be used here (and is overkill for our uses).
Like the current NormalizePath this will not try and analyze periods/spaces within directory segments.
The only callers that used to use Path.Normalize(fullCheck=false) were Path.GetDirectoryName() and Path.GetPathRoot(). Both usages do
not need trimming of trailing whitespace here.
GetPathRoot() could technically skip normalizing separators after the second segment- consider as a future optimization.
For legacy .NET Framework behavior with ExpandShortPaths:
- It has no impact on GetPathRoot() so doesn't need consideration.
- It could impact GetDirectoryName(), but only if the path isn't relative (C:\ or \\Server\Share).
In the case of GetDirectoryName() the ExpandShortPaths behavior was undocumented and provided inconsistent results if the path was
fixed/relative. For example: "C:\PROGRA~1\A.TXT" would return "C:\Program Files" while ".\PROGRA~1\A.TXT" would return ".\PROGRA~1". If you
ultimately call GetFullPath() this doesn't matter, but if you don't or have any intermediate string handling could easily be tripped up by
this undocumented behavior.
We won't match this old behavior because:
1. It was undocumented
2. It was costly (extremely so if it actually contained '~')
3. Doesn't play nice with string logic
4. Isn't a cross-plat friendly concept/behavior
Returns true if the path is effectively empty for the current OS.
For unix, this is empty or null. For Windows, this is empty, null, or
just spaces ((char)32).
Provides static methods for converting from Win32 errors codes to exceptions, HRESULTS and error messages.
Converts, resetting it, the last Win32 error into a corresponding object, optionally
including the specified path in the error message.
Converts the specified Win32 error into a corresponding object, optionally
including the specified path in the error message.
If not already an HRESULT, returns an HRESULT for the specified Win32 error code.
Returns a Win32 error code for the specified HRESULT if it came from FACILITY_WIN32
If not, returns the HRESULT unchanged
Get a pinnable reference to the builder.
Does not ensure there is a null char after
This overload is pattern matched in the C# 7.3+ compiler so you can omit
the explicit method call, and write eg "fixed (char* c = builder)"
Get a pinnable reference to the builder.
Ensures that the builder has a null char after
Returns the underlying storage of the builder.
Returns a span around the contents of the builder.
Ensures that the builder has a null char after
Resize the internal buffer either by doubling current buffer size or
by adding to
whichever is greater.
Number of chars requested beyond current position.
Unable to read beyond the end of the stream.
The BaseStream is only available when the port is open.
The PortName cannot be empty.
The port is closed.
The port is already open.
'{0}' cannot be set while the port is open.
The maximum baud rate for the device is {0}.
The port is in the break state and cannot be written to.
The write timed out.
RtsEnable cannot be accessed if Handshake is set to RequestToSend or RequestToSendXOnXOff.
SerialPort does not support encoding '{0}'. The supported encodings include ASCIIEncoding, UTF8Encoding, UnicodeEncoding, UTF32Encoding, and most single or double byte code pages. For a complete list please see the documentation.
The given port name ({0}) does not resolve to a valid serial port.
The given port name is invalid. It may be a valid port, but not a serial port.
Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
Argument must be between {0} and {1}.
Enum value was out of legal range.
Non-negative number required.
Positive number required.
The timeout must be greater than or equal to -1.
The timeout must be either a positive number or -1.
Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In multithreaded applications, a stream must be accessed in a thread-safe way, such as a thread-safe wrapper returned by TextReader's or TextWriter's ...
The I/O operation has been aborted because of either a thread exit or an application request.
Stream does not support seeking.
Cannot access a closed stream.
Argument {0} cannot be null or zero-length.
IAsyncResult object did not come from the corresponding async method on this type.
EndRead can only be called once for each asynchronous operation.
EndWrite can only be called once for each asynchronous operation.
Access to the port '{0}' is denied.
System.IO.Ports is currently only supported on Windows.
Enumeration of serial port names is not supported on the current platform.
The specified file name or path is too long, or a component of the specified path is too long.
Could not find a part of the path.
Could not find a part of the path '{0}'.
Unable to find the specified file.
Could not find file '{0}'.
Access to the path is denied.
Access to the path '{0}' is denied.
The path '{0}' is too long, or a component of the specified path is too long.
The process cannot access the file '{0}' because it is being used by another process.
The process cannot access the file because it is being used by another process.
Specified file length was too large for the file system.
The file '{0}' already exists.
Cannot create '{0}' because a file or directory with the same name already exists.
Attribute used to indicate a source generator should create a function for marshalling
arguments instead of relying on the runtime to generate an equivalent marshalling function at run-time.
This attribute is meaningless if the source generator associated with it is not enabled.
The current built-in source generator only supports C# and only supplies an implementation when
applied to static, partial, non-generic methods.
Initializes a new instance of the .
Name of the library containing the import.
Gets the name of the library containing the import.
Gets or sets the name of the entry point to be called.
Gets or sets how to marshal string arguments to the method.
If this field is set to a value other than ,
must not be specified.
Gets or sets the used to control how string arguments to the method are marshalled.
If this field is specified, must not be specified
or must be set to .
Gets or sets whether the callee sets an error (SetLastError on Windows or errno
on other platforms) before returning from the attributed method.
Specifies how strings should be marshalled for generated p/invokes
Indicates the user is suppling a specific marshaller in .
Use the platform-provided UTF-8 marshaller.
Use the platform-provided UTF-16 marshaller.
Returns a string message for the specified Win32 error code.
WARNING: This method does not implicitly handle long paths. Use CreateFile.
Blittable version of Windows BOOL type. It is convenient in situations where
manual marshalling is required, or to avoid overhead of regular bool marshalling.
Some Windows APIs return arbitrary integer values although the return type is defined
as BOOL. It is best to never compare BOOL to TRUE. Always use bResult != BOOL.FALSE
or bResult == BOOL.FALSE .