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


C# ParameterInfo.GetCustomAttribute方法代码示例

本文整理汇总了C#中System.Reflection.ParameterInfo.GetCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterInfo.GetCustomAttribute方法的具体用法?C# ParameterInfo.GetCustomAttribute怎么用?C# ParameterInfo.GetCustomAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.ParameterInfo的用法示例。


在下文中一共展示了ParameterInfo.GetCustomAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RegisterRoute

        public async Task RegisterRoute(Uri route, ParameterInfo triggerParameter, ITriggeredFunctionExecutor executor)
        {
            await EnsureServerOpen();

            string routeKey = route.LocalPath.ToLowerInvariant();

            if (_functions.ContainsKey(routeKey))
            {
                throw new InvalidOperationException(string.Format("Duplicate route detected. There is already a route registered for '{0}'", routeKey));
            }

            _functions.AddOrUpdate(routeKey, executor, (k, v) => { return executor; });

            WebHookTriggerAttribute attribute = triggerParameter.GetCustomAttribute<WebHookTriggerAttribute>();
            IWebHookReceiver receiver = null;
            string receiverId = string.Empty;
            string receiverLog = string.Empty;
            if (attribute != null && _webHookReceiverManager.TryParseReceiver(route.LocalPath, out receiver, out receiverId))
            {
                receiverLog = string.Format(" (Receiver: '{0}', Id: '{1}')", receiver.Name, receiverId);
            }

            MethodInfo method = (MethodInfo)triggerParameter.Member;
            string methodName = string.Format("{0}.{1}", method.DeclaringType, method.Name);
            _trace.Verbose(string.Format("WebHook route '{0}' registered for function '{1}'{2}", route.LocalPath, methodName, receiverLog));
        }
开发者ID:paulbatum,项目名称:azure-webjobs-sdk-extensions,代码行数:26,代码来源:WebHookDispatcher.cs

示例2: FileTriggerBinding

 public FileTriggerBinding(FilesConfiguration config, ParameterInfo parameter)
 {
     _config = config;
     _parameter = parameter;
     _attribute = parameter.GetCustomAttribute<FileTriggerAttribute>(inherit: false);
     _bindingContract = CreateBindingContract();
 }
开发者ID:oaastest,项目名称:azure-webjobs-sdk-extensions,代码行数:7,代码来源:FileTriggerBinding.cs

示例3: GetAccountOverrideOrNull

        /// <summary>
        /// Walk from the parameter up to the containing type, looking for a
        /// <see cref="StorageAccountAttribute"/>. If found, return the account.
        /// </summary>
        internal static string GetAccountOverrideOrNull(ParameterInfo parameter)
        {
            if (parameter == null || 
                parameter.GetType() == typeof(AttributeBindingSource.FakeParameterInfo))
            {
                return null;
            }

            StorageAccountAttribute attribute = parameter.GetCustomAttribute<StorageAccountAttribute>();
            if (attribute != null)
            {
                return attribute.Account;
            }

            attribute = parameter.Member.GetCustomAttribute<StorageAccountAttribute>();
            if (attribute != null)
            {
                return attribute.Account;
            }

            attribute = parameter.Member.DeclaringType.GetCustomAttribute<StorageAccountAttribute>();
            if (attribute != null)
            {
                return attribute.Account;
            }

            return null;
        }
开发者ID:GPetrites,项目名称:azure-webjobs-sdk,代码行数:32,代码来源:StorageAccountProviderExtensions.cs

示例4: FileBinding

 public FileBinding(FilesConfiguration config, ParameterInfo parameter, BindingTemplate bindingTemplate)
 {
     _config = config;
     _parameter = parameter;
     _bindingTemplate = bindingTemplate;
     _attribute = _parameter.GetCustomAttribute<FileAttribute>(inherit: false);
 }
开发者ID:paulbatum,项目名称:azure-webjobs-sdk-extensions,代码行数:7,代码来源:FileBinding.cs

