TempFileCollection 클래스

정의

임시 파일의 컬렉션을 나타냅니다.

public ref class TempFileCollection : IDisposable, System::Collections::ICollection
public class TempFileCollection : IDisposable, System.Collections.ICollection
[System.Serializable]
public class TempFileCollection : IDisposable, System.Collections.ICollection
type TempFileCollection = class
    interface ICollection
    interface IEnumerable
    interface IDisposable
[<System.Serializable>]
type TempFileCollection = class
    interface ICollection
    interface IEnumerable
    interface IDisposable
Public Class TempFileCollection
Implements ICollection, IDisposable
상속
TempFileCollection
특성
구현

예제

다음 예제에서는 클래스 및 및 AddFile 메서드의 TempFileCollectionAddExtension 사용을 보여 줍니다.

using System;
using System.CodeDom.Compiler;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        // Create a directory in the current working directory.
        Directory.CreateDirectory("testDir");
        TempFileCollection tfc = new TempFileCollection("testDir", false);
        // Returns the file name relative to the current working directory.
        string fileName = tfc.AddExtension("txt");
        Console.WriteLine(fileName);
        // Name a file in the test directory.
        string file2Name = "testDir\\test.txt";
        // Add the file to the temp directory and indicate it is to be kept.
        tfc.AddFile(file2Name, true);
        Console.WriteLine(tfc.Count);
        // Create and use the test files.
        FileStream fs1 = File.OpenWrite(fileName);
        FileStream fs2 = File.OpenWrite(file2Name);
        StreamWriter sw1 = new StreamWriter(fs1);
        StreamWriter sw2 = new StreamWriter(fs2);
        sw1.WriteLine("Test string");
        sw2.WriteLine("Test string");
        sw1.Close();
        sw2.Close();
        tfc.Delete();
        Console.WriteLine(tfc.Count);
        try
        {
            // This call should succeed.
            File.OpenRead(file2Name);
            // This call should fail.
            File.OpenRead(fileName);
        }
        catch (FileNotFoundException e)
        {
            Console.WriteLine(e.Message);
        }
    }
}
Imports System.CodeDom.Compiler
Imports System.IO



Class Program
    
    Shared Sub Main(ByVal args() As String) 
        ' Create a directory in the current working directory.
        Directory.CreateDirectory("testDir")
        Dim tfc As New TempFileCollection("testDir", False)
        ' Returns the file name relative to the current working directory.
        Dim fileName As String = tfc.AddExtension("txt")
        Console.WriteLine(fileName)
        ' Name a file in the test directory.
        Dim file2Name As String = "testDir\test.txt"
        ' Add the file to the temp directory and indicate it is to be kept.
        tfc.AddFile(file2Name, True)
        Console.WriteLine(tfc.Count)
        ' Create and use the test files.
        Dim fs1 As FileStream = File.OpenWrite(fileName)
        Dim fs2 As FileStream = File.OpenWrite(file2Name)
        Dim sw1 As New StreamWriter(fs1)
        Dim sw2 As New StreamWriter(fs2)
        sw1.WriteLine("Test string")
        sw2.WriteLine("Test string")
        sw1.Close()
        sw2.Close()
        tfc.Delete()
        Console.WriteLine(tfc.Count)
        Try
            ' This call should succeed.
            File.OpenRead(file2Name)
            ' This call should fail.
            File.OpenRead(fileName)
        Catch e As FileNotFoundException
            Console.WriteLine(e.Message)
        End Try
    
    End Sub
End Class

설명

TempFileCollection 는 고유한 파일 이름을 생성하고 파일 목록을 추적하는 데 사용할 수 있습니다. 이는 컴파일러에서 생성된 중간 파일 목록을 관리할 때 구현자에 유용 ICodeCompiler 할 수 있으며, 이 파일은 사용 후 삭제되기도 합니다.

에서 고유한 임시 파일 이름을 생성할 디렉터리를 지정하려면 적절하게 오버로드된 생성자를 사용합니다. 생성자 오버로드를 사용하여 컬렉션에 추가된 파일이 지정되지 않은 경우 또는 AddExtension 메서드를 사용할 AddFile 때 컬렉션이 삭제 Delete 되거나 메서드가 호출될 때 삭제되어야 하는지 여부를 나타낼 수도 있습니다.

모든 디렉터리의 파일을 메서드를 사용하는 AddFile instance TempFileCollection 추가할 수 있습니다.

