当前位置: 首页>>代码示例>>C#>>正文


C# ParameterInfo.IsDefined方法代码示例

本文整理汇总了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

            }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:15,代码来源:ParameterWrapper.cs

示例2: ParameterWrapper

        public ParameterWrapper(ActionBinder binder, ParameterInfo info)
            : this(binder, info.ParameterType)
        {
            _name = SymbolTable.StringToId(info.Name ?? "<unknown>");

            _isParams = info.IsDefined(typeof(ParamArrayAttribute), false);
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:7,代码来源:ParameterWrapper.cs

示例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);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:26,代码来源:RubyParameterBinder.cs

示例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;
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:8,代码来源:Parameter.cs

示例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);
        }
开发者ID:BackupTheBerlios,项目名称:tamjb,代码行数:18,代码来源:JsonRpcServiceReflector.cs

示例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);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:Attribute.cs

示例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);
 }
开发者ID:undeadcat,项目名称:simple-container,代码行数:66,代码来源:SimpleContainer.cs

示例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;
 }
开发者ID:qhhndaye888,项目名称:Cyjb,代码行数:13,代码来源:MethodExt.cs

示例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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:23,代码来源:Attribute.cs

示例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);
            }
        }
开发者ID:BrianGenisio,项目名称:ironruby,代码行数:15,代码来源:ClsTypeEmitter.cs

示例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;
        }
开发者ID:Clockwork-Muse,项目名称:coreclr,代码行数:37,代码来源:Attribute.cs

示例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);
 }
开发者ID:yudhitech,项目名称:xamarin-android,代码行数:12,代码来源:ParameterDataProvider.cs

示例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);
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:8,代码来源:customattribute.cs

示例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);
        }
开发者ID:krbvroc1,项目名称:KeeFox,代码行数:21,代码来源:JsonRpcServiceReflector.cs

示例15: IsParamDictionary

 public static bool IsParamDictionary(ParameterInfo parameter) {
     return parameter.IsDefined(typeof(ParamDictionaryAttribute), false);
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:3,代码来源:BinderHelpers.cs


注:本文中的System.Reflection.ParameterInfo.IsDefined方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。