本文整理汇总了C#中System.Type.GetAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetAttributes方法的具体用法?C# Type.GetAttributes怎么用?C# Type.GetAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.GetAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindIntroductionAspects
private IEnumerable<IIntroductionAspect> FindIntroductionAspects(Type type)
{
return (from item in type.GetAttributes<IntroductionAspectAttribute>(true)
let typeFilter = new PredicateTypeFilter(t => t == type)
let advice = new IntroductionAdvice(item.Types)
select new IntroductionAspect(typeFilter, advice));
}
示例2: RegisterComponent
/// <summary>
/// Register a new component.
/// </summary>
/// <param name="builder"> autofac container builder </param>
/// <param name="type"> Type to register </param>
public virtual void RegisterComponent(ContainerBuilder builder, Type type)
{
if (builder == null) throw new ArgumentNullException("builder");
if (type == null) throw new ArgumentNullException("type");
_builder = builder;
var attribute = type.GetAttributes<ComponentAttribute>(false).Single();
var lifetime = attribute.Lifetime == Lifetime.Default ? DefaultLifetime : attribute.Lifetime;
switch (lifetime)
{
case Lifetime.Transient:
RegisterTransient(type, attribute);
break;
case Lifetime.Singleton:
RegisterSingleton(type, attribute);
break;
case Lifetime.Scoped:
RegisterScoped(type, attribute);
break;
default:
throw new InvalidOperationException(
string.Format(
"Either the [Component] attribute on {0} or the ComponentRegistrar.DefaultLifetime must have been specified.",
type.FullName));
}
}
示例3: AttributesFor
public IEnumerable<IFilterAttribute> AttributesFor(Type type)
{
return withCache(new Signature(type), () =>
{
return type.GetAttributes<IFilterAttribute>();
});
}
示例4: AddSideEffectDeclaration
private void AddSideEffectDeclaration(Type type)
{
IEnumerable<SideEffectDeclaration> sideEffects = from sideEffectAttribute in type.GetAttributes<SideEffectsAttribute>()
from sideEffectType in sideEffectAttribute.SideEffectTypes
select new SideEffectDeclaration(sideEffectType, type);
this.sideEffectDeclarations.AddRange(sideEffects);
}
示例5: AddConstraintDeclarations
private void AddConstraintDeclarations(Type type)
{
IEnumerable<ConstraintAttribute> annotations = type.GetAttributes<ConstraintAttribute>();
foreach (ConstraintAttribute annontation in annotations)
{
this.constraints.Add(new ConstraintDeclaration(annontation, type));
}
}
示例6: IsPersistent
public bool IsPersistent(Type messageType)
{
Preconditions.CheckNotNull(messageType, "messageType");
var deliveryModeAttribute = messageType.GetAttributes<DeliveryModeAttribute>().FirstOrDefault();
if (deliveryModeAttribute != null)
return deliveryModeAttribute.IsPersistent;
return connectionConfiguration.PersistentMessages;
}
示例7: CreateHistoryInfo
public HistoryInfo CreateHistoryInfo(Type decoratedType)
{
return new HistoryInfo(
_historyKey,
((ComponentRegistrationBase)decoratedType.GetAttributes<ComponentRegistrationBase>(true)
.FirstOrDefault()
.GetComponentInfo(decoratedType)).Service
);
}
示例8: GetXmlSerializer
XmlObjectSerializer GetXmlSerializer(Type type)
{
if (type.GetAttributes<DataContractAttribute>(false).Length > 0)
{
return new DataContractSerializer(type);
}
return new NetDataContractSerializer();
}
示例9: AddConcernDeclarations
private static void AddConcernDeclarations(Type type, List<ConcernDeclaration> concerns)
{
IEnumerable<ConcernsAttribute> attributes = type.GetAttributes<ConcernsAttribute>();
IEnumerable<ConcernDeclaration> types = from attribute in attributes
from concernType in attribute.ConcernTypes
select new ConcernDeclaration(concernType, type);
concerns.AddRange(types);
}
示例10: CreateMetaFromType
/// <summary>
/// Creates the meta-info from the specified type.
/// </summary>
/// <param name = "implementation">The implementation type.</param>
/// <returns>The corresponding meta-info.</returns>
public SynchronizeMetaInfo CreateMetaFromType(Type implementation)
{
var syncAttrib = implementation.GetAttributes<SynchronizeAttribute>()[0];
var metaInfo = new SynchronizeMetaInfo(syncAttrib);
PopulateMetaInfoFromType(metaInfo, implementation);
Register(implementation, metaInfo);
return metaInfo;
}
示例11: GetConverter
public static TypeConverter GetConverter(Type type)
{
TypeConverter converter;
if (!Cache.TryGetValue(type, out converter))
{
IEnumerable<TypeConverterAttribute> attributes = type.GetAttributes<TypeConverterAttribute>(true);
if (!attributes.Any<TypeConverterAttribute>())
{
return new TypeConverter();
}
converter = Activator.CreateInstance(Type.GetType(attributes.First<TypeConverterAttribute>().ConverterTypeName)) as TypeConverter;
Cache[type] = converter;
}
return converter;
}
示例12: GetConverter
/// <summary>
/// Returns a type converter for the specified type.
/// </summary>
/// <param name="type">The System.Type of the target component.</param>
/// <returns>A System.ComponentModel.TypeConverter for the specified type.</returns>
public static TypeConverter GetConverter(Type type)
{
TypeConverter converter;
if(!Cache.TryGetValue(type, out converter))
{
var customAttributes = type.GetAttributes<TypeConverterAttribute>(true);
if(!customAttributes.Any())
return new TypeConverter();
converter = Activator.CreateInstance(Type.GetType(customAttributes.First().ConverterTypeName)) as TypeConverter;
Cache[type] = converter;
}
return converter;
}
示例13: CreateCore
/// <summary>
/// Creates the actual description.
/// </summary>
/// <param name="targetType">Type of the target.</param>
/// <returns></returns>
protected virtual IViewModelDescription CreateCore(Type targetType)
{
var customFactory = targetType
.GetAttributes<IViewModelDescriptionFactory>(true)
.FirstOrDefault();
if (customFactory != null)
return customFactory.Create(targetType);
var description = new DefaultViewModelDescription(conventionManager, targetType);
var filters = new FilterManager(targetType, description.TargetType, serviceLocator);
var actions = actionLocator.Locate(new ActionLocationContext(serviceLocator, targetType, filters));
description.Filters = filters;
actions.Apply(description.AddAction);
return description;
}
示例14: FindPointcutAspects
private IEnumerable<IAspect> FindPointcutAspects(Type type)
{
var typeAspects = (from item in type.GetAttributes<PointcutAspectAttribute>(true)
let typeFilter = new PredicateTypeFilter(t => t == type)
let pointcut = new Pointcut(typeFilter)
select new PointcutAspect(pointcut, item.Advice));
var mehodAspects = type.GetMethods().SelectMany(method =>
{
return (from item in method.GetAttributes<PointcutAspectAttribute>(true)
let typeFilter = new PredicateTypeFilter(t => t == type)
let methodMatcher = new PredicateMethodMatcher((m, t) =>
m.Match(method))
let pointcut = new Pointcut(typeFilter, methodMatcher)
select new PointcutAspect(pointcut, item.Advice));
});
return typeAspects.Concat(mehodAspects);
}
示例15: GetQueueAttribute
private QueueAttribute GetQueueAttribute(Type messageType)
{
var attr = messageType.GetAttributes<QueueAttribute>().FirstOrDefault();
return attr ?? new QueueAttribute(string.Empty);
}