XmlIncludeAttribute コンストラクタ
アセンブリ: System.Xml (system.xml.dll 内)
構文
使用例
次の例では 3 つのクラスがあり、そのうち 2 つは 3 番目のクラスから継承したクラスです。この例では、2 つのうちの 1 つの派生クラスのインスタンスを返すメソッドに XmlIncludeAttribute を適用します。Type プロパティには、返されるオブジェクトの型が設定されます。
Public Class Vehicle End Class Public Class Car Inherits Vehicle End Class Public Class Truck Inherits Vehicle End Class Public Class Sample <WebMethod(), _ XmlInclude(GetType(Car)), _ XmlInclude(GetType(Truck))> _ Public Function ReturnVehicle(i As Integer) As Vehicle If i = 0 Then Return New Car() Else Return New Truck() End If End Function End Class
public class Vehicle{} public class Car:Vehicle{} public class Truck:Vehicle{} public class Sample { [WebMethodAttribute] [XmlInclude(typeof(Car))] [XmlInclude(typeof(Truck))] public Vehicle ReturnVehicle(int i){ if(i == 0) return new Car(); else return new Truck(); } }
public ref class Vehicle{}; public ref class Car: public Vehicle{}; public ref class Truck: public Vehicle{}; public ref class Sample { public: [WebMethodAttribute] [XmlInclude(Car::typeid)] [XmlInclude(Truck::typeid)] Vehicle^ ReturnVehicle( int i ) { if ( i == 0 ) return gcnew Car; else return gcnew Truck; } };
public class Vehicle { } //Vehicle public class Car extends Vehicle { } //Car public class Truck extends Vehicle { } //Truck public class Sample { /** @attribute WebMethodAttribute() */ /** @attribute XmlInclude(Car.class) */ /** @attribute XmlInclude(Truck.class) */ public Vehicle ReturnVehicle(int i) { if (i == 0) { return new Car(); } else { return new Truck(); } } //ReturnVehicle } //Sample
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- XmlIncludeAttribute コンストラクタのページへのリンク