/// <summary> /// Filters <see cref="Type"/>s based on the interfaces they implement. /// </summary> /// <param name="type">The <see cref="Type"/> to filter.</param> /// <param name="mustBeRequired">This check will only be performed with this argument matches the value of the /// <see cref="RequireInterfaces"/> property.</param> /// <returns>True if the <paramref name="type"/> should be included; false if it was filtered out.</returns> /// <exception cref="TypeFilterException"><paramref name="mustBeRequired"/> is true, <see cref="RequireInterfaces"/> /// is true, and the <paramref name="type"/> does not implement the required <see cref="Interfaces"/>.</exception> bool FilterInterfaces(Type type, bool mustBeRequired) { if (mustBeRequired != RequireInterfaces) { return(true); } if (Interfaces == null || Interfaces.Count() <= 0) { return(true); } var i = type.GetInterfaces(); var isValid = (MatchAllInterfaces ? Interfaces.All(x => i.Contains(x)) : Interfaces.Any(x => i.Contains(x))); if (!isValid) { if (RequireInterfaces) { const string errmsg = "Type `{0}` does not have the required interfaces: `{1}`."; var err = string.Format(errmsg, type, GetTypeString(Interfaces)); if (log.IsFatalEnabled) { log.Fatal(err); } throw new TypeFilterException(err); } else { return(false); } } return(true); }
protected override void ProcessRecord() { WriteVerbose(String.Format("Adding Interface: {0}", Interfaces.Count())); WriteObject(new BasicConnector(interfaces: Interfaces) { Name = Name }); }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.Append(Name); sb.AppendLine(" ( class )"); if (BaseClass != null) { sb.AppendFormat("Inherits: {0}", BaseClass.FullName); sb.AppendLine(); } if (Interfaces != null && Interfaces.Count() > 0) { sb.Append("Implements: "); foreach (var item in Interfaces) { if (item != Interfaces.First()) { sb.Append(" "); } sb.AppendLine(item.FullName); } } if (Events != null && Events.Count() > 0) { sb.Append("Events: "); foreach (var item in Events) { if (item != Events.First()) { sb.Append(" "); } sb.AppendLine(item.ToString()); } } if (Properties != null && Properties.Count() > 0) { sb.Append("Properties: "); foreach (var item in Properties) { if (item != Properties.First()) { sb.Append(" "); } sb.AppendLine(item.ToString()); } } if (Methods != null && Methods.Count() > 0) { sb.Append("Methods: "); foreach (var item in Methods) { if (item != Methods.First()) { sb.Append(" "); } sb.AppendLine(item.ToString()); } } return(sb.ToString()); }