// 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; IBindingRuleProvider root = (IBindingRuleProvider)providers; var type = root.GetDefaultType(attribute, access, requestedType); if (type == null) { if (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); } } // IBindingProvider does not provide rules. Attempt to use IAsyncCollector<string>. if (access == FileAccess.Write) { return typeof(IAsyncCollector<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; }
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 IBindingRuleProvider inner = _inner as IBindingRuleProvider; if (inner != null) { return(inner.GetDefaultType(attribute, access, requestedType)); } return(null); }