/// <summary> /// Gets the compiler associated to an <see cref="Asset"/> type. /// </summary> /// <param name="type">The type of the <see cref="Asset"/></param> /// <param name="context"></param> /// <returns>The compiler associated the provided asset type or null if no compiler exists for that type.</returns> public IAssetCompiler GetCompiler(Type type, Type context) { AssertAssetType(type); EnsureTypes(); var typeData = new CompilerTypeData { Context = context, Type = type }; IAssetCompiler compiler; if (!typeToCompiler.TryGetValue(typeData, out compiler)) { //support nested context types! if (context.BaseType != typeof(object)) { return(GetCompiler(type, context.BaseType)); } compiler = DefaultCompiler; } return(compiler); }
/// <summary> /// Register a compiler for a given <see cref="Asset"/> type. /// </summary> /// <param name="type">The type of asset the compiler can compile</param> /// <param name="compiler">The compiler to use</param> /// <param name="context"></param> public void RegisterCompiler(Type type, IAssetCompiler compiler, Type context) { if (compiler == null) { throw new ArgumentNullException(nameof(compiler)); } AssertAssetType(type); var typeData = new CompilerTypeData(context, type); typeToCompiler[typeData] = compiler; }