示例5: HandleArgumentNotResolved

        private static object HandleArgumentNotResolved(ParsingContext context, ParameterInfo parameterInfo)
        {
            var attribute = parameterInfo.GetCustomAttribute<ArgumentAttribute>();
            if(attribute == null)
            {
                throw new ArgumentException(string.Format("Could not resolve argument: {0}", parameterInfo.Name));
            }

            var startPosition = context.CurrentPosition;
            var separatorPosition = attribute.Separator == '\0' ? -1 : context.Packet.Data.DataAsString.IndexOf(attribute.Separator, startPosition);
            var length = (separatorPosition == -1 ? context.Packet.Data.DataAsString.Length : separatorPosition) - startPosition;
            var valueToParse = context.Packet.Data.DataAsString.Substring(startPosition, length);

            context.CurrentPosition += length + 1;

            switch(attribute.Encoding)
            {
                case ArgumentAttribute.ArgumentEncoding.HexNumber:
                    return Parse(parameterInfo.ParameterType, valueToParse, NumberStyles.HexNumber);
                case ArgumentAttribute.ArgumentEncoding.DecimalNumber:
                    return Parse(parameterInfo.ParameterType, valueToParse);
                case ArgumentAttribute.ArgumentEncoding.BinaryBytes:
                    return context.Packet.Data.DataAsBinary.Skip(startPosition).ToArray();
                case ArgumentAttribute.ArgumentEncoding.HexBytesString:
                    return valueToParse.Split(2).Select(x => byte.Parse(x, NumberStyles.HexNumber)).ToArray();
                default:
                    throw new ArgumentException(string.Format("Unsupported argument type: {0}", parameterInfo.ParameterType.Name));
            }
        }
开发者ID:rte-se,项目名称:emul8,代码行数:29,代码来源:Command.cs

示例6: GetParameterSoapName

 internal static string GetParameterSoapName(ParameterInfo parameter)
 {
     var name = parameter.Name ?? parameter.Member.Name + "Result";
     var at = (XmlElementAttribute)parameter.GetCustomAttribute(typeof(XmlElementAttribute));
     if (at != null && !string.IsNullOrWhiteSpace(at.ElementName))
         name = at.ElementName;
     return name;
 }
开发者ID:proff,项目名称:Phalanger,代码行数:8,代码来源:WsdlHelper.cs

示例7: FileTriggerBinding

 public FileTriggerBinding(FilesConfiguration config, ParameterInfo parameter, TraceWriter trace)
 {
     _config = config;
     _parameter = parameter;
     _trace = trace;
     _attribute = parameter.GetCustomAttribute<FileTriggerAttribute>(inherit: false);
     _bindingDataProvider = BindingDataProvider.FromTemplate(_attribute.Path);
     _bindingContract = CreateBindingContract();
 }
开发者ID:JulianoBrugnago,项目名称:azure-webjobs-sdk-extensions,代码行数:9,代码来源:FileTriggerBinding.cs

示例8: ParameterData

        public ParameterData(ParameterInfo parameterInfo)
        {
            Type = parameterInfo.ParameterType;

            Attribute[] attributes = parameterInfo.GetCustomAttributes(typeof(ServiceKeyAttribute)).ToArray();
            if (attributes.Length > 0)
                ServiceKey = ((ServiceKeyAttribute)attributes.First()).Key;

            InjectableAttribute = parameterInfo.GetCustomAttribute<InjectableAttribute>();
        }
开发者ID:ReMinoer,项目名称:Diese,代码行数:10,代码来源:ParameterData.cs

示例9: SyntaxParameter

        public SyntaxParameter(ParameterInfo parameter)
        {
            if (parameter == null)
                throw new ArgumentNullException("parameter");

            Name = parameter.Name;
            ParameterType = parameter.ParameterType;
            IsOptional = parameter.IsOptional;
            IsParams = parameter.GetCustomAttribute<ParamArrayAttribute>() != null;
        }
开发者ID:modulexcite,项目名称:CSharpSyntax,代码行数:10,代码来源:SyntaxParameter.cs

示例10: GetValuesFor

        /// <summary>
        /// Gets a sequence of values that should be tested for the specified parameter.
        /// </summary>
        /// <param name="parameter">The parameter to get possible values for.</param>
        /// <returns>A sequence of values for the parameter.</returns>
        internal static IEnumerable<object> GetValuesFor(ParameterInfo parameter)
        {
            Requires.NotNull(parameter, nameof(parameter));

            var valuesAttribute = parameter.GetCustomAttribute<CombinatorialValuesAttribute>();
            if (valuesAttribute != null)
            {
                return valuesAttribute.Values;
            }

            return GetValuesFor(parameter.ParameterType);
        }
开发者ID:AArnott,项目名称:Xunit.Combinatorial,代码行数:17,代码来源:ValuesUtilities.cs

