FormatterServices.PopulateObjectMembers メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Public Shared Function PopulateObjectMembers ( _ obj As Object, _ members As MemberInfo(), _ data As Object() _ ) As Object
Dim obj As Object Dim members As MemberInfo() Dim data As Object() Dim returnValue As Object returnValue = FormatterServices.PopulateObjectMembers(obj, members, data)
public: static Object^ PopulateObjectMembers ( Object^ obj, array<MemberInfo^>^ members, array<Object^>^ data )
public static function PopulateObjectMembers ( obj : Object, members : MemberInfo[], data : Object[] ) : Object
- members
新しく設定されたオブジェクト。



Book クラスのインスタンスを作成し、そのインスタンスのフィールド値を設定する例を次に示します。このコードでは、次に GetSerializableMembers メソッドを使用して型情報を取得します。また、GetObjectData メソッドを使用して、インスタンスのデータをオブジェクトの配列にコピーします。さらに、GetSafeUninitializedObject メソッドを使用して、初期化前の状態に戻したクラスの新しいインスタンスを作成します。最後に、PopulateObjectMembers メソッドを使用して、1 つ目のインスタンスのデータを 2 つ目のインスタンスにコピーします。
Imports System Imports System.Collections Imports System.Runtime.Serialization Imports System.IO Imports System.Reflection Imports System.Security.Permissions <Assembly: SecurityPermission(SecurityAction.RequestMinimum)> ' The SerializableAttribute specifies that instances of the class ' can be serialized by the BinaryFormatter or SoapFormatter. <Serializable()> _ Class Book Public Title As String Public Author As String ' Constructor for setting new values. Public Sub New(ByVal newTitle As String, _ ByVal newAuthor As String) Title = newTitle Author = newAuthor End Sub End Class <SecurityPermission(SecurityAction.Demand)> _ Public NotInheritable Class Test Public Shared Sub Main() Try Run() Catch exc As System.Exception Console.WriteLine("{0}: {1}", _ exc.Message, exc.StackTrace) Finally Console.WriteLine("Press <Enter> to exit....") Console.ReadLine() End Try End Sub Shared Sub Run() ' Create an instance of a Book class ' with a title and author. Dim Book1 As New Book("Book Title 1", "Masato Kawai") ' Store data about the serializable members in a ' MemberInfo array. The MemberInfo type holds ' only type data, not instance data. Dim members As MemberInfo() = _ FormatterServices.GetSerializableMembers(GetType(Book)) ' Copy the data from the first book into an ' array of objects. Dim data As Object() = _ FormatterServices.GetObjectData(Book1, members) ' Create an uninitialized instance of the Book class. Dim Book1Copy As Book = _ CType(FormatterServices.GetSafeUninitializedObject _ (GetType(Book)), Book) ' Call the PopuluateObjectMembers to copy the ' data into the new Book instance. FormatterServices.PopulateObjectMembers _ (Book1Copy, members, data) ' Print the data from the copy. Console.WriteLine("Title: {0}", Book1Copy.Title) Console.WriteLine("Author: {0}", Book1Copy.Author) End Sub ' A private constructor is good practice on ' a class containing only static methods. Private Sub New() End Sub End Class
using System; using System.Collections; using System.Runtime.Serialization; using System.IO; using System.Reflection; using System.Security.Permissions; [assembly: SecurityPermission(SecurityAction.RequestMinimum)] namespace Examples { // The SerializableAttribute specifies that instances of the class // can be serialized by the BinaryFormatter or SoapFormatter. [Serializable] class Book { public string Title; public string Author; // Constructor for setting new values. public Book(string newTitle, string newAuthor) { Title = newTitle; Author = newAuthor; } } [SecurityPermission(SecurityAction.Demand)] public sealed class Test { public static void Main() { try { Run(); } catch (System.Exception exc) { Console.WriteLine("{0}: {1}", exc.Message, exc.StackTrace); } finally { Console.WriteLine("Press <Enter> to exit...."); Console.ReadLine(); } } static void Run() { // Create an instance of a Book class // with a title and author. Book Book1 = new Book("Book Title 1", "Masato Kawai"); // Store data about the serializable members in a // MemberInfo array. The MemberInfo type holds // only type data, not instance data. MemberInfo[] members = FormatterServices.GetSerializableMembers (typeof(Book)); // Copy the data from the first book into an // array of objects. object[] data = FormatterServices.GetObjectData(Book1, members); // Create an uninitialized instance of the Book class. Book Book1Copy = (Book)FormatterServices.GetSafeUninitializedObject (typeof(Book)); // Call the PopuluateObjectMembers to copy the // data into the new Book instance. FormatterServices.PopulateObjectMembers (Book1Copy, members, data); // Print the data from the copy. Console.WriteLine("Title: {0}", Book1Copy.Title); Console.WriteLine("Author: {0}", Book1Copy.Author); } // A private constructor is good practice on // a class containing only static methods. private Test() { } } }


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からFormatterServices.PopulateObjectMembers メソッドを検索する場合は、下記のリンクをクリックしてください。

- FormatterServices.PopulateObjectMembers メソッドのページへのリンク