本文整理汇总了C#中System.Type.GetInterfaces方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetInterfaces方法的具体用法?C# Type.GetInterfaces怎么用?C# Type.GetInterfaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.GetInterfaces方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadAllToCache
/// <summary>
/// Dumps everything of a single type into the cache from the filesystem for BackingData
/// </summary>
/// <typeparam name="T">the type to get and store</typeparam>
/// <returns>full or partial success</returns>
public static bool LoadAllToCache(Type objectType)
{
if (!objectType.GetInterfaces().Contains(typeof(IData)))
return false;
var fileAccessor = new NetMud.DataAccess.FileSystem.BackingData();
var typeDirectory = fileAccessor.BaseDirectory + fileAccessor.CurrentDirectoryName + objectType.Name + "/";
if (!fileAccessor.VerifyDirectory(typeDirectory, false))
{
LoggingUtility.LogError(new AccessViolationException(String.Format("Current directory for type {0} does not exist.", objectType.Name)));
return false;
}
var filesDirectory = new DirectoryInfo(typeDirectory);
foreach (var file in filesDirectory.EnumerateFiles())
{
try
{
BackingDataCache.Add(fileAccessor.ReadEntity(file, objectType));
}
catch(Exception ex)
{
LoggingUtility.LogError(ex);
//Let it keep going
}
}
return true;
}
示例2: IsCollectionType
/// <summary>
/// Determines whether the specified property type is a collection.
/// </summary>
/// <param name="propertyType">Type of the property.</param>
/// <returns></returns>
public static bool IsCollectionType(Type propertyType)
{
return (propertyType.GetInterfaces().Contains(typeof(IList)) ||
propertyType.GetInterfaces().Contains(typeof(ICollection)) ||
propertyType.GetInterfaces().Contains(typeof(IDictionary)) ||
propertyType.IsArray);
}
示例3: Initialise
/// <summary>
/// Initialises the Factory property based on the type to which the attribute is applied.
/// </summary>
/// <param name="decoratedType">The type to which the attribute is applied</param>
public virtual void Initialise(Type decoratedType)
{
if (Initialised)
{
throw new InvalidOperationException("Already initialised!");
}
var name = decoratedType.Name.ToProperCase();
var alias = decoratedType.Name.ToCamelCase();
if (Name == null)
{
Name = name;
}
if (Alias == null)
{
Alias = alias;
}
if (AllowedChildren == null && decoratedType.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IListViewDocumentType<>)))
{
var type = decoratedType.GetInterfaces().First(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IListViewDocumentType<>)).GetGenericArguments().First();
if (type.GetCodeFirstAttribute<DocumentTypeAttribute>(false) != null)
{
AllowedChildren = new Type[] { type };
}
}
Initialised = true;
}
示例4: AppendBaseClasses
public void AppendBaseClasses(Type type)
{
if (((type.BaseType == null) || (type.BaseType == typeof(object))) && (type.GetInterfaces().Length == 0))
{
return;
}
// Dont use base types in comparing declarations.. someday, would be good to do a more intelligent compare (implemented interfaces removed is possibly a breaking change?)
AppendMode restore = _mode;
_mode &= ~AppendMode.Text;
AppendText(" : ");
if ((type.BaseType != null) && (type.BaseType != typeof(object)))
{
AppendType(type.BaseType);
AppendText(", ");
}
foreach (Type intf in type.GetInterfaces())
{
AppendType(intf);
AppendText(", ");
}
RemoveCharsFromEnd(2);
_mode = restore;
}
示例5: ExcludedTypes
private bool ExcludedTypes(Type type)
{
return type != typeof(SecureSocketStyxEngine) &&
!type.GetInterfaces().Contains(typeof(IHostConfiguration)) &&
!type.GetInterfaces().Contains(typeof(IHandshakeNegotiator)) &&
!type.GetInterfaces().Contains(typeof(ILogger));
}
示例6: GetLeastGeneralCommonType
private Type GetLeastGeneralCommonType(Type type1, Type type2)
{
if (type1.IsInterface)
{
if (type2.GetInterfaces().Contains(type1)) return type1;
if (type2.IsInterface)
{
if (type1.GetInterfaces().Contains(type2)) return type2;
}
return typeof(object);
}
else
{
if (type2.IsInterface)
{
if (type1.GetInterfaces().Contains(type2)) return type2;
return typeof(object);
}
Type current = type1;
List<Type> types = new List<Type>();
while (current != null)
{
types.Add(current);
current = current.BaseType;
}
current = type2;
while (!types.Contains(current))
{
current = current.BaseType;
}
return current;
}
}
示例7: Resolve
public override object Resolve(Type jobType)
{
var instance = _container.TryGetInstance(jobType);
// since it fails we can try to get the first interface and request from container
if (instance == null && jobType.GetInterfaces().Count() > 0)
instance = _container.GetInstance(jobType.GetInterfaces().FirstOrDefault());
return instance;
}
示例8: ActivateJob
public override object ActivateJob(Type jobType)
{
// this will fail if you do self referencing job queues on a class with an interface:
// BackgroundJob.Enqueue(() => this.SendSms(message));
var instance = _container.TryGetInstance(jobType);
// since it fails we can try to get the first interface and request from container
if (instance==null && jobType.GetInterfaces().Count()>0)
instance = _container.GetInstance(jobType.GetInterfaces().FirstOrDefault());
return instance;
}
示例9: EnumerateGenericIntefaces
private static IEnumerable<Type> EnumerateGenericIntefaces( Type source, Type genericType, bool includesOwn )
{
return
( includesOwn ? new[] { source }.Concat( source.GetInterfaces() ) : source.GetInterfaces() )
.Where( @interface =>
@interface.GetIsGenericType()
&& ( genericType.GetIsGenericTypeDefinition()
? @interface.GetGenericTypeDefinition() == genericType
: @interface == genericType
)
).Select( @interface => // If source is GenericTypeDefinition, type def is only valid type (i.e. has name)
source.GetIsGenericTypeDefinition() ? @interface.GetGenericTypeDefinition() : @interface
);
}
示例10: CreateTypeBuilder
public ITypeBuilder CreateTypeBuilder(Type type)
{
// Check which ICollection<T> is implemented
var interfaceType = (from @interface in new[] {type}.Concat(type.GetInterfaces())
where
@interface.IsGenericType &&
@interface.GetGenericTypeDefinition() == typeof (ICollection<>)
select @interface)
.FirstOrDefault();
if (interfaceType == null)
{
// Check if it is IEnumerable<T>
interfaceType = (from @interface in new[] {type}.Concat(type.GetInterfaces())
where
@interface.IsGenericType &&
@interface.GetGenericTypeDefinition() == typeof (IEnumerable<>)
select @interface)
.FirstOrDefault();
}
if (interfaceType == null)
{
return null;
}
var elementType = interfaceType.GetGenericArguments()[0];
// Determine concrete ICollection<T> to instantiate
var listType = type.IsInterface
? typeof (List<>).MakeGenericType(elementType)
: type;
if (!type.IsAssignableFrom(listType))
{
return null;
}
// List must have default constructor
if (listType.GetConstructor(Type.EmptyTypes) == null)
{
return null;
}
return
((ITypeBuilderFactory)
typeof (CollectionBuilderFactory<,>)
.MakeGenericType(listType, interfaceType.GetGenericArguments()[0])
.GetConstructor(Type.EmptyTypes)
.Invoke(new object[0])).CreateTypeBuilder(type);
}
示例11: GetAllServiceTypesFor
private static IEnumerable<Type> GetAllServiceTypesFor(Type t)
{
if (t == null)
{
return new List<Type>();
}
List<Type> list2 = new List<Type>(t.GetInterfaces()) { t };
List<Type> list = list2;
foreach (Type type in t.GetInterfaces())
{
list.AddRange(GetAllServiceTypesFor(type));
}
return list;
}
示例12: ConcurrentAttribute
public ConcurrentAttribute(ConcurrentBehavior behavior, Type resolver)
{
this.Behavior = behavior;
if (behavior == ConcurrentBehavior.Dynamic)
{
if (resolver.GetInterfaces().Length != 1 ||
resolver.GetInterfaces()[0] != typeof(IUserDefinedMergeResolver))
{
throw new ArgumentException("User defined resolver type missing or not derived from IUserDefinedMergeResolver");
}
this.Resolver = resolver;
}
}
示例13: Register
public void Register(IIocBuilder builder, Type type)
{
if (!type.IsAbstract && type.IsClass)
{
var itypes = type.GetInterfaces();
if (itypes != null && itypes.Length > 0)
{
var itype = type.GetInterfaces()[0];
if (itype.IsGenericType && itype.GetGenericTypeDefinition().Equals(typeof(IMessageMapper<>)))
{
builder.RegisterType(itype, type, LifeTimeScope.Transient, type.FullName);
}
}
}
}
示例14: FindIEnumerable
private static Type FindIEnumerable(Type seqType)
{
if (seqType == null || seqType == typeof(string))
return null;
if (seqType.IsArray)
return typeof(IEnumerable<>).MakeGenericType(seqType.GetElementType());
if (seqType.IsGenericType)
foreach (var arg in seqType.GetGenericArguments())
{
var ienum = typeof(IEnumerable<>).MakeGenericType(arg);
if (ienum.IsAssignableFrom(seqType))
return ienum;
}
var ifaces = seqType.GetInterfaces();
if (ifaces != null)
foreach (var iface in ifaces)
{
var ienum = FindIEnumerable(iface);
if (ienum != null)
return ienum;
}
if (seqType.BaseType != null && seqType.BaseType != typeof(object))
return FindIEnumerable(seqType.BaseType);
return null;
}
示例15: GetEnumerableType
private static Type GetEnumerableType(Type type)
{
return type.GetInterfaces()
.Where(intType => intType.IsGenericType && intType.GetGenericTypeDefinition() == typeof(IEnumerable<>))
.Select(intType => intType.GetGenericArguments()[0])
.FirstOrDefault();
}