Example #1
0
        /// <summary>
        /// Returns true if this implements given DaggerInterface
        /// </summary>
        /// <param name="daggerInterface"></param>
        /// <returns></returns>
        public bool Implements(DaggerInterface daggerInterface)
        {
            foreach (DaggerInterfacePin pin in daggerInterface._inputPins)
            {
                // find the input pin by name
                DaggerInterfacePin foundPin = GetInputPin(pin.PinName);
                if (foundPin == null)
                {
                    return(false);
                }

                // check type compatiblity
                if (!((foundPin.PinDataType.IsAssignableFrom(pin.PinDataType)) || pin.PinDataType.IsAssignableFrom(foundPin.PinDataType)))
                {
                    TypeConverter tc = TypeDescriptor.GetConverter(foundPin.PinDataType);
                    if (tc != null)
                    {
                        if (!tc.CanConvertFrom(foundPin.PinDataType))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            foreach (DaggerInterfacePin pin in daggerInterface._outputPins)
            {
                // find the output pin by name
                DaggerInterfacePin foundPin = GetOutputPin(pin.PinName);
                if (foundPin == null)
                {
                    return(false);
                }

                // check type compatibility
                if (!((foundPin.PinDataType.IsAssignableFrom(pin.PinDataType)) || pin.PinDataType.IsAssignableFrom(foundPin.PinDataType)))
                {
                    TypeConverter tc = TypeDescriptor.GetConverter(foundPin.PinDataType);
                    if (tc != null)
                    {
                        return(tc.CanConvertFrom(foundPin.PinDataType));
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #2
0
        public static DaggerInterface operator +(DaggerInterface dx, DaggerInterface dy)
        {
            // create a new temp interface
            DaggerInterface newinterface = new DaggerInterface(dx);

            // merge the pins with the second
            foreach (DaggerInterfacePin pin in dy._inputPins)
            {
                newinterface.AddInputPin(pin);
            }
            foreach (DaggerInterfacePin pin in dy._outputPins)
            {
                newinterface.AddOutputPin(pin);
            }

            return(newinterface);
        }
Example #3
0
 /// <summary>
 /// Construct a new DaggerInterface from an exisiting one
 /// </summary>
 /// <param name="daggerInterface"></param>
 public DaggerInterface(DaggerInterface daggerInterface)
 {
     // we can create lists directly from the daggerInterface because the Pins properties are already deep copies
     _inputPins  = new List <DaggerInterfacePin>(daggerInterface.InputPins);
     _outputPins = new List <DaggerInterfacePin>(daggerInterface.OutputPins);
 }