コード例 #1
0
        public ArithmeticOperation Get(int operation, BaseTypes left, BaseTypes right)
        {
            var key = new ArithmeticOpKey(operation, left, right);

            if (!ArithmeticOperations.TryGetValue(key, out var op))
            {
                throw new ArgumentException(
                          $"Cannot find operation {OberonGrammarLexer.DefaultVocabulary.GetDisplayName(operation)} ({left:G}, {right:G})");
            }

            return(op);
        }
コード例 #2
0
        private ExpressionRepository()
        {
            var configuration = new ContainerConfiguration().WithAssembly(typeof(IArithmeticOperation).Assembly);
            var container     = configuration.CreateContainer();
            var operations    = container.GetExports <ExportFactory <IArithmeticOperation, ArithmeticOpMetadata> >();

            // translate all arithmetic operations to a dictionary
            ArithmeticOperations = new Dictionary <ArithmeticOpKey, ArithmeticOperation>();
            foreach (var mefArithmeticOperation in operations)
            {
                var key = new ArithmeticOpKey(
                    mefArithmeticOperation.Metadata.Operation,
                    mefArithmeticOperation.Metadata.LeftHandType,
                    mefArithmeticOperation.Metadata.RightHandType,
                    mefArithmeticOperation.Metadata.ResultType);
                ArithmeticOperations.Add(
                    key,
                    new ArithmeticOperation(mefArithmeticOperation.CreateExport().Value, key));
            }
        }