本文整理汇总了C#中System.Type.Is方法的典型用法代码示例。如果您正苦于以下问题:C# Type.Is方法的具体用法?C# Type.Is怎么用?C# Type.Is使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.Is方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Close
// this has been through red and green phase, it has yet to see it's refactor phase
public Type Close(Type conversionPatternType, Type sourceType, Type targetType)
{
var @interface = conversionPatternType.GetInterface(typeof (IConversionPattern<,>));
if (@interface == null)
{
throw new ArgumentException(string.Format("Type {0} doesn't implement {1} and therefore is invalid for this operation.", conversionPatternType, typeof (IConversionPattern<,>)));
}
var arguments = @interface.GetGenericArguments();
var interfaceSourceType = arguments[0];
var interfaceTargetType = arguments[1];
if (conversionPatternType.IsGenericType == false)
{
if (sourceType.Is(interfaceSourceType) && targetType.Is(interfaceTargetType))
{
return conversionPatternType;
}
return null;
}
var openClassArguments = conversionPatternType.GetGenericArguments();
var parameters = new Type[openClassArguments.Length];
if (TryAddParameters(sourceType, interfaceSourceType, parameters, openClassArguments) == false)
{
return null;
}
if (TryAddParameters(targetType, interfaceTargetType, parameters, openClassArguments) == false)
{
return null;
}
if (parameters.Any(p => p == null))
{
return null;
}
return conversionPatternType.MakeGenericType(parameters);
}
示例2: CanConvert
public override bool CanConvert(Type objectType)
{
// Type should not be a User or Device since these have their specific serializers.
// This serializer should be used for any other type that inherits from article.
if (objectType != typeof(User) && objectType != typeof(Device))
return objectType.Is<Article>();
else
return false;
}
示例3: To
public IBindingScope To(Type concreteType)
{
Assert.IsNotNull(concreteType);
Assert.IsTrue(concreteType.IsConcrete());
Assert.IsTrue(concreteType.Is(ContractType));
return ToMethod(c => c.Container.Instantiator
.Instantiate(new InjectionContext { Container = c.Container, DeclaringType = concreteType }));
}
示例4: JobConfiguration
/// <summary>
/// Constructor
/// </summary>
/// <param name="jobType">The type of the class that implements the job</param>
/// <param name="builder">The trigger builder</param>
public JobConfiguration(
Type jobType,
Func<TriggerBuilder> builder)
{
jobType.Is<IJob>();
builder.NotNull(nameof(builder));
JobType = jobType;
TriggerBuilder = builder;
}
示例5: ToFactory
public IBindingScope ToFactory(Type factoryType)
{
Assert.IsNotNull(factoryType);
Assert.IsTrue(factoryType.Is<IInjectionFactory>());
Container.Binder.Bind(factoryType).ToSelf().AsSingleton();
return ToMethod(c => ((IInjectionFactory)c.Container.Resolver
.Resolve(new InjectionContext { Container = c.Container, ContractType = factoryType }))
.Create(c));
}
示例6: SelectInterceptors
public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
{
if (type.Is<ICatalog>())
{
if (method.Name == "AddItem")
{
return interceptors;
}
}
return null;
}
示例7: AbstractHandler
/// <summary>
/// Constructor
/// </summary>
/// <param name="exceptionMessage">Exception message to be included in the new exception</param>
/// <param name="exceptionType">Type of the new exception to be created</param>
public AbstractHandler(
string exceptionMessage,
Type exceptionType)
{
exceptionMessage.NotNullOrEmpty(nameof(exceptionMessage));
exceptionType.NotNull(nameof(exceptionType));
exceptionType.Is<Exception>();
_exceptionMessage = exceptionMessage;
ExceptionType = exceptionType;
}
示例8: ConvertibleAttribute
/// <summary>
/// Defines the <see cref = "ITypeConverter" /> to be used to convert the type
/// </summary>
/// <param name = "converterType"></param>
public ConvertibleAttribute(Type converterType)
{
if (converterType.Is<ITypeConverter>() == false)
{
throw new ArgumentException(
string.Format("ConverterType {0} does not implement {1} interface", converterType.FullName,
typeof(ITypeConverter).FullName), "converterType");
}
this.converterType = converterType;
}
示例9: Generate
/// <summary>
/// Generates the key that should be use to cache/retrieve the content
/// for the given controllerType and action name
/// </summary>
/// <param name="controllerType">The controller type (must be ApiController)</param>
/// <param name="actionName">The action name</param>
/// <param name="context">The action context</param>
/// <returns>The key for the given controller type and action name</returns>
/// <exception cref="ArgumentException">If controller type is not an ApiController</exception>
public virtual string Generate(
Type controllerType,
string actionName,
HttpActionContext context)
{
controllerType.NotNull(nameof(controllerType));
controllerType.Is<ApiController>();
actionName.NotNullOrEmpty(nameof(actionName));
context.NotNull(nameof(context));
return "{0}-{1}".AsFormat(controllerType.FullName, actionName);
}
示例10: InvalidateXReferencedOutputCacheAttribute
/// <summary>
/// Constructor
/// </summary>
/// <param name="controllerType">The controller type (must be ApiController)</param>
/// <param name="actionName">The action name</param>
/// <param name="cacheKeyGeneratorType">The type of the class responsible for generating the keys</param>
public InvalidateXReferencedOutputCacheAttribute(
Type controllerType,
string actionName,
Type cacheKeyGeneratorType = null)
{
controllerType.NotNull(nameof(controllerType));
controllerType.Is<ApiController>();
actionName.NotNullOrEmpty(nameof(actionName));
ActionName = actionName;
ControllerType = controllerType;
CacheKeyGeneratorType = cacheKeyGeneratorType ?? typeof(DefaultCacheKeyGenerator);
}
示例11: GetValue
public override object GetValue(IContent content, PropertyInfo property, Type collectionItemType)
{
// Let's support both Pages and ContentReference collections
bool returnReferences = collectionItemType.Is<ContentReference>();
var descendents = ContentLoader.GetDescendents(content.ContentLink);
var result = returnReferences
? descendents.ToList()
: GetPagesCollection(() => descendents, collectionItemType);
return result;
}
示例12: ExtractInvokeMethod
public static MethodInfo ExtractInvokeMethod(Type service)
{
if (!service.Is<MulticastDelegate>())
{
return null;
}
var invoke = GetInvokeMethod(service);
if (!HasReturn(invoke))
{
return null;
}
return invoke;
}
示例13: AddNodeProcessor
public void AddNodeProcessor(Type type)
{
if (type.Is<IXmlNodeProcessor>())
{
var processor = type.CreateInstance<IXmlNodeProcessor>();
foreach(var nodeType in processor.AcceptNodeTypes)
{
RegisterProcessor(nodeType, processor);
}
}
else
{
throw new XmlProcessorException("{0} does not implement IElementProcessor interface", type.FullName);
}
}
示例14: JobAttribute
/// <summary>
/// Constructor
/// </summary>
/// <param name="processorType">The type that implments IProcessor</param>
public JobAttribute(Type processorType)
{
processorType.Is<IProcessor>();
ProcessorType = processorType;
}
示例15: CanConvert
public override bool CanConvert(Type objectType)
{
return objectType.Is<APConnection>();
}