/// <summary> /// Determines if the container inherits the target interface or not. /// </summary> /// <param name="source">Source container to check</param> /// <param name="lookupInterface">lookup model data for the interface.</param> /// <param name="supportGenerics">Optional parameter that determines if a generic name for the interface will be checked.</param> /// <returns>Will return the interface that is either the lookup interface type, or inherits it.</returns> public static CsInterface HasInterface(this CsContainer source, ModelLookupData lookupInterface, bool supportGenerics = false) { if (source == null) { return(null); } if (lookupInterface == null) { return(null); } CsInterface result = null; if (source.ModelType == CsModelType.Interface) { CsInterface target = source as CsInterface; if (target == null) { return(null); } result = target.IsTargetInterface(lookupInterface, supportGenerics); } else { result = source.InheritedInterfaces.FirstOrDefault(i => i.HasInterface(lookupInterface, supportGenerics) != null); } return(result); }
/// <summary> /// Extension method that checks if this interface is the target type, or if it inherits it. /// </summary> /// <param name="source">Interface to check.</param> /// <param name="lookupInterface"></param> /// <param name="supportGenerics"></param> /// <returns></returns> public static CsInterface IsTargetInterface(this CsInterface source, ModelLookupData lookupInterface, bool supportGenerics = false) { if (source == null) { return(null); } if (!source.IsLoaded) { return(null); } if (source.Namespace == lookupInterface.Namespace) { if (source.Name == lookupInterface.Name) { return(source); } } return(source.InheritsInterface(lookupInterface.FullName, supportGenerics) ? source : null); }