本文整理汇总了C#中System.Reflection.ParameterInfo.AllAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterInfo.AllAttributes方法的具体用法?C# ParameterInfo.AllAttributes怎么用?C# ParameterInfo.AllAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.ParameterInfo
的用法示例。
在下文中一共展示了ParameterInfo.AllAttributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateInjectableInfoForParam
static InjectableInfo CreateInjectableInfoForParam(
Type parentType, ParameterInfo paramInfo)
{
var injectAttributes = paramInfo.AllAttributes<InjectAttribute>().ToList();
var injectOptionalAttributes = paramInfo.AllAttributes<InjectOptionalAttribute>().ToList();
string identifier = null;
Assert.That(injectAttributes.IsEmpty() || injectOptionalAttributes.IsEmpty(),
"Found both 'InjectOptional' and 'Inject' attributes on type parameter '{0}' of type '{1}'. Parameter should only have one or the other.", paramInfo.Name, parentType.Name());
if (injectAttributes.Any())
{
identifier = injectAttributes.Single().Identifier;
}
else if (injectOptionalAttributes.Any())
{
identifier = injectOptionalAttributes.Single().Identifier;
}
return new InjectableInfo(
injectOptionalAttributes.Any(),
identifier,
paramInfo.Name,
paramInfo.ParameterType,
parentType,
null);
}
示例2: CreateInjectableInfoForParam
static InjectableInfo CreateInjectableInfoForParam(
Type parentType, ParameterInfo paramInfo)
{
var identifier = paramInfo.AllAttributes<InjectAttribute>().Select(x => x.Identifier)
.Concat(paramInfo.AllAttributes<InjectOptionalAttribute>().Select(x => x.Identifier)).FirstOrDefault();
return new InjectableInfo(
paramInfo.HasAttribute(typeof(InjectOptionalAttribute)),
identifier,
paramInfo.Name,
paramInfo.ParameterType,
parentType,
null);
}
示例3: CreateInjectableInfoForParam
static InjectableInfo CreateInjectableInfoForParam(
Type parentType, ParameterInfo paramInfo)
{
var injectAttributes = paramInfo.AllAttributes<InjectAttributeBase>().ToList();
Assert.That(injectAttributes.Count <= 1,
"Found multiple 'Inject' attributes on type parameter '{0}' of type '{1}'. Parameter should only have one", paramInfo.Name, parentType.Name());
var injectAttr = injectAttributes.SingleOrDefault();
string identifier = null;
bool isOptional = false;
InjectSources sourceType = InjectSources.Any;
if (injectAttr != null)
{
identifier = injectAttr.Identifier;
isOptional = injectAttr.IsOptional;
sourceType = injectAttr.SourceType;
}
bool isOptionalWithADefaultValue = (paramInfo.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault;
return new InjectableInfo(
isOptionalWithADefaultValue || isOptional,
identifier,
paramInfo.Name,
paramInfo.ParameterType,
parentType,
null,
isOptionalWithADefaultValue ? paramInfo.DefaultValue : null,
sourceType);
}
示例4: ToProperty
public MetadataPropertyType ToProperty(ParameterInfo pi)
{
var propertyAttrs = pi.AllAttributes();
var property = new MetadataPropertyType
{
Name = pi.Name,
Attributes = ToAttributes(propertyAttrs),
Type = pi.ParameterType.GetOperationName(),
IsValueType = pi.ParameterType.IsValueType() ? true : (bool?)null,
IsSystemType = pi.ParameterType.IsSystemType() ? true : (bool?)null,
IsEnum = pi.ParameterType.IsEnum() ? true : (bool?)null,
TypeNamespace = pi.ParameterType.Namespace,
Description = pi.GetDescription(),
};
return property;
}
示例5: ToProperty
public MetadataPropertyType ToProperty(ParameterInfo pi)
{
var propertyAttrs = pi.AllAttributes();
var property = new MetadataPropertyType
{
Name = pi.Name,
Attributes = ToAttributes(propertyAttrs),
Type = pi.ParameterType.GetOperationName(),
Description = pi.GetDescription(),
};
return property;
}