本文整理汇总了C#中System.GetInterfaces方法的典型用法代码示例。如果您正苦于以下问题:C# System.GetInterfaces方法的具体用法?C# System.GetInterfaces怎么用?C# System.GetInterfaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.GetInterfaces方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindIEnumerable
private static System.Type FindIEnumerable(System.Type seqType)
{
if (seqType == null || seqType == typeof(string))
return null;
if (seqType.IsArray)
return typeof(IEnumerable<>).MakeGenericType(seqType.GetElementType());
if (seqType.IsGenericType) {
foreach (System.Type arg in seqType.GetGenericArguments())
{
System.Type ienum = typeof(IEnumerable<>).MakeGenericType(arg);
if (ienum.IsAssignableFrom(seqType)) {
return ienum;
}
}
}
System.Type[] ifaces = seqType.GetInterfaces();
if (ifaces != null && ifaces.Length > 0) {
foreach (System.Type iface in ifaces)
{
System.Type ienum = FindIEnumerable(iface);
if (ienum != null) return ienum;
}
}
if (seqType.BaseType != null && seqType.BaseType != typeof(object)) {
return FindIEnumerable(seqType.BaseType);
}
return null;
}
示例2: TypeProjectItem
public TypeProjectItem(string alias, System.Type type)
: base(alias)
{
if ((type.BaseType != null) || (type.GetInterfaces().Length != 0))
{
base.SetFlags(ProjectItemFlags.NonExpandable, false);
}
this._type = type;
}
示例3: GetInterfaceProperties
private static List<PropertyInfo> GetInterfaceProperties(System.Type interfaceToReflect, List<PropertyInfo> properties)
{
var interfaces = interfaceToReflect.GetInterfaces();
foreach (var inter in interfaces)
{
properties.AddRange(GetInterfaceProperties(inter, properties));
}
properties.AddRange(interfaceToReflect.GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList());
return properties.Distinct().OrderBy(i => i.Name).ToList();
}
示例4: TryGetCollectionItemType
public static System.Type TryGetCollectionItemType(System.Type collectionType)
{
if (collectionType == null)
return null;
if (collectionType.IsInterface && IsCollectionType(collectionType))
return collectionType.GetGenericArguments().Single();
System.Type enumerableType = collectionType.GetInterfaces().FirstOrDefault(IsCollectionType);
if (enumerableType == null)
return null;
return enumerableType.GetGenericArguments().Single();
}
示例5: IsAssignableToGenericType
public static bool IsAssignableToGenericType(System.Type givenType, System.Type genericType)
{
var interfaceTypes = givenType.GetInterfaces();
foreach (var it in interfaceTypes)
if (it.IsGenericType)
if (it.GetGenericTypeDefinition() == genericType) return true;
System.Type baseType = givenType.BaseType;
if (baseType == null) return false;
return baseType.IsGenericType &&
baseType.GetGenericTypeDefinition() == genericType ||
IsAssignableToGenericType(baseType, genericType);
}
示例6: GetMethodFromInterface
private static MethodInfo GetMethodFromInterface(System.Type type, string methodName, System.Type[] parameterTypes)
{
const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly;
if (type == null)
return null;
MethodInfo method = type.GetMethod(methodName, flags, null, parameterTypes, null);
if (method == null)
{
System.Type[] interfaces = type.GetInterfaces();
foreach (var @interface in interfaces)
{
method = GetMethodFromInterface(@interface, methodName, parameterTypes);
if (method != null)
return method;
}
}
return method;
}
示例7: GetIntroducedMethods
private static MethodInfo[] GetIntroducedMethods(System.Type type, ref string[] methodAttributes)
{
BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
MethodInfo[] methods = type.GetMethods(bindingAttr);
if (!type.IsInterface)
{
methodAttributes = new string[methods.Length];
FindMethodAttributes(type, methods, ref methodAttributes, bindingAttr);
ArrayList list = new ArrayList();
foreach (System.Type type2 in type.GetInterfaces())
{
foreach (MethodInfo info in type.GetInterfaceMap(type2).TargetMethods)
{
if (!info.IsPublic && (type.GetMethod(info.Name, bindingAttr | BindingFlags.NonPublic) != null))
{
list.Add(info);
}
}
}
MethodInfo[] infoArray2 = null;
if (list.Count > 0)
{
infoArray2 = new MethodInfo[methods.Length + list.Count];
for (int i = 0; i < methods.Length; i++)
{
infoArray2[i] = methods[i];
}
for (int j = 0; j < list.Count; j++)
{
infoArray2[methods.Length + j] = (MethodInfo) list[j];
}
return infoArray2;
}
}
return methods;
}
示例8: GetIntroducedInterfaces
private static System.Type[] GetIntroducedInterfaces(System.Type type)
{
ArrayList list = new ArrayList();
foreach (System.Type type2 in type.GetInterfaces())
{
if (!type2.FullName.StartsWith("System."))
{
list.Add(type2);
}
}
System.Type[] typeArray2 = new System.Type[list.Count];
for (int i = 0; i < list.Count; i++)
{
typeArray2[i] = (System.Type) list[i];
}
return typeArray2;
}
示例9: GetSpecifications
/// <summary>
/// Finds the OPC specifications supported by the .NET server.
/// </summary>
private Specifications GetSpecifications(System.Type systemType)
{
if (systemType == null)
{
return Specifications.None;
}
Specifications specifications = Specifications.None;
foreach (System.Type interfaces in systemType.GetInterfaces())
{
if (interfaces.GUID == typeof(OpcRcw.Da.IOPCItemProperties).GUID)
{
specifications |= Specifications.DA2;
}
if (interfaces.GUID == typeof(OpcRcw.Da.IOPCBrowse).GUID)
{
specifications |= Specifications.DA3;
}
if (interfaces.GUID == typeof(OpcRcw.Ae.IOPCEventServer).GUID)
{
specifications |= Specifications.AE;
}
if (interfaces.GUID == typeof(OpcRcw.Hda.IOPCHDA_Server).GUID)
{
specifications |= Specifications.HDA;
}
}
return specifications;
}
示例10: GetAllInterfaces
private static IEnumerable<System.Type> GetAllInterfaces(System.Type currentType)
{
var interfaces = currentType.GetInterfaces();
foreach (var current in interfaces)
{
yield return current;
foreach (var @interface in GetAllInterfaces(current))
{
yield return @interface;
}
}
}
示例11: IsTypeActiveXControl
private static bool IsTypeActiveXControl(System.Type type)
{
if (IsTypeComObject(type))
{
string name = @"CLSID\{" + type.GUID.ToString() + @"}\Control";
RegistryKey key = Registry.ClassesRoot.OpenSubKey(name);
if (key == null)
{
return false;
}
key.Close();
System.Type[] interfaces = type.GetInterfaces();
if ((interfaces != null) && (interfaces.Length >= 1))
{
return true;
}
}
return false;
}
示例12: IsCollection
public static bool IsCollection(System.Type clazz)
{
bool isNonGenericCollection = Collection.superClass.IsAssignableFrom(clazz);
if (isNonGenericCollection)
{
return true;
}
Type[] types = clazz.GetInterfaces();
for (int i = 0; i < types.Length; i++)
{
//Console.WriteLine(types[i].ToString()+ " / " + types[i].FullName);
int ind = types[i].FullName.IndexOf("System.Collections.Generic.ICollection");
if ( ind != -1)
{
return true;
}
}
//return Collection.superClass.IsAssignableFrom(clazz) || CollectionGeneric.superClass.IsAssignableFrom(clazz);
return false;
}
示例13: AxWrapperGen
public AxWrapperGen(System.Type axType)
{
this.axctl = axType.Name;
this.axctl = this.axctl.TrimStart(new char[] { '_', '1' });
this.axctl = "Ax" + this.axctl;
this.clsidAx = axType.GUID;
CustomAttributeData[] attributeData = GetAttributeData(axType, typeof(ComSourceInterfacesAttribute));
if ((attributeData.Length == 0) && axType.BaseType.GUID.Equals(axType.GUID))
{
attributeData = GetAttributeData(axType.BaseType, typeof(ComSourceInterfacesAttribute));
}
if (attributeData.Length > 0)
{
CustomAttributeData data = attributeData[0];
CustomAttributeTypedArgument argument = data.ConstructorArguments[0];
string str = argument.Value.ToString();
int length = str.IndexOfAny(new char[1]);
string name = str.Substring(0, length);
this.axctlEventsType = axType.Module.Assembly.GetType(name);
if (this.axctlEventsType == null)
{
this.axctlEventsType = System.Type.GetType(name, false);
}
if (this.axctlEventsType != null)
{
this.axctlEvents = this.axctlEventsType.FullName;
}
}
System.Type[] interfaces = axType.GetInterfaces();
this.axctlType = interfaces[0];
foreach (System.Type type in interfaces)
{
if (GetAttributeData(type, typeof(CoClassAttribute)).Length > 0)
{
System.Type[] typeArray2 = type.GetInterfaces();
if ((typeArray2 != null) && (typeArray2.Length > 0))
{
this.axctl = "Ax" + type.Name;
this.axctlType = typeArray2[0];
break;
}
}
}
this.axctlIface = this.axctlType.Name;
foreach (System.Type type2 in interfaces)
{
if (type2 == typeof(IEnumerable))
{
this.enumerableInterface = true;
break;
}
}
try
{
attributeData = GetAttributeData(this.axctlType, typeof(InterfaceTypeAttribute));
if (attributeData.Length > 0)
{
CustomAttributeData data2 = attributeData[0];
CustomAttributeTypedArgument argument2 = data2.ConstructorArguments[0];
this.dispInterface = argument2.Value.Equals(ComInterfaceType.InterfaceIsIDispatch);
}
}
catch (MissingMethodException)
{
}
}
示例14: GetGetterOrNull
/// <summary>
/// Helper method to find the Property <c>get</c>.
/// </summary>
/// <param name="type">The <see cref="System.Type"/> to find the Property in.</param>
/// <param name="propertyName">The name of the mapped Property to get.</param>
/// <returns>
/// The <see cref="BasicGetter"/> for the Property <c>get</c> or <c>null</c>
/// if the Property could not be found.
/// </returns>
internal static BasicGetter GetGetterOrNull( System.Type type, string propertyName )
{
if( type==typeof( object ) || type==null )
{
// the full inheritance chain has been walked and we could
// not find the Property get
return null;
}
PropertyInfo property = type.GetProperty( propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly );
if( property != null )
{
return new BasicGetter( type, property, propertyName );
}
else
{
// recursively call this method for the base Type
BasicGetter getter = GetGetterOrNull( type.BaseType, propertyName );
// didn't find anything in the base class - check to see if there is
// an explicit interface implementation.
if( getter == null )
{
System.Type[ ] interfaces = type.GetInterfaces();
for( int i = 0; getter == null && i < interfaces.Length; i++ )
{
getter = GetGetterOrNull( interfaces[ i ], propertyName );
}
}
return getter;
}
}
示例15: GetSetterOrNull
/// <summary>
/// Helper method to find the Property <c>set</c>.
/// </summary>
/// <param name="type">The <see cref="System.Type"/> to find the Property in.</param>
/// <param name="propertyName">The name of the mapped Property to set.</param>
/// <returns>
/// The <see cref="BasicSetter"/> for the Property <c>set</c> or <see langword="null" />
/// if the Property could not be found.
/// </returns>
internal static BasicSetter GetSetterOrNull(System.Type type, string propertyName)
{
if (type == typeof(object) || type == null)
{
// the full inheritance chain has been walked and we could
// not find the Property get
return null;
}
BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
if (type.IsValueType)
{
// the BindingFlags.IgnoreCase is important here because if type is a struct, the GetProperty method does
// not ignore case by default. If type is a class, it _does_ ignore case... we're better off explicitly
// stating that casing should be ignored so we get the same behavior for both structs and classes
bindingFlags = bindingFlags | BindingFlags.IgnoreCase;
}
PropertyInfo property = type.GetProperty(propertyName, bindingFlags);
if (property != null && property.CanWrite)
{
return new BasicSetter(type, property, propertyName);
}
// recursively call this method for the base Type
BasicSetter setter = GetSetterOrNull(type.BaseType, propertyName);
// didn't find anything in the base class - check to see if there is
// an explicit interface implementation.
if (setter == null)
{
System.Type[] interfaces = type.GetInterfaces();
for (int i = 0; setter == null && i < interfaces.Length; i++)
{
setter = GetSetterOrNull(interfaces[i], propertyName);
}
}
return setter;
}