mirror of
https://github.com/claunia/Claunia.IO.git
synced 2025-12-16 19:24:44 +00:00
* Claunia.IO/DirectoryInfo.cs:
Created FileInfo class that cheats to inherint System.IO.DirectoryInfo * Claunia.IO/FileInfo.cs: Created FileInfo class that cheats to inherint System.IO.FileInfo * Claunia.IO/Claunia.IO.csproj: Removed skeleton class and added FileInfo and DirectoryInfo classes. * Claunia.IO/MyClass.cs: Removed skeleton empty class
This commit is contained in:
17
Claunia.IO/ChangeLog
Normal file
17
Claunia.IO/ChangeLog
Normal file
@@ -0,0 +1,17 @@
|
||||
2015-02-08 Natalia Portillo <claunia@claunia.com>
|
||||
|
||||
* DirectoryInfo.cs:
|
||||
Created FileInfo class that cheats to inherint
|
||||
System.IO.DirectoryInfo
|
||||
|
||||
* FileInfo.cs:
|
||||
Created FileInfo class that cheats to inherint
|
||||
System.IO.FileInfo
|
||||
|
||||
* Claunia.IO.csproj:
|
||||
Removed skeleton class and added FileInfo and DirectoryInfo
|
||||
classes.
|
||||
|
||||
* MyClass.cs:
|
||||
Removed skeleton empty class
|
||||
|
||||
@@ -31,8 +31,9 @@
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MyClass.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="FileInfo.cs" />
|
||||
<Compile Include="DirectoryInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
||||
268
Claunia.IO/DirectoryInfo.cs
Normal file
268
Claunia.IO/DirectoryInfo.cs
Normal file
@@ -0,0 +1,268 @@
|
||||
//
|
||||
// DirectoryInfo.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2015 © Claunia.com
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if !MOBILE
|
||||
using System.Security.AccessControl;
|
||||
#endif
|
||||
|
||||
|
||||
namespace Claunia.IO
|
||||
{
|
||||
[SerializableAttribute]
|
||||
[ComVisibleAttribute(true)]
|
||||
public sealed class DirectoryInfo : System.IO.FileSystemInfo
|
||||
{
|
||||
System.IO.DirectoryInfo _dirInfo;
|
||||
|
||||
public DirectoryInfo(String path)
|
||||
{
|
||||
_dirInfo = new System.IO.DirectoryInfo(path);
|
||||
}
|
||||
|
||||
// For manual casting
|
||||
public DirectoryInfo (System.IO.DirectoryInfo dirInfo)
|
||||
{
|
||||
_dirInfo = dirInfo;
|
||||
}
|
||||
|
||||
public override bool Exists {
|
||||
get {
|
||||
return _dirInfo.Exists;
|
||||
}
|
||||
}
|
||||
|
||||
public override string Name {
|
||||
get { return _dirInfo.Name; }
|
||||
}
|
||||
|
||||
public DirectoryInfo Parent {
|
||||
get {
|
||||
return new DirectoryInfo(_dirInfo.Parent);
|
||||
}
|
||||
}
|
||||
|
||||
public DirectoryInfo Root {
|
||||
get {
|
||||
return new DirectoryInfo(_dirInfo.Root);
|
||||
}
|
||||
}
|
||||
|
||||
public void Create ()
|
||||
{
|
||||
_dirInfo.Create();
|
||||
}
|
||||
|
||||
public DirectoryInfo CreateSubdirectory (string path)
|
||||
{
|
||||
return new DirectoryInfo(_dirInfo.CreateSubdirectory(path));
|
||||
}
|
||||
|
||||
public FileInfo [] GetFiles ()
|
||||
{
|
||||
System.IO.FileInfo[] _systemFileInfos = _dirInfo.GetFiles();
|
||||
FileInfo[] _fileInfos = new FileInfo[_systemFileInfos.Length];
|
||||
|
||||
for(int i = 0; i < _fileInfos.Length; i++)
|
||||
_fileInfos[i] = new FileInfo(_systemFileInfos[i]);
|
||||
|
||||
return _fileInfos;
|
||||
}
|
||||
|
||||
public FileInfo [] GetFiles (string searchPattern)
|
||||
{
|
||||
System.IO.FileInfo[] _systemFileInfos = _dirInfo.GetFiles(searchPattern);
|
||||
FileInfo[] _fileInfos = new FileInfo[_systemFileInfos.Length];
|
||||
|
||||
for(int i = 0; i < _fileInfos.Length; i++)
|
||||
_fileInfos[i] = new FileInfo(_systemFileInfos[i]);
|
||||
|
||||
return _fileInfos;
|
||||
}
|
||||
|
||||
public FileInfo[] GetFiles (string searchPattern, System.IO.SearchOption searchOption)
|
||||
{
|
||||
System.IO.FileInfo[] _systemFileInfos = _dirInfo.GetFiles(searchPattern, searchOption);
|
||||
FileInfo[] _fileInfos = new FileInfo[_systemFileInfos.Length];
|
||||
|
||||
for(int i = 0; i < _fileInfos.Length; i++)
|
||||
_fileInfos[i] = new FileInfo(_systemFileInfos[i]);
|
||||
|
||||
return _fileInfos;
|
||||
}
|
||||
|
||||
|
||||
public DirectoryInfo [] GetDirectories ()
|
||||
{
|
||||
System.IO.DirectoryInfo[] _systemDirInfos = _dirInfo.GetDirectories();
|
||||
DirectoryInfo[] _dirInfos = new DirectoryInfo[_systemDirInfos.Length];
|
||||
|
||||
for(int i = 0; i < _dirInfos.Length; i++)
|
||||
_dirInfos[i] = new DirectoryInfo(_systemDirInfos[i]);
|
||||
|
||||
return _dirInfos;
|
||||
}
|
||||
|
||||
public DirectoryInfo [] GetDirectories (string searchPattern)
|
||||
{
|
||||
System.IO.DirectoryInfo[] _systemDirInfos = _dirInfo.GetDirectories(searchPattern);
|
||||
DirectoryInfo[] _dirInfos = new DirectoryInfo[_systemDirInfos.Length];
|
||||
|
||||
for(int i = 0; i < _dirInfos.Length; i++)
|
||||
_dirInfos[i] = new DirectoryInfo(_systemDirInfos[i]);
|
||||
|
||||
return _dirInfos;
|
||||
}
|
||||
|
||||
public DirectoryInfo[] GetDirectories (string searchPattern, System.IO.SearchOption searchOption)
|
||||
{
|
||||
System.IO.DirectoryInfo[] _systemDirInfos = _dirInfo.GetDirectories(searchPattern, searchOption);
|
||||
DirectoryInfo[] _dirInfos = new DirectoryInfo[_systemDirInfos.Length];
|
||||
|
||||
for(int i = 0; i < _dirInfos.Length; i++)
|
||||
_dirInfos[i] = new DirectoryInfo(_systemDirInfos[i]);
|
||||
|
||||
return _dirInfos;
|
||||
}
|
||||
|
||||
public System.IO.FileSystemInfo [] GetFileSystemInfos ()
|
||||
{
|
||||
return _dirInfo.GetFileSystemInfos();
|
||||
}
|
||||
|
||||
public System.IO.FileSystemInfo [] GetFileSystemInfos (string searchPattern)
|
||||
{
|
||||
return _dirInfo.GetFileSystemInfos(searchPattern);
|
||||
}
|
||||
|
||||
public
|
||||
System.IO.FileSystemInfo [] GetFileSystemInfos (string searchPattern, System.IO.SearchOption searchOption)
|
||||
{
|
||||
return _dirInfo.GetFileSystemInfos(searchPattern, searchOption);
|
||||
}
|
||||
|
||||
public override void Delete ()
|
||||
{
|
||||
_dirInfo.Delete();
|
||||
}
|
||||
|
||||
public void Delete (bool recursive)
|
||||
{
|
||||
_dirInfo.Delete(recursive);
|
||||
}
|
||||
|
||||
public void MoveTo (string destDirName)
|
||||
{
|
||||
_dirInfo.MoveTo(destDirName);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return _dirInfo.ToString();
|
||||
}
|
||||
|
||||
#if !MOBILE
|
||||
public void Create (DirectorySecurity directorySecurity)
|
||||
{
|
||||
_dirInfo.Create(directorySecurity);
|
||||
}
|
||||
|
||||
public DirectoryInfo CreateSubdirectory (string path, DirectorySecurity directorySecurity)
|
||||
{
|
||||
return new DirectoryInfo(_dirInfo.CreateSubdirectory(path, directorySecurity));
|
||||
}
|
||||
|
||||
public DirectorySecurity GetAccessControl ()
|
||||
{
|
||||
return _dirInfo.GetAccessControl();
|
||||
}
|
||||
|
||||
public DirectorySecurity GetAccessControl (AccessControlSections includeSections)
|
||||
{
|
||||
return _dirInfo.GetAccessControl(includeSections);
|
||||
}
|
||||
|
||||
public void SetAccessControl (DirectorySecurity directorySecurity)
|
||||
{
|
||||
_dirInfo.SetAccessControl(directorySecurity);
|
||||
}
|
||||
#endif
|
||||
|
||||
public IEnumerable<DirectoryInfo> EnumerateDirectories ()
|
||||
{
|
||||
foreach(System.IO.DirectoryInfo _sysDirInfo in _dirInfo.EnumerateDirectories())
|
||||
yield return new DirectoryInfo(_sysDirInfo);
|
||||
}
|
||||
|
||||
public IEnumerable<DirectoryInfo> EnumerateDirectories (string searchPattern)
|
||||
{
|
||||
foreach(System.IO.DirectoryInfo _sysDirInfo in _dirInfo.EnumerateDirectories(searchPattern))
|
||||
yield return new DirectoryInfo(_sysDirInfo);
|
||||
}
|
||||
|
||||
public IEnumerable<DirectoryInfo> EnumerateDirectories (string searchPattern, System.IO.SearchOption searchOption)
|
||||
{
|
||||
foreach(System.IO.DirectoryInfo _sysDirInfo in _dirInfo.EnumerateDirectories(searchPattern, searchOption))
|
||||
yield return new DirectoryInfo(_sysDirInfo);
|
||||
}
|
||||
|
||||
public IEnumerable<FileInfo> EnumerateFiles ()
|
||||
{
|
||||
foreach(System.IO.FileInfo _sysFileInfo in _dirInfo.EnumerateFiles())
|
||||
yield return new FileInfo(_sysFileInfo);
|
||||
}
|
||||
|
||||
public IEnumerable<FileInfo> EnumerateFiles (string searchPattern)
|
||||
{
|
||||
foreach(System.IO.FileInfo _sysFileInfo in _dirInfo.EnumerateFiles(searchPattern))
|
||||
yield return new FileInfo(_sysFileInfo);
|
||||
}
|
||||
|
||||
public IEnumerable<FileInfo> EnumerateFiles (string searchPattern, System.IO.SearchOption searchOption)
|
||||
{
|
||||
foreach(System.IO.FileInfo _sysFileInfo in _dirInfo.EnumerateFiles(searchPattern, searchOption))
|
||||
yield return new FileInfo(_sysFileInfo);
|
||||
}
|
||||
|
||||
public IEnumerable<System.IO.FileSystemInfo> EnumerateFileSystemInfos ()
|
||||
{
|
||||
return _dirInfo.EnumerateFileSystemInfos();
|
||||
}
|
||||
|
||||
public IEnumerable<System.IO.FileSystemInfo> EnumerateFileSystemInfos (string searchPattern)
|
||||
{
|
||||
return _dirInfo.EnumerateFileSystemInfos(searchPattern);
|
||||
}
|
||||
|
||||
public IEnumerable<System.IO.FileSystemInfo> EnumerateFileSystemInfos (string searchPattern, System.IO.SearchOption searchOption)
|
||||
{
|
||||
return _dirInfo.EnumerateFileSystemInfos(searchPattern, searchOption);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
211
Claunia.IO/FileInfo.cs
Normal file
211
Claunia.IO/FileInfo.cs
Normal file
@@ -0,0 +1,211 @@
|
||||
//
|
||||
// FileInfo.cs
|
||||
//
|
||||
// Author:
|
||||
// Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Copyright (c) 2015 © Claunia.com
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
#if !MOBILE
|
||||
using System.Security.AccessControl;
|
||||
#endif
|
||||
|
||||
namespace Claunia.IO
|
||||
{
|
||||
[SerializableAttribute]
|
||||
[ComVisibleAttribute(true)]
|
||||
public sealed class FileInfo : System.IO.FileSystemInfo
|
||||
{
|
||||
// As FileInfo is sealed, let's gonna cheat a little :p
|
||||
readonly System.IO.FileInfo _fileInfo;
|
||||
|
||||
public FileInfo (string fileName)
|
||||
{
|
||||
_fileInfo = new System.IO.FileInfo(fileName);
|
||||
}
|
||||
|
||||
// For manual casting
|
||||
public FileInfo (System.IO.FileInfo fileInfo)
|
||||
{
|
||||
_fileInfo = fileInfo;
|
||||
}
|
||||
|
||||
public override bool Exists {
|
||||
get {
|
||||
return _fileInfo.Exists;
|
||||
}
|
||||
}
|
||||
|
||||
public override string Name {
|
||||
get {
|
||||
return _fileInfo.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly {
|
||||
get {
|
||||
return _fileInfo.IsReadOnly;
|
||||
}
|
||||
|
||||
set {
|
||||
_fileInfo.IsReadOnly = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Encrypt ()
|
||||
{
|
||||
_fileInfo.Encrypt();
|
||||
}
|
||||
|
||||
public void Decrypt ()
|
||||
{
|
||||
_fileInfo.Decrypt();
|
||||
}
|
||||
|
||||
public long Length {
|
||||
get {
|
||||
return _fileInfo.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public string DirectoryName {
|
||||
get {
|
||||
return _fileInfo.DirectoryName;
|
||||
}
|
||||
}
|
||||
|
||||
public DirectoryInfo Directory {
|
||||
get {
|
||||
return new DirectoryInfo(_fileInfo.Directory);
|
||||
}
|
||||
}
|
||||
|
||||
public StreamReader OpenText ()
|
||||
{
|
||||
return _fileInfo.OpenText();
|
||||
}
|
||||
|
||||
public StreamWriter CreateText ()
|
||||
{
|
||||
return _fileInfo.CreateText();
|
||||
}
|
||||
|
||||
public StreamWriter AppendText ()
|
||||
{
|
||||
return _fileInfo.AppendText();
|
||||
}
|
||||
|
||||
public FileStream Create ()
|
||||
{
|
||||
return _fileInfo.Create();
|
||||
}
|
||||
|
||||
public FileStream OpenRead ()
|
||||
{
|
||||
return _fileInfo.OpenRead();
|
||||
}
|
||||
|
||||
public FileStream OpenWrite ()
|
||||
{
|
||||
return _fileInfo.OpenWrite();
|
||||
}
|
||||
|
||||
public FileStream Open (FileMode mode)
|
||||
{
|
||||
return _fileInfo.Open(mode);
|
||||
}
|
||||
|
||||
public FileStream Open (FileMode mode, FileAccess access)
|
||||
{
|
||||
return _fileInfo.Open(mode, access);
|
||||
}
|
||||
|
||||
public FileStream Open (FileMode mode, FileAccess access, FileShare share)
|
||||
{
|
||||
return _fileInfo.Open(mode, access, share);
|
||||
}
|
||||
|
||||
public override void Delete ()
|
||||
{
|
||||
_fileInfo.Delete();
|
||||
}
|
||||
|
||||
public void MoveTo (string destFileName)
|
||||
{
|
||||
_fileInfo.MoveTo(destFileName);
|
||||
}
|
||||
|
||||
public FileInfo CopyTo (string destFileName)
|
||||
{
|
||||
System.IO.FileInfo tmpFileInfo = _fileInfo.CopyTo(destFileName);
|
||||
return new FileInfo(tmpFileInfo);
|
||||
}
|
||||
|
||||
public FileInfo CopyTo (string destFileName, bool overwrite)
|
||||
{
|
||||
System.IO.FileInfo tmpFileInfo = _fileInfo.CopyTo(destFileName, overwrite);
|
||||
return new FileInfo(tmpFileInfo);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return _fileInfo.ToString();
|
||||
}
|
||||
|
||||
#if !MOBILE
|
||||
public FileSecurity GetAccessControl ()
|
||||
{
|
||||
return _fileInfo.GetAccessControl();
|
||||
}
|
||||
|
||||
public FileSecurity GetAccessControl (AccessControlSections includeSections)
|
||||
{
|
||||
return _fileInfo.GetAccessControl(includeSections);
|
||||
}
|
||||
|
||||
public FileInfo Replace (string destinationFileName,
|
||||
string destinationBackupFileName)
|
||||
{
|
||||
System.IO.FileInfo tmpFileInfo =_fileInfo.Replace(destinationFileName, destinationBackupFileName);
|
||||
return new FileInfo(tmpFileInfo);
|
||||
}
|
||||
|
||||
public FileInfo Replace (string destinationFileName,
|
||||
string destinationBackupFileName,
|
||||
bool ignoreMetadataErrors)
|
||||
{
|
||||
System.IO.FileInfo tmpFileInfo = _fileInfo.Replace(destinationFileName, destinationBackupFileName, ignoreMetadataErrors);
|
||||
return new FileInfo(tmpFileInfo);
|
||||
}
|
||||
|
||||
public void SetAccessControl (FileSecurity fileSecurity)
|
||||
{
|
||||
_fileInfo.SetAccessControl(fileSecurity);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Claunia.IO
|
||||
{
|
||||
public class MyClass
|
||||
{
|
||||
public MyClass()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user