本文整理汇总了C#中System.Type.FindInterfaces方法的典型用法代码示例。如果您正苦于以下问题:C# Type.FindInterfaces方法的具体用法?C# Type.FindInterfaces怎么用?C# Type.FindInterfaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.FindInterfaces方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TypesToGenerateForType
public static IEnumerable<Type> TypesToGenerateForType(Type type)
{
foreach (var interfaceType in type.FindInterfaces((ignored, data) => true, null))
{
yield return interfaceType;
}
yield return type;
}
示例2: RoleSet
public RoleSet(Type _Class)
{
TypeFilter filter = new TypeFilter(RoleFilter);
Type[] Roles = _Class.FindInterfaces(filter, (object)__RoleTypes);
_Set = new HashSet<Type>();
foreach (Type r in Roles) {
_Set.Add(r);
}
}
示例3: TypeImplementsInterface
public static bool TypeImplementsInterface(Type type, Type typeToImplement)
{
Type[] interfaces = type.FindInterfaces(
(typ, obj) => typ == typeToImplement,
type);
if (interfaces != null && interfaces.Length > 0)
return true;
return false;
}
示例4: InterfacePresentInType
/// <summary>
/// InterfacePresentInClass check that an inteface is implimented for the specific dll type
/// </summary>
/// <param name="checkType">The type to check i.e the class</param>
/// <param name="compareType">The interface type</param>
/// <returns>Returns true if the interface is implemented in the class</returns>
public static bool InterfacePresentInType(Type checkType, Type compareType)
{
TypeFilter interfaceFilter = InterfaceFilter;
Type[] list = checkType.FindInterfaces(interfaceFilter, compareType);
if (list != null && list.Length > 0)
return true;
return false;
}
示例5: FindCollectionInterface
private static Type FindCollectionInterface(Type type)
{
Type[] array = type.FindInterfaces(new TypeFilter(CollectionUtils.IsCollectionInterface), null);
if (array.Length == 1)
{
return array[0];
}
return null;
}
示例6: ElementType
private static Type ElementType(Type collectionType)
{
Debug.Assert(collectionType != null);
Debug.Assert(typeof(IEnumerable).IsAssignableFrom(collectionType));
Type[] stronglyTypedInterfaces = collectionType.FindInterfaces((m, c) => m.IsConstructedGenericType && m.GetGenericTypeDefinition() == typeof(IEnumerable<>), null);
if (stronglyTypedInterfaces == null || stronglyTypedInterfaces.Length == 0 || stronglyTypedInterfaces.Length > 1)
{
return null; // not a strongly typed collection, or a strongly typed collection of more than one thing (yikes)
}
return stronglyTypedInterfaces[0].GetGenericArguments()[0];
}
示例7: GetInterfaceType
private Type GetInterfaceType(Type type)
{
lock (_cacheLock)
{
Type interfaceType;
if (!_cache.TryGetValue(type, out interfaceType))
{
_cache[type] = interfaceType = type.FindInterfaces((t, o) => ((Type[])o).All(c => t == c || !t.IsAssignableFrom(c)), type.GetInterfaces()).Single();
}
return interfaceType;
}
}
示例8: FindGenericInterface
public static Type FindGenericInterface(Type gType, Type gInterface)
{
// maybe gType is generic interface?
if (gType.IsGenericType && gType.GetGenericTypeDefinition() == gInterface)
return gType;
string interfaceName = gInterface.Name;
Type[] foundInterfaces = gType.FindInterfaces(Module.FilterTypeName, interfaceName);
if (foundInterfaces != null)
for (int i = 0; i < foundInterfaces.Length; i++) {
Type deff = foundInterfaces[i].GetGenericTypeDefinition();
if (deff == gInterface)
return foundInterfaces[i];
}
return null;
}
示例9: IsCollectionType
/// <summary>
/// true if type is array, IEnumerable, etc
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static bool IsCollectionType(Type type)
{
if (type.IsArray) return true;
if (type == typeof(IList)) return true;
if (type == typeof(string)) return false;
if (type.IsGenericType)
{
if (type.GetGenericTypeDefinition() == typeof (IEnumerable<>)) return true;
var types = type.FindInterfaces((typ, cri) => (
typ.IsGenericType && typ.GetGenericTypeDefinition() == typeof(IEnumerable<>)), null);
return types.Length != 0;
}
return false;
}
示例10: GetProperties
public static PropertyInfo[] GetProperties(Type IType, Type clazz)
{
PropertyInfo[] pi = IType.GetProperties();
Type[] interfaces = clazz.FindInterfaces(new TypeFilter(MyInterfaceFilter), IType);
if (interfaces.Length == 0)
return pi;
PropertyInfo[] piChild = interfaces[0].GetProperties();
if (piChild.Length == 0)
return pi;
PropertyInfo[] res = new PropertyInfo[pi.Length + piChild.Length];
pi.CopyTo(res, 0);
piChild.CopyTo(res, pi.Length);
return res;
}
示例11: CollectMethodsToProxy
protected void CollectMethodsToProxy(ArrayList methodList, Type type, bool onlyVirtuals)
{
CollectMethods(methodList, type, onlyVirtuals);
if (type.IsInterface)
{
Type[] typeChain = type.FindInterfaces(new TypeFilter(NoFilter), null);
foreach(Type interType in typeChain)
{
CollectMethods(methodList, interType, onlyVirtuals);
}
}
}
示例12: GetGenericInterfaceElementType
/// <summary>
/// Returns the "T" in the IQueryable of T implementation of type.
/// </summary>
/// <param name="type">Type to check.</param>
/// <param name="typeFilter">filter against which the type is checked</param>
/// <returns>
/// The element type for the generic IQueryable interface of the type,
/// or null if it has none or if it's ambiguous.
/// </returns>
internal static Type GetGenericInterfaceElementType(Type type, TypeFilter typeFilter)
{
Debug.Assert(type != null, "type != null");
Debug.Assert(!type.IsGenericTypeDefinition, "!type.IsGenericTypeDefinition");
if (typeFilter(type, null))
{
return type.GetGenericArguments()[0];
}
Type[] queriables = type.FindInterfaces(typeFilter, null);
if (queriables != null && queriables.Length == 1)
{
return queriables[0].GetGenericArguments()[0];
}
else
{
return null;
}
}
示例13: FindInterfaceMethod
private static MethodInfo FindInterfaceMethod( Type targetType, Type interfaceType, string name, Type[] parameterTypes )
{
if ( targetType.GetIsInterface() )
{
return targetType.FindInterfaces( ( type, _ ) => type == interfaceType, null ).Single().GetMethod( name, parameterTypes );
}
var map = targetType.GetInterfaceMap( interfaceType );
#if !SILVERLIGHT
int index = Array.FindIndex( map.InterfaceMethods, method => method.Name == name && method.GetParameters().Select( p => p.ParameterType ).SequenceEqual( parameterTypes ) );
#else
int index = map.InterfaceMethods.FindIndex( method => method.Name == name && method.GetParameters().Select( p => p.ParameterType ).SequenceEqual( parameterTypes ) );
#endif
if ( index < 0 )
{
#if DEBUG
Contract.Assert( false, interfaceType + "::" + name + "(" + String.Join( ", ", parameterTypes.Select( t => t.ToString() ).ToArray() ) + ") is not found in " + targetType );
#endif
return null;
}
else
{
return map.TargetMethods[ index ];
}
}
示例14: FindConstructionOfGenericInterfaceDefinition
/// <summary>
/// Finds and returns the constructed type of an interface
/// generic type definition if the type implements it. Otherwise
/// returns a <c>null</c> reference.
/// </summary>
/// <exception cref="System.ArgumentNullException">
/// Either <paramref name="type"/> or <paramref name="genericTypeDefinition"/>
/// is a null reference.
/// </exception>
internal static Type FindConstructionOfGenericInterfaceDefinition(Type type, Type genericTypeDefinition)
{
if (type == null) throw new ArgumentNullException("type");
if (genericTypeDefinition == null) throw new ArgumentNullException("genericTypeDefinition");
Type[] interfaces = type.FindInterfaces(new TypeFilter(IsConstructionOfGenericInterfaceDefinition), genericTypeDefinition);
return interfaces.Length == 0 ? null : interfaces[0];
}
示例15: Select
/// <summary>
/// Selects the range of all the lists that are keyed on the type
/// name given or the name of any parent class or interface. For
/// example, giving typeof(string) will return any for
/// "System.String" or "System.Object" and so on.
/// </summary>
public IList Select(Type type)
{
// Create a list
ArrayList list = new ArrayList();
// Ignore nulls (since that happens at the top-most object)
if (type == null)
return list;
// Add this type's keys
IList l = (IList) lists[type.FullName];
if (l != null)
list.AddRange(l);
// Add the base types
list.AddRange(Select(type.BaseType));
// Add the interfaces, if any
Type [] interfaces
= type.FindInterfaces(new TypeFilter(FindAllTypes), null);
foreach (Type iType in interfaces)
list.AddRange(Select(iType));
// Return the list
return list;
}