Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Operator"/> class.
        /// </summary>
        /// <param name="descriptor">Can be <see langword="null"/>.</param>
        /// <param name="inputCount"></param>
        /// <param name="outputCount"></param>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="descriptor"/> is <see langword="null"/>.</para>
        /// </exception>
        public Operator(OperatorDescriptor descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException("descriptor");
            }

            _descriptor = descriptor;
            Name        = Header = _descriptor.Name;

            CreateOutputs(descriptor.OutputParameterCount);
            Object defaultOutputValue = NuGenActivator.CreateObject(descriptor.GetOutputParameter().ParameterType);

            SetOutput(0, "Result", defaultOutputValue);

            CreateInputs(descriptor.InputParameterCount);
            ParameterInfo[] inputParameters = descriptor.GetInputParameters();

            for (int i = 0; i < descriptor.InputParameterCount; i++)
            {
                Object defaultInputValue = NuGenActivator.CreateObject(inputParameters[i].ParameterType);
                SetInput(i, inputParameters[i].Name, defaultInputValue);
            }
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Operator"/> class.
		/// </summary>
		/// <param name="descriptor">Can be <see langword="null"/>.</param>
		/// <param name="inputCount"></param>
		/// <param name="outputCount"></param>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="descriptor"/> is <see langword="null"/>.</para>
		/// </exception>
		public Operator(OperatorDescriptor descriptor)
		{
			if (descriptor == null)
			{
				throw new ArgumentNullException("descriptor");
			}

			_descriptor = descriptor;
			Name = Header = _descriptor.Name;

			CreateOutputs(descriptor.OutputParameterCount);
			Object defaultOutputValue = NuGenActivator.CreateObject(descriptor.GetOutputParameter().ParameterType);

			SetOutput(0, "Result", defaultOutputValue);

			CreateInputs(descriptor.InputParameterCount);
			ParameterInfo[] inputParameters = descriptor.GetInputParameters();

			for (int i = 0; i < descriptor.InputParameterCount; i++)
			{
				Object defaultInputValue = NuGenActivator.CreateObject(inputParameters[i].ParameterType);
				SetInput(i, inputParameters[i].Name, defaultInputValue);
			}
		}
Ejemplo n.º 3
0
		public void OperatorDescriptorCtorArgumentNullException()
		{
			OperatorDescriptor descriptor = null;
			MethodInfo mi = typeof(Object).GetMethod("ToString");
			Assert.IsNotNull(mi);

			try
			{
				descriptor = new OperatorDescriptor(mi, null, "stringRepresentation", 0, PrimitiveOperator.No);
				Assert.Fail();
			}
			catch (ArgumentNullException)
			{
			}

			try
			{
				descriptor = new OperatorDescriptor(mi, "", "stringRepresentation", 0, PrimitiveOperator.No);
				Assert.Fail();
			}
			catch (ArgumentNullException)
			{
			}

			try
			{
				descriptor = new OperatorDescriptor(mi, "name", null, 0, PrimitiveOperator.No);
				Assert.Fail();
			}
			catch (ArgumentNullException)
			{
			}

			try
			{
				descriptor = new OperatorDescriptor(mi, "name", "", 0, PrimitiveOperator.No);
				Assert.Fail();
			}
			catch (ArgumentNullException)
			{
			}

			try
			{
				descriptor = new OperatorDescriptor(null, "name", "representation", 0, PrimitiveOperator.No);
				Assert.Fail();
			}
			catch (ArgumentNullException)
			{
			}
		}
Ejemplo n.º 4
0
		private void AddOperator(OperatorDescriptor operatorDescriptor)
		{
			TreeNode node = new TreeNode(operatorDescriptor.ToString());
			node.Tag = operatorDescriptor;
			_operatorNode.Nodes.Add(node);
		}
Ejemplo n.º 5
0
		private void LoadOperators()
		{
			Dictionary<String, OperatorDescriptor> operators = OperatorsCache.Operators;
			OperatorDescriptor[] operatorsToSort = new OperatorDescriptor[operators.Values.Count];
			operators.Values.CopyTo(operatorsToSort, 0);

			Array.Sort<OperatorDescriptor>(operatorsToSort, new OperatorDescriptorComparer());

			foreach (OperatorDescriptor descriptor in operatorsToSort)
			{
				AddOperator(descriptor);
			}

			_operatorNode.Expand();
		}