本文整理汇总了C#中System.Reflection.ParameterInfo.IsDefined方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterInfo.IsDefined方法的具体用法?C# ParameterInfo.IsDefined怎么用?C# ParameterInfo.IsDefined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.ParameterInfo
的用法示例。
在下文中一共展示了ParameterInfo.IsDefined方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParameterWrapper
public ParameterWrapper(ActionBinder binder, ParameterInfo info)
: this(binder, info.ParameterType) {
_name = SymbolTable.StringToId(info.Name ?? "<unknown>");
#if FULL
_prohibitNull = info.IsDefined(typeof(NotNullAttribute), false);
#endif
_isParams = info.IsDefined(typeof(ParamArrayAttribute), false);
#if FULL
_isParamsDict = info.IsDefined(typeof(ParamDictionaryAttribute), false);
#endif
}
示例2: ParameterWrapper
public ParameterWrapper(ActionBinder binder, ParameterInfo info)
: this(binder, info.ParameterType)
{
_name = SymbolTable.StringToId(info.Name ?? "<unknown>");
_isParams = info.IsDefined(typeof(ParamArrayAttribute), false);
}
示例3: ConvertExpression
public override Expression/*!*/ ConvertExpression(Expression/*!*/ expr, ParameterInfo info, Type/*!*/ toType) {
Type fromType = expr.Type;
// block:
if (fromType == typeof(MissingBlockParam)) {
Debug.Assert(toType == typeof(BlockParam) || toType == typeof(MissingBlockParam));
return AstUtils.Constant(null);
}
if (fromType == typeof(BlockParam) && toType == typeof(MissingBlockParam)) {
return AstUtils.Constant(null);
}
// protocol conversions:
if (info != null && info.IsDefined(typeof(DefaultProtocolAttribute), false)) {
var action = RubyConversionAction.TryGetDefaultConversionAction(toType);
if (action != null) {
// TODO: once we work with MetaObjects, we could inline these dynamic sites:
return Ast.Dynamic(action, toType, ContextExpression, expr);
}
throw new InvalidOperationException(String.Format("No default protocol conversion for type {0}.", toType));
}
return Binder.ConvertExpression(expr, toType, ConversionResultKind.ExplicitCast, ScopeExpression);
}
示例4: FromParameterInfo
public static Parameter FromParameterInfo(ParameterInfo parameterInfo) {
Parameter parameter = new Parameter();
parameter._name = parameterInfo.Name;
parameter._position = parameterInfo.Position;
parameter._parameterType = parameterInfo.ParameterType;
parameter._isParamArray = parameterInfo.IsDefined(typeof(ParamArrayAttribute), true);
return parameter;
}
示例5: BuildParameter
private static void BuildParameter(ParameterBuilder builder, ParameterInfo parameter)
{
Debug.Assert(parameter != null);
Debug.Assert(builder != null);
builder.Name = parameter.Name;
builder.ParameterType = parameter.ParameterType;
builder.Position = parameter.Position;
builder.IsParamArray = parameter.IsDefined(typeof(ParamArrayAttribute), true);
//
// Build via attributes.
//
object[] attributes = parameter.GetCustomAttributes(typeof(IParameterReflector), true);
foreach (IParameterReflector reflector in attributes)
reflector.Build(builder, parameter);
}
示例6: IsDefined
public static bool IsDefined(ParameterInfo element, Type attributeType, bool inherit)
{
if (element == null)
{
throw new ArgumentNullException("element");
}
if (attributeType == null)
{
throw new ArgumentNullException("attributeType");
}
if (!attributeType.IsSubclassOf(typeof(Attribute)) && (attributeType != typeof(Attribute)))
{
throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
}
MemberTypes memberType = element.Member.MemberType;
if (memberType == MemberTypes.Constructor)
{
return element.IsDefined(attributeType, false);
}
if (memberType != MemberTypes.Method)
{
if (memberType != MemberTypes.Property)
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidParamInfo"));
}
return element.IsDefined(attributeType, false);
}
return InternalParamIsDefined(element, attributeType, inherit);
}
示例7: InstantiateDependency
internal ServiceDependency InstantiateDependency(ParameterInfo formalParameter, ContainerService.Builder builder)
{
ValueWithType actualArgument;
if (builder.Arguments != null && builder.Arguments.TryGet(formalParameter.Name, out actualArgument))
return containerContext.Constant(formalParameter, actualArgument.value);
var parameters = builder.Configuration.ParametersSource;
object actualParameter;
if (parameters != null && parameters.TryGet(formalParameter.Name, formalParameter.ParameterType, out actualParameter))
return containerContext.Constant(formalParameter, actualParameter);
var dependencyConfiguration = builder.Configuration.GetOrNull(formalParameter);
Type implementationType = null;
if (dependencyConfiguration != null)
{
if (dependencyConfiguration.ValueAssigned)
return containerContext.Constant(formalParameter, dependencyConfiguration.Value);
if (dependencyConfiguration.Factory != null)
{
var dependencyBuilder = new ContainerService.Builder(new ServiceName(formalParameter.ParameterType))
{
Context = builder.Context,
DependencyName = formalParameter.Name
};
builder.Context.Stack.Add(dependencyBuilder);
dependencyBuilder.CreateInstanceBy(CallTarget.F(dependencyConfiguration.Factory), true);
builder.Context.Stack.RemoveLast();
return dependencyBuilder.GetService().AsDependency(containerContext, formalParameter.Name, false);
}
implementationType = dependencyConfiguration.ImplementationType;
}
implementationType = implementationType ?? formalParameter.ParameterType;
FromResourceAttribute resourceAttribute;
if (implementationType == typeof (Stream) && formalParameter.TryGetCustomAttribute(out resourceAttribute))
{
var resourceStream = builder.Type.Assembly.GetManifestResourceStream(builder.Type, resourceAttribute.Name);
if (resourceStream == null)
return containerContext.Error(null, formalParameter.Name,
"can't find resource [{0}] in namespace of [{1}], assembly [{2}]",
resourceAttribute.Name, builder.Type, builder.Type.Assembly.GetName().Name);
return containerContext.Resource(formalParameter, resourceAttribute.Name, resourceStream);
}
var dependencyName = ServiceName.Parse(implementationType.UnwrapEnumerable(),
InternalHelpers.ParseContracts(formalParameter));
if (dependencyName.Type.IsSimpleType())
{
if (!formalParameter.HasDefaultValue)
return containerContext.Error(null, formalParameter.Name,
"parameter [{0}] of service [{1}] is not configured",
formalParameter.Name, builder.Type.FormatName());
return containerContext.Constant(formalParameter, formalParameter.DefaultValue);
}
var resultService = ResolveCore(dependencyName, false, null, builder.Context);
if (resultService.Status.IsBad())
return containerContext.ServiceError(resultService);
var isEnumerable = dependencyName.Type != implementationType;
if (isEnumerable)
return containerContext.Service(resultService, resultService.GetAllValues());
if (resultService.Status == ServiceStatus.NotResolved)
{
if (formalParameter.HasDefaultValue)
return containerContext.Service(resultService, formalParameter.DefaultValue);
if (formalParameter.IsDefined<OptionalAttribute>() || formalParameter.IsDefined("CanBeNullAttribute"))
return containerContext.Service(resultService, null);
return containerContext.NotResolved(resultService);
}
return resultService.AsDependency(containerContext, null, false);
}
示例8: GetParamArrayType
/// <summary>
/// 如果给定的参数信息是 params 参数,则返回对应的数组元素类型;否则为 <c>null</c>。
/// </summary>
/// <param name="parameter">参数信息。</param>
/// <returns>params 参数的元素类型。</returns>
internal static Type GetParamArrayType(ParameterInfo parameter)
{
if (parameter.ParameterType.IsArray && parameter.IsDefined(typeof(ParamArrayAttribute), true))
{
return parameter.ParameterType.GetElementType();
}
return null;
}
示例9: InternalParamIsDefined
private static bool InternalParamIsDefined(ParameterInfo param, Type type, bool inherit)
{
if (param.IsDefined(type, false))
{
return true;
}
if ((param.Member.DeclaringType != null) && inherit)
{
for (ParameterInfo info = GetParentDefinition(param); info != null; info = GetParentDefinition(info))
{
object[] customAttributes = info.GetCustomAttributes(type, false);
for (int i = 0; i < customAttributes.Length; i++)
{
AttributeUsageAttribute attributeUsage = InternalGetAttributeUsage(customAttributes[i].GetType());
if ((customAttributes[i] is Attribute) && attributeUsage.Inherited)
{
return true;
}
}
}
}
return false;
}
示例10: CopyParameterAttributes
public static void CopyParameterAttributes(ParameterInfo from, ParameterBuilder to) {
if (from.IsDefined(typeof(ParamArrayAttribute), false)) {
to.SetCustomAttribute(new CustomAttributeBuilder(
typeof(ParamArrayAttribute).GetConstructor(Type.EmptyTypes), ArrayUtils.EmptyObjects)
);
} else if (from.IsDefined(typeof(ParamDictionaryAttribute), false)) {
to.SetCustomAttribute(new CustomAttributeBuilder(
typeof(ParamDictionaryAttribute).GetConstructor(Type.EmptyTypes), ArrayUtils.EmptyObjects)
);
}
if ((from.Attributes & ParameterAttributes.HasDefault) != 0) {
to.SetConstant(from.DefaultValue);
}
}
示例11: InternalParamIsDefined
private static bool InternalParamIsDefined(ParameterInfo param, Type type, bool inherit)
{
Contract.Requires(param != null);
Contract.Requires(type != null);
// For ParameterInfo's we need to make sure that we chain through all the MethodInfo's in the inheritance chain.
// We pick up all the CustomAttributes for the starting ParameterInfo. We need to pick up only attributes
// that are marked inherited from the remainder of the ParameterInfo's in the inheritance chain.
// For MethodInfo's on an interface we do not do an inheritance walk. For ParameterInfo's on a
// Class we walk up the inheritance chain but do not look at the MethodInfo's on the interfaces that the class inherits from.
if (param.IsDefined(type, false))
return true;
if (param.Member.DeclaringType == null || !inherit) // This is an interface so we are done.
return false;
ParameterInfo baseParam = GetParentDefinition(param);
while (baseParam != null)
{
Object[] objAttr = baseParam.GetCustomAttributes(type, false);
for (int i =0; i < objAttr.Length; i++)
{
Type objType = objAttr[i].GetType();
AttributeUsageAttribute attribUsage = InternalGetAttributeUsage(objType);
if ((objAttr[i] is Attribute) && (attribUsage.Inherited))
return true;
}
baseParam = GetParentDefinition(baseParam);
}
return false;
}
示例12: HasDataFor
/// <summary>
/// Determine whether any data is available for a parameter.
/// </summary>
/// <param name="parameter">A ParameterInfo representing one
/// argument to a parameterized test</param>
/// <returns>
/// True if any data is available, otherwise false.
/// </returns>
public bool HasDataFor(ParameterInfo parameter)
{
return parameter.IsDefined(typeof(DataAttribute), false);
}
示例13: IsDefined
internal static bool IsDefined(ParameterInfo target, Type caType, bool inherit) {
// JScript implements subclasses of ParameterInfo which throw an exception when Module is
// accessed. We know that none of these are from a ReflectionOnly assembly.
Type t = target.GetType();
if (t.Assembly == typeof(CustomAttribute).Assembly || !target.Member.Module.Assembly.ReflectionOnly)
return target.IsDefined(caType, inherit);
return CustomAttribute.CheckForCustomAttribute(CustomAttributeData.GetCustomAttributes(target), caType);
}
示例14: BuildParameter
internal static void BuildParameter(ParameterBuilder builder, ParameterInfo parameter)
{
Debug.Assert(parameter != null);
Debug.Assert(builder != null);
//
// Build...
//
builder.Name = parameter.Name;
builder.ParameterType = parameter.ParameterType;
builder.IsParamArray = parameter.IsDefined(typeof(ParamArrayAttribute), true);
//
// Modify...
//
object[] modifiers = GetCustomAttributes(parameter, typeof(IParameterModifier), true);
foreach (IParameterModifier modifier in modifiers)
modifier.Modify(builder);
}
示例15: IsParamDictionary
public static bool IsParamDictionary(ParameterInfo parameter) {
return parameter.IsDefined(typeof(ParamDictionaryAttribute), false);
}