// $Id$
//
// Copyright 2007-2008 Cisco Systems Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
using System;
namespace Etch.Msg
{
///
/// class used to implement ValueFactory based import / export code
/// for service defined types.
///
public class ImportExportHelper
{
protected ImportExportHelper()
{
ev = delegate(ValueFactory vf, Object value)
{
throw new NotImplementedException("must override ExportValue method");
};
iv = delegate(StructValue sv)
{
throw new NotImplementedException("must override ImportValue method");
};
}
public ImportExportHelper( ExportValueDelegate ev, ImportValueDelegate iv )
{
if (ev == null)
throw new ArgumentNullException("ev == null");
if (iv == null)
throw new ArgumentNullException("iv == null");
this.ev = ev;
this.iv = iv;
}
private readonly ExportValueDelegate ev;
private readonly ImportValueDelegate iv;
///
/// Exports a value by creating an equivalent StructValue.
///
/// the value factory used to export.
/// a service defined type to export.
/// a StructValue representing the exported value.
public virtual StructValue ExportValue( ValueFactory vf, Object value )
{
return ev( vf, value );
}
///
/// Imports a value from an equivalent StructValue.
///
/// a StructValue representing the exported value.
/// a service defined type.
public virtual Object ImportValue( StructValue sv )
{
return iv( sv );
}
///
/// Exports a value by creating an equivalent StructValue.
///
/// the value factory to use for export.
/// a service defined type to export.
/// a StructValue representing the exported value.
public delegate StructValue ExportValueDelegate(ValueFactory vf, Object value);
///
/// Imports a value from an equivalent StructValue.
///
/// a StructValue representing the exported value.
/// a service defined type.
public delegate Object ImportValueDelegate( StructValue sv );
}
}