本文整理汇总了C#中System.Type.IsInterface方法的典型用法代码示例。如果您正苦于以下问题:C# Type.IsInterface方法的具体用法?C# Type.IsInterface怎么用?C# Type.IsInterface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.IsInterface方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsGenericTypeOf
public static bool IsGenericTypeOf(this Type t, Type genericDefinition, out Type[] genericParameters)
{
genericParameters = new Type[] { };
if (!genericDefinition.IsGenericType())
{
return false;
}
var isMatch = t.IsGenericType() && t.GetGenericTypeDefinition() == genericDefinition.GetGenericTypeDefinition();
if (!isMatch && t.GetBaseType() != null)
{
isMatch = IsGenericTypeOf(t.GetBaseType(), genericDefinition, out genericParameters);
}
if (!isMatch && genericDefinition.IsInterface() && t.GetInterfaces().Any())
{
foreach (var i in t.GetInterfaces())
{
if (i.IsGenericTypeOf(genericDefinition, out genericParameters))
{
isMatch = true;
break;
}
}
}
if (isMatch && !genericParameters.Any())
{
genericParameters = t.GetGenericArguments();
}
return isMatch;
}
示例2: ToClass
public static RubyClass ToClass(RubyContext/*!*/ context, Type/*!*/ self)
{
if (self.IsInterface()) {
RubyExceptions.CreateTypeError("Cannot convert a CLR interface to a Ruby class");
}
return context.GetClass(self);
}
示例3: CreateDictionary
public static object CreateDictionary(Type dictionaryType, Type keyType, Type valueType)
{
var type = dictionaryType.IsInterface()
? typeof (Dictionary<,>).MakeGenericType(keyType, valueType)
: dictionaryType;
return CreateObject(type);
}
示例4: CreateObject
public static object CreateObject(Type type)
{
return type.IsArray
? CreateArray(type.GetElementType(), 0)
: type == typeof (string)
? null
: type.IsInterface() && type.IsDictionaryType()
? CreateDictionary(type)
: DelegateFactory.CreateCtor(type)();
}
示例5: CreateDictionary
public static object CreateDictionary(Type dictionaryType)
{
Type keyType = dictionaryType.GetTypeInfo().GenericTypeArguments[0];
Type valueType = dictionaryType.GetTypeInfo().GenericTypeArguments[1];
var type = dictionaryType.IsInterface()
? typeof (Dictionary<,>).MakeGenericType(keyType, valueType)
: dictionaryType;
return DelegateFactory.CreateCtor(type)();
}
示例6: IsPrimitiveOrClass
private bool IsPrimitiveOrClass(Type type)
{
if ((type.IsPrimitive() && type != typeof(IntPtr)))
{
return true;
}
return ((type.IsClass() || type.IsInterface()) &&
type.IsGenericParameter == false &&
type.IsByRef == false);
}
示例7: AddEmptyInterface
public void AddEmptyInterface(Type @interface)
{
DebugExtender.Assert(@interface != null, "@interface == null", "Shouldn't be adding empty interfaces...");
DebugExtender.Assert(@interface.IsInterface(), "@interface.IsInterface()", "Should be adding interfaces only...");
DebugExtender.Assert(!interfaces.Contains(@interface), "!interfaces.Contains(@interface)",
"Shouldn't be adding same interface twice...");
DebugExtender.Assert(!empty.Contains(@interface), "!empty.Contains(@interface)",
"Shouldn't be adding same interface twice...");
empty.Add(@interface);
}
示例8: GetTryConvertReturnValue
/// <summary>
/// Returns a value which indicates failure when a OldConvertToAction of ImplicitTry or
/// ExplicitTry.
/// </summary>
public static Expression GetTryConvertReturnValue(Type type)
{
Expression res;
if (type.IsInterface() || type.IsClass()) {
res = AstUtils.Constant(null, type);
} else {
res = AstUtils.Constant(null);
}
return res;
}
示例9: GetImplementedInterfaces
public static IEnumerable<Type> GetImplementedInterfaces(Type type)
{
if (type.IsInterface())
{
yield return type;
}
foreach (var implementedInterface in type.GetInterfaces())
{
yield return implementedInterface;
}
}
示例10: CreateProxyUsingCastleProxyGenerator
private object CreateProxyUsingCastleProxyGenerator(Type typeToProxy, Type[] additionalInterfaces,
object[] constructorArguments,
IInterceptor interceptor,
ProxyGenerationOptions proxyGenerationOptions)
{
if (typeToProxy.IsInterface())
{
VerifyNoConstructorArgumentsGivenForInterface(constructorArguments);
return _proxyGenerator.CreateInterfaceProxyWithoutTarget(typeToProxy, additionalInterfaces, proxyGenerationOptions, interceptor);
}
return _proxyGenerator.CreateClassProxy(typeToProxy, additionalInterfaces, proxyGenerationOptions, constructorArguments, interceptor);
}
示例11: CreateProviderForType
IProvider CreateProviderForType(
Type contractType, IPrefabInstantiator instantiator)
{
if (contractType == typeof(GameObject))
{
return new PrefabGameObjectProvider(instantiator);
}
Assert.That(contractType.IsInterface() || contractType.DerivesFrom<Component>());
return new GetFromPrefabComponentProvider(
contractType, instantiator);
}
示例12: RegisterValidator
public static void RegisterValidator(this Container container, Type validator, ReuseScope scope=ReuseScope.None)
{
var baseType = validator.BaseType();
if (validator.IsInterface() || baseType == null) return;
while (!baseType.IsGenericType())
{
baseType = baseType.BaseType();
}
var dtoType = baseType.GetGenericArguments()[0];
var validatorType = typeof(IValidator<>).GetCachedGenericType(dtoType);
container.RegisterAutoWiredType(validator, validatorType, scope);
}
示例13: CodeTypeReference
public CodeTypeReference(Type type) {
if (type == null)
throw new ArgumentNullException("type");
if (type.IsArray) {
this.arrayRank = type.GetArrayRank();
this.arrayElementType = new CodeTypeReference(type.GetElementType());
this.baseType = null;
} else {
InitializeFromType(type);
this.arrayRank = 0;
this.arrayElementType = null;
}
this.isInterface = type.IsInterface();
}
示例14: Create
public object Create(Type type)
{
if (type.IsInterface())
{
Type implementationType;
if (defaultInterfaceImplementations.TryGetValue(type.GetGenericTypeDefinition(), out implementationType))
{
type = implementationType.MakeGenericType(type.GetGenericArguments());
}
}
try
{
return Activator.CreateInstance(type);
}
catch (Exception err)
{
var message = string.Format("Failed to create an instance of type '{0}'.", type);
throw new InvalidOperationException(message, err);
}
}
示例15: GetNamespacesUsed
public HashSet<string> GetNamespacesUsed(Type type)
{
var to = new HashSet<string>();
if (type.IsUserType() || type.IsInterface() || type.IsOrHasGenericInterfaceTypeOf(typeof(IEnumerable<>)))
{
foreach (var pi in GetInstancePublicProperties(type))
{
if (pi.PropertyType.Namespace != null)
{
to.Add(pi.PropertyType.Namespace);
}
if (pi.PropertyType.IsGenericType())
{
pi.PropertyType.GetGenericArguments()
.Where(x => x.Namespace != null).Each(x => to.Add(x.Namespace));
}
}
if (type.IsGenericType())
{
type.GetGenericArguments()
.Where(x => x.Namespace != null).Each(x => to.Add(x.Namespace));
}
}
if (type.Namespace != null)
{
to.Add(type.Namespace);
}
return to;
}