internal static IInstruction CompileInstruction(string opcode, params string[] operands) { IInstructionWithOperand instruction = null; #region TASK 1 & TASK 6 EXTENSION - TO BE IMPLEMENTED BY THE STUDENT List <Type> types = GetTypesFromSVMAssembly(opcode); types.AddRange(GetTypesFromDLLs(opcode)); // types.AddRange(GetUntrustedTypes(opcode)); foreach (Type type in types) { object instance = Activator.CreateInstance(type); if (instance is IInstructionWithOperand) { instruction = instance as IInstructionWithOperand; instruction.Operands = operands; } else { throw new SvmCompilationException(); } } #endregion TASK 1 & TASK 6 EXTENSION - TO BE IMPLEMENTED BY THE STUDENT return(instruction); }
internal static IInstruction CompileInstruction(string opcode, params string[] operands) { bool verification = false; IInstructionWithOperand instruction = null; var myAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList(); var files = Directory.GetFiles(System.Environment.CurrentDirectory, "*.dll").ToList(); try { foreach (var current in files) { if (StrongNameSignatureVerificationEx(current, true, ref verification)) { myAssemblies.Add(Assembly.LoadFrom(current)); } } } catch { // Ignores the fact it cant load .NET assembly } foreach (Assembly currentassembly in myAssemblies) { Type[] types = currentassembly.GetTypes(); foreach (Type currentype in types) { if (currentype.Name.ToLower() == opcode.ToLower()) { //typed.MyFunction(); instruction = (IInstructionWithOperand)Activator.CreateInstance(currentype); instruction.Operands = operands; return(instruction); } } } #region TASK 1 - TO BE IMPLEMENTED BY THE STUDENT #endregion throw new SvmCompilationException(); }