// // ObjectModelConverter.cs // // Author: // beckermj <> // // Copyright (c) 2023 ${CopyrightHolder} // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . using System; using System.Linq; namespace UniversalEditor { public abstract class ObjectModelConverter { protected abstract void ConvertInternal(ObjectModel source, ObjectModel destination); public void Convert(ObjectModel source, ObjectModel destination) { ConvertInternal(source, destination); } protected virtual ObjectModelConversion[] GetSupportedConversionsInternal() { return new ObjectModelConversion[0]; } /// /// Gets a indicating the /// conversions supported by this . /// /// /// A where the /// is the source and the /// is the destination . /// public ObjectModelConversion[] GetSupportedConversions() { return GetSupportedConversionsInternal(); } /// /// Determines if this supports /// converting from the specified to the /// given . /// /// true, if the conversion is supported; false otherwise. /// An indicating the type of being converted from. /// An indicating the type of being converted to. public bool CanConvert(ObjectModelReference source, ObjectModelReference destination) { ObjectModelConversion tup = new ObjectModelConversion(source, destination); ObjectModelConversion[] tups = GetSupportedConversions(); bool supported = tups.Contains(tup); return supported; } public bool CanConvertFrom(ObjectModelReference source) { ObjectModelConversion[] tups = GetSupportedConversions(); foreach (ObjectModelConversion tup in tups) { if (tup.Source == source) return true; } return false; } public bool CanConvertTo(ObjectModelReference destination) { ObjectModelConversion[] tups = GetSupportedConversions(); foreach (ObjectModelConversion tup in tups) { if (tup.Destination == destination) return true; } return false; } } }