DataObject.SetData 메서드

정의

DataObject에 개체를 추가합니다.

오버로드

SetData(Object)

개체 형식을 데이터 형식으로 사용하여 DataObject에 지정된 개체를 추가합니다.

SetData(String, Object)

지정된 형식을 사용하여 DataObject에 지정된 개체를 추가합니다.

SetData(Type, Object)

지정된 형식을 형식으로 사용하여 DataObject에 지정된 개체를 추가합니다.

SetData(String, Boolean, Object)

지정된 형식을 사용하고 데이터가 다른 형식으로 변환될 수 있는지 여부를 나타내어 DataObject에 지정된 개체를 추가합니다.

SetData(Object)

개체 형식을 데이터 형식으로 사용하여 DataObject에 지정된 개체를 추가합니다.

public:
 virtual void SetData(System::Object ^ data);
public virtual void SetData (object data);
public virtual void SetData (object? data);
abstract member SetData : obj -> unit
override this.SetData : obj -> unit
Public Overridable Sub SetData (data As Object)

매개 변수

data
Object

저장할 데이터입니다.

구현

예제

다음 코드 예제에서는 데이터를 에 저장합니다 DataObject. 먼저 새 DataObject 가 만들어지고 구성 요소가 저장됩니다. 그런 다음, 클래스를 지정하여 데이터를 검색합니다. 결과 텍스트 상자에 표시 됩니다.

이 코드를 실행 하려면 textBox1 만들었습니다.

private:
   void AddMyData3()
   {
      // Creates a component to store in the data object.
      Component^ myComponent = gcnew Component;
      
      // Creates a new data object.
      DataObject^ myDataObject = gcnew DataObject;
      
      // Adds the component to the DataObject.
      myDataObject->SetData( myComponent );
      
      // Prints whether data of the specified type is in the DataObject.
      Type^ myType = myComponent->GetType();
      if ( myDataObject->GetDataPresent( myType ) )
      {
         textBox1->Text = String::Concat( "Data of type ", myType->Name,
           " is present in the DataObject" );
      }
      else
      {
         textBox1->Text = String::Concat( "Data of type ", myType->Name,
           " is not present in the DataObject" );
      }
   }
private void AddMyData3() {
    // Creates a component to store in the data object.
    Component myComponent = new Component();
 
    // Creates a new data object.
    DataObject myDataObject = new DataObject();
 
    // Adds the component to the DataObject.
    myDataObject.SetData(myComponent);
 
    // Prints whether data of the specified type is in the DataObject.
    Type myType = myComponent.GetType();
    if(myDataObject.GetDataPresent(myType))
       textBox1.Text = "Data of type " + myType.GetType().Name + 
       " is present in the DataObject";
    else
       textBox1.Text = "Data of type " + myType.GetType().Name +
       " is not present in the DataObject";
 }
Private Sub AddMyData3()
    ' Creates a component to store in the data object.
    Dim myComponent As New Component()
    
    ' Creates a new data object.
    Dim myDataObject As New DataObject()
    
    ' Adds the component to the DataObject.
    myDataObject.SetData(myComponent)
    
    ' Prints whether data of the specified type is in the DataObject.
    Dim myType As Type = myComponent.GetType()
    If myDataObject.GetDataPresent(myType) Then
        textBox1.Text = "Data of type " & myType.GetType().Name & _
            " is present in the DataObject"
    Else
        textBox1.Text = "Data of type " & myType.GetType().Name & _
            " is not present in the DataObject"
    End If
End Sub

설명

중요

신뢰할 수 없는 데이터로 이 메서드를 호출하는 것은 보안상 위험합니다. 신뢰할 수 있는 데이터로만 이 메서드를 호출하세요. 자세한 내용은 모든 입력 유효성 검사를 참조하세요.

대상 애플리케이션의 형식을 모르는 경우이 메서드를 사용 하 여 여러 형식의 데이터를 저장할 수 있습니다. 이 메서드를 사용하여 저장된 데이터는 검색할 때 호환되는 형식으로 변환할 수 있습니다.

SetData(Object) 오버로드는 메서드를 data 호출 Object.GetType 하여 결정하는 형식으로 값을 저장합니다. 인터페이스를 구현하는 ISerializable 경우 data 이 오버로드는 값도 형식으로 Serializable 저장합니다.

추가 정보

적용 대상

SetData(String, Object)

지정된 형식을 사용하여 DataObject에 지정된 개체를 추가합니다.

public:
 virtual void SetData(System::String ^ format, System::Object ^ data);
public virtual void SetData (string format, object data);
public virtual void SetData (string format, object? data);
abstract member SetData : string * obj -> unit
override this.SetData : string * obj -> unit
Public Overridable Sub SetData (format As String, data As Object)

매개 변수

format
String

데이터와 관련된 형식입니다. 미리 정의된 형식에 대한 자세한 내용은 DataFormats를 참조하십시오.

data
Object

저장할 데이터입니다.

구현

