// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) VRMADA, All rights reserved.
//
// --------------------------------------------------------------------------------------------------------------------
using System;
using UltimateXR.Core.Serialization;
using UltimateXR.Core.StateSync;
namespace UltimateXR.Exceptions
{
///
/// Exception thrown when trying to deserialize an object that implements the interface
/// but can't be instantiated using the name/assembly provided.
///
public sealed class UxrSerializableClassNotFoundException : Exception
{
#region Public Types & Data
///
/// Gets the class type name.
///
public string ClassName { get; }
///
/// Gets the assembly where the type is located.
///
public string AssemblyName { get; }
#endregion
#region Constructors & Finalizer
///
/// Constructor.
///
/// Class name
/// Assembly name where the type is located
/// Exception message
public UxrSerializableClassNotFoundException(string className, string assemblyName, string message = null) : base(FormatMessage(className, assemblyName, message))
{
ClassName = className;
AssemblyName = assemblyName;
}
#endregion
#region Private Methods
///
/// Gets a formatted exception message.
///
/// Class name
/// Assembly name where the type is located
/// Original message
/// Exception message
private static string FormatMessage(string className, string assemblyName, string message)
{
string assemblyInformation = !string.IsNullOrEmpty(assemblyName) ? $" in assembly {assemblyName}" : string.Empty;
string prefix = !string.IsNullOrEmpty(message) ? $"{message}: " : string.Empty;
return $"{prefix}Can't instantiate type {className}{assemblyInformation} or it does not implement the {nameof(IUxrSerializable)} interface.";
}
#endregion
}
}