특정 파일 확장자의 임시 파일에 대한 고유한 이름을 생성하려면 를 호출 AddExtension 하고 생성할 파일 이름의 확장명을 지정합니다. 메서드는 AddExtension 속성에 지정된 디렉터리에서 지정된 확장의 파일 이름에 대한 전체 경로로 구성된 문자열을 TempDir 반환합니다. 메서드는 AddExtension 파일 이름 확장명당 하나의 고유한 파일 이름만 반환합니다.

AddFileAddExtension 메서드에는 컬렉션이 삭제될 때 파일을 삭제할지 또는 메서드가 호출될 때 파일을 삭제할지 여부를 지정할 수 있는 오버로드가 Delete 있습니다.

메서드는 Delete 보관되도록 표시된 파일을 제외한 컬렉션의 모든 파일을 삭제합니다.

속성은 BasePath 메서드에서 반환 AddExtension 된 파일 이름을 생성하는 데 사용되는 파일 이름 확장명 없이 기본 파일 이름의 전체 경로를 나타냅니다.

참고

이 클래스에는 모든 멤버에 적용되는 클래스 수준에서 링크 요청 및 상속 요청이 포함됩니다. 직접 SecurityException 호출자 또는 파생 클래스에 완전 신뢰 권한이 없는 경우 이 throw됩니다. 보안 요청에 대 한 자세한 내용은 참조 하세요 링크 요청 하 고 상속 요청합니다.

생성자

TempFileCollection()

기본값을 사용하여 TempFileCollection 클래스의 새 인스턴스를 초기화합니다.

TempFileCollection(String)

기본적으로, 임시 파일을 생성하고 사용한 후에 해당 임시 파일을 삭제하도록 설정한 지정된 임시 디렉터리를 사용하여 TempFileCollection 클래스의 새 인스턴스를 초기화합니다.

TempFileCollection(String, Boolean)

기본적으로, 임시 파일을 생성하고사용한 후에 해당 임시 파일을 유지할 것인지 또는 삭제할 것인지 여부를 나타내는 지정된 값과 지정된 임시 디렉터리를 사용하여 TempFileCollection 클래스의 새 인스턴스를 초기화합니다.

속성

BasePath

컬렉션의 임시 파일 이름을 생성하는 데 사용되는 임시 디렉터리 경로의 기본 파일 이름(파일 확장명 제외)에 대한 전체 경로를 가져옵니다.

Count

컬렉션에 있는 파일의 수를 가져옵니다.

KeepFiles

Delete() 메서드가 호출되거나 컬렉션이 삭제될 때 기본적으로 파일을 유지하는지 여부를 나타내는 값을 가져오거나 설정합니다.

TempDir

임시 파일을 저장할 임시 디렉터리를 가져옵니다.

메서드

AddExtension(String)

지정된 파일 확장명의 파일 이름을 컬렉션에 추가합니다.

AddExtension(String, Boolean)

파일을 삭제해야 하는지 유지해야 하는지를 나타내는 지정된 값을 사용하여 지정된 파일 확장명의 파일 이름을 컬렉션에 추가합니다.

AddFile(String, Boolean)

컬렉션이 삭제되거나 Delete() 메서드가 호출될 때 파일을 보관할 것인지 여부를 나타내는 특정 값을 사용하여 지정된 파일을 컬렉션에 추가합니다.

CopyTo(String[], Int32)

지정된 인덱스에서 시작하여 지정된 문자열에 컬렉션의 멤버를 복사합니다.

Delete()

이 컬렉션 내에서 보관하도록 표시되지 않은 임시 파일을 삭제합니다.

Dispose(Boolean)

TempFileCollection에서 사용하는 관리되지 않는 리소스를 해제하고, 관리되는 리소스를 선택적으로 해제할 수 있습니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
Finalize()

가비지 수집에서 이 개체를 회수하기 전에 임시 파일을 삭제하려고 합니다.

GetEnumerator()

컬렉션의 멤버를 열거할 수 있는 열거자를 가져옵니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

ICollection.CopyTo(Array, Int32)

컬렉션의 요소를 대상 배열의 지정한 인덱스에서 시작하는 배열에 복사합니다.

ICollection.Count

컬렉션에 포함된 요소 수를 가져옵니다.

ICollection.IsSynchronized

해당 컬렉션에 대한 액세스가 동기화되어 스레드로부터 안전하게 보호되는지를 나타내는 값을 가져옵니다.

ICollection.SyncRoot

컬렉션에 대한 액세스를 동기화하는 데 사용할 수 있는 개체를 가져옵니다.

IDisposable.Dispose()

관리되지 않는 리소스의 확보, 해제 또는 다시 설정과 관련된 애플리케이션 정의 작업을 수행합니다.

IEnumerable.GetEnumerator()

컬렉션을 반복하는 열거자를 반환합니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상