示例11: Load

        private object Load(HttpApiContext context, ParameterInfo p)
        {
            string key = p.Name;
            var source = ModelSource.FormOrQuery;
            var ms = p.GetCustomAttribute<ModelSourceAttribute>();
            if (ms != null)
            {
                source = ms.ModelSource;
                if (!string.IsNullOrWhiteSpace(ms.Name))
                {
                    key = ms.Name;
                }
            }

            var pt = p.ParameterType;

            object value = LoadValue(context, source, key, pt) ?? p.DefaultValue;
            if (value == null)
            {
                
                if (pt.IsValueType)
                    return Activator.CreateInstance(pt);
                if (pt == typeof(string))
                    return value;
                if (pt.GetGenericTypeDefinition() == typeof(Nullable<>))
                    return value;
            }

            /// load model from form..
            if (source == ModelSource.FormOrQuery)
            {

            }
            else
            {
                var model = context.Request.Form["formModel"];
                return JsonConvert.DeserializeObject(model, pt);
            }

            return value;
            
        }
开发者ID:neurospeech,项目名称:app-web-core,代码行数:42,代码来源:HttpApiController.cs

示例12: EvaluateValidationAttributes

        private void EvaluateValidationAttributes(ParameterInfo parameter, object argument, ModelStateDictionary modelState)
        {
            var validationAttributes = parameter.CustomAttributes;

            foreach (var attributeData in validationAttributes)
            {
                var attributeInstance = parameter.GetCustomAttribute(attributeData.AttributeType);

                var validationAttribute = attributeInstance as ValidationAttribute;

                if (validationAttribute != null)
                {
                    var isValid = validationAttribute.IsValid(argument);
                    if (!isValid)
                    {
                        modelState.AddModelError(parameter.Name, validationAttribute.FormatErrorMessage(parameter.Name));
                    }
                }
            }
        }
开发者ID:hotdiggitydoddo,项目名称:sugarmama,代码行数:20,代码来源:ValidateModelStateAttribute.cs

示例13: GetAccountOverrideOrNull

        internal static string GetAccountOverrideOrNull(ParameterInfo parameter)
        {
            ServiceBusAccountAttribute attribute = parameter.GetCustomAttribute<ServiceBusAccountAttribute>();
            if (attribute != null)
            {
                return attribute.Account;
            }

            attribute = parameter.Member.GetCustomAttribute<ServiceBusAccountAttribute>();
            if (attribute != null)
            {
                return attribute.Account;
            }

            attribute = parameter.Member.DeclaringType.GetCustomAttribute<ServiceBusAccountAttribute>();
            if (attribute != null)
            {
                return attribute.Account;
            }

            return null;
        }
开发者ID:ConnorMcMahon,项目名称:azure-webjobs-sdk,代码行数:22,代码来源:ServiceBusAccount.cs

示例14: TryGetRange

        /// <summary>
        ///   Tries to get the valid range of a distribution's parameter.
        /// </summary>
        /// 
        public static bool TryGetRange(ParameterInfo parameter, out DoubleRange range)
        {
            range = new DoubleRange(0, 0);

            var attrb = parameter.GetCustomAttribute<RangeAttribute>();
            if (attrb == null)
                return false;

            double min = (double)Convert.ChangeType(attrb.Minimum, typeof(double));
            double max = (double)Convert.ChangeType(attrb.Maximum, typeof(double));

            range = new DoubleRange(min, max);

            return true;
        }
开发者ID:amurshed,项目名称:statistics-workbench,代码行数:19,代码来源:DistributionManager.cs

示例15: GetParameterBinder

        private static ITypeBinder GetParameterBinder(ParameterInfo parameter)
        {
            try
            {
                var typeBinderAttribute = parameter.GetCustomAttribute<TypeBinderAttribute>(false);

                return typeBinderAttribute ?? TypeBinderRegistry.GetBinder(parameter.ParameterType);
            }
            catch (AmbiguousMatchException)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError, String.Format(CultureInfo.InvariantCulture,
                                                                                                  Resources.Global.MultipleTypeBindersPerParameter,
                                                                                                  parameter.Name,
                                                                                                  parameter.Member.Name,
                                                                                                  parameter.Member.DeclaringType != null ? parameter.Member.DeclaringType.Name : String.Empty));
            }
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:17,代码来源:ParameterValueProvider.cs


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