예제

다음 코드 예제에서는 데이터를 에 저장 DataObject하고 형식을 유니코드로 지정합니다.

그런 다음, 텍스트 형식을 지정하여 데이터를 검색합니다. 기본값은 최종 형식이 호환될 때 데이터를 변환하는 것입니다. 결과 텍스트 상자에 표시 됩니다.

이 코드를 실행 하려면 textBox1 만들었습니다.

private:
   void AddMyData()
   {
      // Creates a new data object using a string and the text format.
      DataObject^ myDataObject = gcnew DataObject;
      
      // Stores a string, specifying the Unicode format.
      myDataObject->SetData( DataFormats::UnicodeText, "Text string" );
      
      // Retrieves the data by specifying Text.
      textBox1->Text = myDataObject->GetData( DataFormats::Text )->GetType()->Name;
   }
private void AddMyData() {
    // Creates a new data object using a string and the text format.
    DataObject myDataObject = new DataObject();
 
    // Stores a string, specifying the Unicode format.
    myDataObject.SetData(DataFormats.UnicodeText, "Text string");
 
    // Retrieves the data by specifying Text.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).GetType().Name;
 }
Private Sub AddMyData()
    ' Creates a new data object using a string and the text format.
    Dim myDataObject As New DataObject()
    
    ' Stores a string, specifying the Unicode format.
    myDataObject.SetData(DataFormats.UnicodeText, "Text string")
    
    ' Retrieves the data by specifying Text.
    textBox1.Text = myDataObject.GetData(DataFormats.Text).GetType().Name
End Sub

설명

중요

신뢰할 수 없는 데이터로 이 메서드를 호출하는 것은 보안상 위험합니다. 신뢰할 수 있는 데이터로만 이 메서드를 호출하세요. 자세한 내용은 모든 입력 유효성 검사를 참조하세요.

대상 애플리케이션의 형식을 모르는 경우이 메서드를 사용 하 여 여러 형식의 데이터를 저장할 수 있습니다.

이 메서드를 사용하여 저장된 데이터는 검색할 때 호환되는 형식으로 변환할 수 있습니다.

추가 정보

적용 대상

SetData(Type, Object)

지정된 형식을 형식으로 사용하여 DataObject에 지정된 개체를 추가합니다.

public:
 virtual void SetData(Type ^ format, System::Object ^ data);
public virtual void SetData (Type format, object data);
public virtual void SetData (Type format, object? data);
abstract member SetData : Type * obj -> unit
override this.SetData : Type * obj -> unit
Public Overridable Sub SetData (format As Type, data As Object)

매개 변수

format
Type

데이터와 관련된 형식을 나타내는 Type입니다.

data
Object

저장할 데이터입니다.

구현

예제

다음 코드 예제에서는 데이터 형식으로 사용 DataObject 하 여 Type 에 데이터를 저장 합니다. 그런 다음 를 사용하여 Type 를 호출 GetData 하여 데이터 형식을 지정하여 데이터를 검색합니다. 결과 텍스트 상자에 표시 됩니다.

이 코드를 실행 하려면 textBox1 만들었습니다.

private:
   void AddMyData2()
   {
      // Creates a component to store in the data object.
      Component^ myComponent = gcnew Component;
      
      // Gets the type of the component.
      Type^ myType = myComponent->GetType();
      
      // Creates a new data object.
      DataObject^ myDataObject = gcnew DataObject;
      
      // Adds the component to the DataObject.
      myDataObject->SetData( myType, myComponent );
      
      // Prints whether data of the specified type is in the DataObject.
      if ( myDataObject->GetDataPresent( myType ) )
      {
         textBox1->Text = String::Concat( "Data of type ", myType->Name,
            " is present in the DataObject" );
      }
      else
      {
         textBox1->Text = String::Concat( "Data of type ", myType->Name,
           " is not present in the DataObject" );
      }
   }
private void AddMyData2() {
    // Creates a component to store in the data object.
    Component myComponent = new Component();
 
    // Gets the type of the component.
    Type myType = myComponent.GetType();
 
    // Creates a new data object.
    DataObject myDataObject = new DataObject();
 
    // Adds the component to the DataObject.
    myDataObject.SetData(myType, myComponent);
 
    // Prints whether data of the specified type is in the DataObject.
    if(myDataObject.GetDataPresent(myType))
       textBox1.Text = "Data of type " + myType.GetType().Name + 
       " is present in the DataObject";
    else
       textBox1.Text = "Data of type " + myType.GetType().Name +
       " is not present in the DataObject";
 }
Private Sub AddMyData2()
    ' Creates a component to store in the data object.
    Dim myComponent As New Component()
    
    ' Gets the type of the component.
    Dim myType As Type = myComponent.GetType()
    
    ' Creates a new data object.
    Dim myDataObject As New DataObject()
    
    ' Adds the component to the DataObject.
    myDataObject.SetData(myType, myComponent)
    
    ' Prints whether data of the specified type is in the DataObject.
    If myDataObject.GetDataPresent(myType) Then
        textBox1.Text = "Data of type " & myType.GetType().Name & _
            " is present in the DataObject"
    Else
        textBox1.Text = "Data of type " & myType.GetType().Name & _
            " is not present in the DataObject"
    End If
