public override bool Matches( Type returnType, ParameterInfo[] parameters, DefinitionAttribute attribute, IDictionary <string, Type> aliases) { if (typeof(Promise).IsAssignableFrom(returnType)) { var promiseType = returnType.GetOpenTypeConformance(typeof(Promise <>)); returnType = promiseType != null ? promiseType.GetGenericArguments()[0] : typeof(object); } else if (typeof(Task).IsAssignableFrom(returnType)) { var taskType = returnType.GetOpenTypeConformance(typeof(Task <>)); returnType = taskType != null ? taskType.GetGenericArguments()[0] : typeof(object); } else if (_required) { return(false); } return(base.Matches(returnType, parameters, attribute, aliases)); }
public override bool Matches( Type returnType, ParameterInfo[] parameters, DefinitionAttribute attribute, IDictionary <string, Type> aliases) { return(Rule.Matches(returnType, parameters, attribute, aliases)); }
public override bool Matches( Type returnType, ParameterInfo[] parameters, DefinitionAttribute attribute, IDictionary <string, Type> aliases) { return(returnType.IsClassOf(_type)); }
public override bool Matches( ParameterInfo parameter, DefinitionAttribute attribute, IDictionary <string, Type> aliases) { var paramType = parameter.ParameterType; return(typeof(IHandler).IsAssignableFrom(paramType)); }
public override PolicyMethodBinding BindMethod( MethodRule rule, MethodDispatch dispatch, DefinitionAttribute attribute) { var binding = base.BindMethod(rule, dispatch, attribute); InferVariance(binding); return(binding); }
public void fillComponents(DataGridView grid) { grid.Rows.Clear(); foreach (IComponent c in Loader.Soba.Registered) { Type type = c.GetType(); if (!Inspector.IsComponent(type)) { continue; } bool enabled = c.Enabled; string className = c.GetType().Name; Component v = SlnEvents.Components?.FirstOrDefault(p => p.ClassName == className); if (v != null) { enabled = v.Enabled; } cInfo[className] = new List <INodeInfo>(); bool withoutAttr = true; foreach (Attribute attr in type.GetCustomAttributes(true)) { if (attr.GetType() == typeof(ComponentAttribute) || attr.GetType() == typeof(DefinitionAttribute)) { withoutAttr = false; } if (attr.GetType() == typeof(ComponentAttribute) && ((ComponentAttribute)attr).Parent == null) { fillComponents((ComponentAttribute)attr, enabled, className, grid); } else if (attr.GetType() == typeof(DefinitionAttribute) && ((DefinitionAttribute)attr).Parent == null) { DefinitionAttribute def = (DefinitionAttribute)attr; grid.Rows.Add(DomIcon.definition, enabled, def.Name, className, def.Description); } else if (((DefinitionAttribute)attr).Parent != null) { cInfo[className].Add(new NodeInfo((DefinitionAttribute)attr)); } else if (((ComponentAttribute)attr).Parent != null) { cInfo[className].Add(new NodeInfo((ComponentAttribute)attr)); } } if (withoutAttr) { grid.Rows.Add(DomIcon.package, enabled, String.Empty, className, String.Empty); } cInfo[className].AddRange(new List <INodeInfo>(domElemsBy(className))); } grid.Sort(grid.Columns[2], System.ComponentModel.ListSortDirection.Descending); }
public static bool TryGetDefinition(this PropertyInfo property, out string definition) { definition = null; DefinitionAttribute def = property.GetCustomAttribute <DefinitionAttribute>(); if (def.Exists()) { definition = def.Definition; return(true); } return(false); }
public PolicyMethodBinding Bind(MethodDispatch dispatch, DefinitionAttribute attribute) { var binding = _binder(this, dispatch, attribute); _returnValue?.Configure(binding); var parameters = dispatch.Method.GetParameters(); for (var i = 0; i < parameters.Length; ++i) { _args[i].Configure(parameters[i], binding); } return(binding); }
public override bool Matches( ParameterInfo parameter, DefinitionAttribute attribute, IDictionary <string, Type> aliases) { var paramType = parameter.ParameterType; if (typeof(Res).IsAssignableFrom(paramType)) { if (_alias != null) { aliases.Add(_alias, paramType); } return(true); } return(false); }
public PolicyMethodBinding(MethodRule rule, MethodDispatch dispatch, DefinitionAttribute attribute, CallbackPolicy policy) : base(dispatch) { if (rule == null) { throw new ArgumentNullException(nameof(rule)); } if (dispatch == null) { throw new ArgumentNullException(nameof(dispatch)); } Rule = rule; Attribute = attribute; Policy = policy; }
public bool Matches(MethodInfo method, DefinitionAttribute attribute) { var parameters = method.GetParameters(); var paramCount = parameters.Length; var aliases = new Dictionary <string, Type>(); if (paramCount < _minArgs || paramCount > _args.Length || !parameters.Zip(_args, (param, arg) => arg.Matches(param, attribute, aliases)) .All(m => m)) { return(false); } if (_returnValue?.Matches(method.ReturnType, parameters, attribute, aliases) == false) { throw new InvalidOperationException( $"Method '{method.GetDescription()} satisfied the arguments but rejected the return'"); } return(true); }
public override bool Matches( ParameterInfo parameter, DefinitionAttribute attribute, IDictionary <string, Type> aliases) { var paramType = parameter.ParameterType; if (_type.IsAssignableFrom(paramType)) { if (_aliases != null && _aliases.Length > 0) { throw new InvalidOperationException( $"{_type.FullName} is not a generic definition and cannot bind aliases"); } return(base.Matches(parameter, attribute, aliases)); } var openGeneric = paramType.GetOpenTypeConformance(_type); if (openGeneric == null) { return(false); } if (_aliases == null || _aliases.Length == 0) { return(true); } var genericArgs = openGeneric.GetGenericArguments(); if (_aliases.Length > genericArgs.Length) { throw new InvalidOperationException( $"{_type.FullName} has {genericArgs.Length} generic args, but {_aliases.Length} requested"); } for (var i = 0; i < _aliases.Length; ++i) { var alias = _aliases[i]; if (!string.IsNullOrEmpty(alias)) { aliases.Add(_aliases[i], genericArgs[i]); } } return(base.Matches(parameter, attribute, aliases)); }
public override bool Matches( ParameterInfo parameter, DefinitionAttribute attribute, IDictionary <string, Type> aliases) { var paramType = parameter.ParameterType; if (typeof(Cb).IsAssignableFrom(paramType)) { return(false); } if (paramType.IsGenericParameter) { var contraints = paramType.GetGenericParameterConstraints(); switch (contraints.Length) { case 0: paramType = typeof(object); break; case 1: paramType = contraints[0]; break; default: return(false); } } var restrict = attribute.Key as Type; if (restrict == null || restrict.IsAssignableFrom(paramType) || paramType.IsAssignableFrom(restrict)) { if (_alias != null) { aliases.Add(_alias, paramType); } return(true); } throw new InvalidOperationException( $"Key {restrict.FullName} is not related to {paramType.FullName}"); }
public override bool Matches( Type returnType, ParameterInfo[] parameters, DefinitionAttribute attribute, IDictionary <string, Type> aliases) { if (IsLogicalVoid(returnType)) { return(false); } if (returnType.IsArray) { returnType = returnType.GetElementType(); } var restrict = attribute.Key as Type; if (restrict == null || restrict.IsAssignableFrom(returnType) || returnType.IsAssignableFrom(restrict)) { return(true); } throw new InvalidOperationException( $"Key {restrict.FullName} is not related to {returnType.FullName}"); }
/// <summary> Write a Definition XML Element from attributes in a member. </summary> public virtual void WriteDefinition(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, DefinitionAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass) { writer.WriteStartElement( "definition" ); // Attribute: <class> writer.WriteAttributeString("class", attribute.Class==null ? DefaultHelper.Get_Definition_Class_DefaultValue(member) : GetAttributeValue(attribute.Class, mappedClass)); WriteUserDefinedContent(writer, member, null, attribute); System.Collections.ArrayList memberAttribs = GetSortedAttributes(member); int attribPos; // Find the position of the DefinitionAttribute (its <sub-element>s must be after it) for(attribPos=0; attribPos<memberAttribs.Count; attribPos++) if( memberAttribs[attribPos] is DefinitionAttribute && ((BaseAttribute)memberAttribs[attribPos]).Position == attribute.Position ) break; // found int i = attribPos + 1; // Element: <param> for(; i<memberAttribs.Count; i++) { BaseAttribute memberAttrib = memberAttribs[i] as BaseAttribute; if( IsNextElement(memberAttrib, parentAttribute, attribute.GetType()) || IsNextElement(memberAttrib, attribute, typeof(ParamAttribute)) ) break; // next attributes are 'elements' of the same level OR for 'sub-elements' else { if( memberAttrib is DefinitionAttribute ) break; // Following attributes are for this Definition if( memberAttrib is ParamAttribute ) WriteParam(writer, member, memberAttrib as ParamAttribute, attribute, mappedClass); } } WriteUserDefinedContent(writer, member, typeof(ParamAttribute), attribute); writer.WriteEndElement(); }
public virtual PolicyMethodBinding BindMethod(MethodRule rule, MethodDispatch dispatch, DefinitionAttribute attribute) { return(Binder?.Invoke(rule, dispatch, attribute, this) ?? new PolicyMethodBinding(rule, dispatch, attribute, this)); }
public abstract bool Matches( Type returnType, ParameterInfo[] parameters, DefinitionAttribute attribute, IDictionary <string, Type> aliases);
public abstract bool Matches( ParameterInfo parameter, DefinitionAttribute attribute, IDictionary <string, Type> aliases);
/// <summary> Write a Definition XML Element from attributes in a member. </summary> public virtual void WriteDefinition(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, DefinitionAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass) { writer.WriteStartElement( "definition" ); // Attribute: <class> writer.WriteAttributeString("class", attribute.Class==null ? DefaultHelper.Get_Definition_Class_DefaultValue(member) : GetAttributeValue(attribute.Class, mappedClass)); WriteUserDefinedContent(writer, member, null, attribute); writer.WriteEndElement(); }
public override bool Matches( ParameterInfo parameter, DefinitionAttribute attribute, IDictionary <string, Type> aliases) { return(Argument.Matches(parameter, attribute, aliases)); }
public MethodRule MatchMethod(MethodInfo method, DefinitionAttribute attribute) { return(_rules.FirstOrDefault(r => r.Matches(method, attribute))); }
/// <param name="attr">Attribute of property</param> /// <param name="displaying">Displays element over the 'Name' property</param> public NodeInfo(DefinitionAttribute attr, string displaying = null) : this(attr.Name, attr.Description, new NodeIdent(attr.Name, null), InfoType.Definition, displaying) { }