#pragma once
#include <string>
#include "convert.h"
namespace refl {
	bool Convert::ToString(Any& dst, const Any& src)
	{
		if (src.Parent() == &TypeInfo<char>::StaticClass) {
			std::construct_at(dst.CastTo<std::string*>(), src.CastTo<const char*>());
			return true;
		}
		return false;
	}
	inline bool Convert::Construct(Any& dst, const Any& src)
	{
		if (dst.Check(src.cls)) {
			dst.cls->parent->InitObject((void*)dst.ptr);
			dst.cls->parent->CopyObject((void*)dst.ptr, src.ptr);
			return true;
		}
		auto it = ClassMap.find(dst.cls);
		if (it == ClassMap.end()) {
			return false;
		}
		return it->second(dst, src);
	}
	ConvertMap Convert::BuildClassMap()
	{
		ConvertMap classMap;
		classMap.emplace(&TypeInfo<std::string*>::StaticClass, &ToString);
		return classMap;
	}
}