End Sub

설명

중요

신뢰할 수 없는 데이터로 이 메서드를 호출하는 것은 보안상 위험합니다. 신뢰할 수 있는 데이터로만 이 메서드를 호출하세요. 자세한 내용은 모든 입력 유효성 검사를 참조하세요.

대상 애플리케이션의 형식을 모르는 경우이 메서드를 사용 하 여 여러 형식의 데이터를 저장할 수 있습니다.

이 메서드를 사용하여 저장된 데이터는 검색할 때 호환되는 형식으로 변환할 수 있습니다.

추가 정보

적용 대상

SetData(String, Boolean, Object)

지정된 형식을 사용하고 데이터가 다른 형식으로 변환될 수 있는지 여부를 나타내어 DataObject에 지정된 개체를 추가합니다.

public:
 virtual void SetData(System::String ^ format, bool autoConvert, System::Object ^ data);
public virtual void SetData (string format, bool autoConvert, object data);
public virtual void SetData (string format, bool autoConvert, object? data);
abstract member SetData : string * bool * obj -> unit
override this.SetData : string * bool * obj -> unit
Public Overridable Sub SetData (format As String, autoConvert As Boolean, data As Object)

매개 변수

format
String

데이터와 관련된 형식입니다. 미리 정의된 형식에 대한 자세한 내용은 DataFormats를 참조하십시오.

autoConvert
Boolean

데이터를 다른 형식으로 변환할 수 있도록 하려면 true이고, 그렇지 않으면 false입니다.

data
Object

저장할 데이터입니다.

구현

예제

다음 코드 예제에서는 데이터를 에 DataObject 저장하고 데이터를 네이티브 형식으로만 검색할 수 있도록 지정합니다.

먼저 새 DataObject 가 만들어집니다. 유니코드 형식의 데이터는 로 설정된 falseDataObjectautoConvert 저장됩니다.

그런 다음 가 DataObject 사용 가능한 데이터 형식 목록을 쿼리합니다. 유니코드 데이터는 텍스트 및 기타 형식으로 변환할 수 있지만 유니코드 형식만 반환됩니다.

이 코드를 실행 하려면 textBox1 만들었습니다.

private:
   void AddMyData4()
   {
      // Creates a new data object, and assigns it the component.
      DataObject^ myDataObject = gcnew DataObject;
      
      // Adds data to the DataObject, and specifies no format conversion.
      myDataObject->SetData( DataFormats::UnicodeText, false, "My Unicode data" );
      
      // Gets the data formats in the DataObject.
      array<String^>^ arrayOfFormats = myDataObject->GetFormats();
      
      // Prints the results.
      textBox1->Text = "The format(s) associated with the data are: \n";
      for ( int i = 0; i < arrayOfFormats->Length; i++ )
      {
         textBox1->Text = String::Concat( textBox1->Text, arrayOfFormats[ i ], "\n" );
      }
   }
private void AddMyData4() {
    // Creates a new data object, and assigns it the component.
    DataObject myDataObject = new DataObject();
 
    // Adds data to the DataObject, and specifies no format conversion.
    myDataObject.SetData(DataFormats.UnicodeText, false, "My Unicode data");
 
    // Gets the data formats in the DataObject.
    String[] arrayOfFormats = myDataObject.GetFormats();
 
    // Prints the results.
    textBox1.Text = "The format(s) associated with the data are: " + '\n';
    for(int i=0; i<arrayOfFormats.Length; i++)
       textBox1.Text += arrayOfFormats[i] + '\n';
 }
Private Sub AddMyData4()
    ' Creates a new data object, and assigns it the component.
    Dim myDataObject As New DataObject()
    
    ' Adds data to the DataObject, and specifies no format conversion.
    myDataObject.SetData(DataFormats.UnicodeText, False, "My Unicode data")
    
    ' Gets the data formats in the DataObject.
    Dim arrayOfFormats As String() = myDataObject.GetFormats()
    
    ' Prints the results.
    textBox1.Text = "The format(s) associated with the data are: " & ControlChars.Cr
    Dim i As Integer
    For i = 0 To arrayOfFormats.Length - 1
        textBox1.Text += arrayOfFormats(i) & ControlChars.Cr
    Next i
End Sub

설명

중요

신뢰할 수 없는 데이터로 이 메서드를 호출하는 것은 보안상 위험합니다. 신뢰할 수 있는 데이터로만 이 메서드를 호출하세요. 자세한 내용은 모든 입력 유효성 검사를 참조하세요.

대상 애플리케이션의 형식을 모르는 경우이 메서드를 사용 하 여 여러 형식의 데이터를 저장할 수 있습니다.

추가 정보

적용 대상