XMLファイルからのパラメータ復元

Namespace: FVIL.File
Assembly: FVILbasic (in FVILbasic.dll) Version: 3.1.0.0 (3.1.0.17)

Syntax

C#
public static Object LoadXml(
	string xmlfile,
	Type target_type
)
Visual Basic
Public Shared Function LoadXml ( 
	xmlfile As String,
	target_type As Type
) As Object

Parameters

xmlfile
Type: System..::..String
XML ファイル名称
target_type
Type: System..::..Type
復元するクラスの型

Return Value

Type: Object
復元されたインスタンスを返します。

Remarks

この関数は FileStreamXmlSerializer を使用し、 指定の XML ファイルからパラメータを復元して返します。 引数の xmlfile には、 SaveXml(String, Object) 関数で保存したファイルを指定してください。


内部の処理:
		StreamWriter^ fs = gcnew StreamWriter(xmlfile, false, Encoding::UTF8);
		try
		{
			XmlSerializer^ xml = gcnew XmlSerializer(target_type);
			Object^ result = xml->Deserialize(fs);
			return result;
		}
		catch (System::Exception^ ex)
		{
			throw ex;
		}
		finally
		{
			fs->Close();
		}
	

Examples

下記は、CFviSobelFilter のパラメータを XML ファイルから復元する例です。 XML ファイルへ保存する方法については、 SaveXml(String, Object) 関数のサンプルコードをご参照ください。



使用例:
C# Copy imageCopy
FVIL.Filter.CFviSobelFilter target =
    (FVIL.Filter.CFviSobelFilter)FVIL.File.Function.LoadXml(
        "sobel.xml", typeof(FVIL.Filter.CFviSobelFilter));

Console.WriteLine("SrcImages[0]={0}", target.SrcImages[0]);
Console.WriteLine("DstImages[0]={0}", target.DstImages[0]);
Console.WriteLine("BorderMode  ={0}", target.BorderMode);
Console.WriteLine("BorderValue ={0}", target.BorderValue);
Console.WriteLine("CalcMode    ={0}", target.CalcMode);


使用例:
		FVIL::Filter::CFviSobelFilter^ target = 
			safe_cast<FVIL::Filter::CFviSobelFilter^>(
				FVIL::File::Function::LoadXml(
					"sobel.xml", FVIL::Filter::CFviSobelFilter::typeid)
			);

		Console::WriteLine("SrcImages[0]={0}", target->SrcImages[0]);
		Console::WriteLine("DstImages[0]={0}", target->DstImages[0]);
		Console::WriteLine("BorderMode  ={0}", target->BorderMode);
		Console::WriteLine("BorderValue ={0}", target->BorderValue);
		Console::WriteLine("CalcMode    ={0}", target->CalcMode);
	


出力結果:
	SrcImages[0]=
	DstImages[0]=
	BorderMode  =Continuous
	BorderValue =55.6
	CalcMode    =SQRTMode
	

See Also