示例#1
0
        // Get a better implementation
        public Type GetDefaultType(
            Attribute attribute,
            FileAccess access,  // direction In, Out, In/Out
            Type requestedType) // combination of Cardinality and DataType.
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }
            if (requestedType == null)
            {
                requestedType = typeof(object);
            }
            var providers = this._root;

            IRuleProvider root = (IRuleProvider)providers;
            var           type = root.GetDefaultType(attribute, access, requestedType);

            if ((type == null) && (access == FileAccess.Read))
            {
                // For input bindings, if we have a specific requested type, then return and try to bind against that.
                // ITriggerBindingProvider doesn't provide rules.
                if (requestedType != typeof(object))
                {
                    return(requestedType);
                }
                else
                {
                    // common default. If binder doesn't support this, it will fail later in the pipeline.
                    return(typeof(String));
                }
            }

            if (type == null)
            {
                throw new InvalidOperationException($"Can't bind {attribute.GetType().Name} to a script-compatible type for {access} access" +
                                                    ((requestedType != null) ? $"to { requestedType.Name }." : "."));
            }
            return(type);
        }
示例#2
0
        public Type GetDefaultType(Attribute attribute, FileAccess access, Type requestedType)
        {
            TAttribute attr = attribute as TAttribute;

            if (attr == null)
            {
                return(null);
            }
            bool ok = _predicate(attr, requestedType);

            if (!ok)
            {
                return(null);
            }

            // Must apply filter
            IRuleProvider inner = _inner as IRuleProvider;

            if (inner != null)
            {
                return(inner.GetDefaultType(attribute, access, requestedType));
            }
            return(null);
        }