本文整理汇总了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));
}
示例2: FileTriggerBinding
public FileTriggerBinding(FilesConfiguration config, ParameterInfo parameter)
{
_config = config;
_parameter = parameter;
_attribute = parameter.GetCustomAttribute<FileTriggerAttribute>(inherit: false);
_bindingContract = CreateBindingContract();
}
示例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;
}
示例4: FileBinding
public FileBinding(FilesConfiguration config, ParameterInfo parameter, BindingTemplate bindingTemplate)
{
_config = config;
_parameter = parameter;
_bindingTemplate = bindingTemplate;
_attribute = _parameter.GetCustomAttribute<FileAttribute>(inherit: false);
}
示例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));
}
}
示例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;
}
示例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();
}
示例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>();
}
示例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;
}
示例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);
}
示例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;
}
示例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));
}
}
}
}
示例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;
}
示例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;
}
示例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));
}
}