Exemplo n.º 1
0
        public override bool CanCreate(IOBuildContext context)
        {
            var ioType    = context.IOType;
            var dataType  = context.DataType;
            var attribute = context.IOAttribute;

            if (dataType != null)
            {
                var baseType = dataType.BaseType;
                if (baseType != null && baseType == typeof(Enum))
                {
                    var openIOType = ioType.GetGenericTypeDefinition();
                    if (attribute is InputAttribute)
                    {
                        return(FInputDelegates.ContainsKey(openIOType));
                    }
                    if (attribute is OutputAttribute)
                    {
                        return(FOutputDelegates.ContainsKey(openIOType));
                    }
                    if (attribute is ConfigAttribute)
                    {
                        return(FConfigDelegates.ContainsKey(openIOType));
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public override bool CanCreate(IOBuildContext context)
        {
            // In case of multidimensional streams we're only interested in:
            // * IInStream<IEnumerable<T>>, IInStream<Spread<T>>
            // * IOutStream<Spread<T>>
            var ioType = context.IOType;

            if (ioType.IsGenericType)
            {
                var genericArgument = ioType.GetGenericArguments()[0];
                if (genericArgument.IsGenericType)
                {
                    var attribute  = context.IOAttribute;
                    var openIOType = ioType.GetGenericTypeDefinition();
                    if (openIOType == typeof(IInStream <>) && attribute.IsBinSizeEnabled)
                    {
                        var genericTypeDefinition = genericArgument.GetGenericTypeDefinition();
                        return(genericTypeDefinition == typeof(IEnumerable <>) ||
                               genericTypeDefinition == typeof(global::VL.Lib.Collections.Spread <>) ||
                               genericArgument == typeof(IResourceProvider <Stream>));
                    }
                    if (openIOType == typeof(IOutStream <>) && attribute.IsBinSizeEnabled)
                    {
                        var genericTypeDefinition = genericArgument.GetGenericTypeDefinition();
                        return(genericTypeDefinition == typeof(global::VL.Lib.Collections.Spread <>) ||
                               genericArgument == typeof(IResourceProvider <Stream>));
                    }
                    return(false);
                }
                else
                {
                    // We do not want IInStream<> and IOutStream<> to match.
                    switch (context.Direction)
                    {
                    case PinDirection.Input:
                        return(FInputDelegates.ContainsKey(ioType));

                    case PinDirection.Output:
                        return(FOutputDelegates.ContainsKey(ioType));

                    default:
                        return(false);
                    }
                }
            }
            return(false);
        }