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


C# ParameterInfo.GetCustomAttributes方法代码示例

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


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

示例1: Argument

        public Argument(object target, ParameterInfo mi)
            : base(target, mi)
        {
            _default = null;
            _required = true;
            _allArguments = Parameter.IsDefined(typeof (AllArgumentsAttribute), true);

            if (Parameter.DefaultValue != DBNull.Value)
            {
                _default = Parameter.DefaultValue;
                _required = false;
            }

            foreach (DefaultValueAttribute a in mi.GetCustomAttributes(typeof (DefaultValueAttribute), true))
            {
                _default = a.Value;
                _required = false;
            }

            foreach (ArgumentAttribute a in mi.GetCustomAttributes(typeof (ArgumentAttribute), true))
            {
                if (a.HasDefault)
                {
                    _required = false;
                    _default = a.DefaultValue;
                }
            }

            if (Visible && _description == mi.ToString())
            {
                if (IsFlag)
                {
                    if (Required)
                        _description = String.Format("Required flag can be \"/{0}\" or \"/{0}:false\".", base.DisplayName);
                    else
                        _description = String.Format("Optional flag of \"/{0}\" or \"/{0}:false\".", base.DisplayName);
                }
                else
                {
                    if (Required)
                        _description = String.Format("Specifies the required value for \"{0}\" of type {1}.", base.DisplayName,
                            UnderlyingType.Name);
                    else
                        _description = String.Format("Specifies an optional value for \"{0}\" of type {1}.", base.DisplayName,
                            UnderlyingType.Name);
                }
            }
        }
开发者ID:andy-uq,项目名称:Echo,代码行数:48,代码来源:Argument.cs

示例2: ResolveValue

    /// <summary>
    /// Resolves the value for the parameter.
    /// </summary>
    /// <param name="value">The initial value.</param>
    /// <param name="parameter">The parameter.</param>
    /// <returns>The new value.</returns>
    protected override object ResolveValue(object value, ParameterInfo parameter)
    {
      IEnumerable<string> configurationNodes = parameter.GetCustomAttributes(typeof(SitecoreConfigurationReferenceAttribute)).Cast<SitecoreConfigurationReferenceAttribute>().Select(attribute => attribute.ConfigurationNode);

      if (!configurationNodes.Any())
      {
        configurationNodes = parameter.Member.GetCustomAttributes(typeof(SitecoreConfigurationReferenceAttribute)).Cast<SitecoreConfigurationReferenceAttribute>().Select(attribute => attribute.ConfigurationNode);
        
        if (parameter.Member.ReflectedType != null)
        {
          configurationNodes = configurationNodes.Union(parameter.Member.ReflectedType.GetCustomAttributes(typeof(SitecoreConfigurationReferenceAttribute)).Cast<SitecoreConfigurationReferenceAttribute>().Select(attribute => attribute.ConfigurationNode));
          configurationNodes = configurationNodes.Union(parameter.Member.ReflectedType.Assembly.GetCustomAttributes(typeof(SitecoreConfigurationReferenceAttribute)).Cast<SitecoreConfigurationReferenceAttribute>().Select(attribute => attribute.ConfigurationNode));
        }
      }

      XmlNode targetNode = null;

      foreach (string configurationNode in configurationNodes)
      {
        XmlNode nodeCandidate = Factory.GetConfigNode(configurationNode, true);

        if (parameter.ParameterType.IsAssignableFrom(Factory.CreateType(nodeCandidate, true)))
        {
          if (targetNode != null)
          {
            throw new InvalidOperationException(string.Format("Cannot resolve value for argument '{0}'. There are several configuration nodes applicable to this argument.", parameter.Name));
          }

          targetNode = nodeCandidate;
        }
      }

      return Factory.CreateObject(targetNode, true);
    }
开发者ID:sergeyshushlyapin,项目名称:Sitecore.LiveTesting,代码行数:40,代码来源:SitecoreArgumentProvider.cs

示例3: GetARDataBindPrefix

 public virtual string GetARDataBindPrefix(ParameterInfo p)
 {
     var db = p.GetCustomAttributes<ARDataBindAttribute>();
     if (db.Length == 0)
         return null;
     return db[0].Prefix;
 }
开发者ID:ruanzx,项目名称:mausch,代码行数:7,代码来源:ARUtils.cs

示例4: AppendParameterInfo

 private static void AppendParameterInfo(StringBuilder toolTipText, ParameterInfo parameterInfo, bool isLastParameter)
 {
     System.Type parameterType = parameterInfo.ParameterType;
     if (parameterType != null)
     {
         if (parameterType.IsByRef)
         {
             if (parameterInfo.IsOut)
             {
                 toolTipText.Append("out ");
             }
             else
             {
                 toolTipText.Append("ref ");
             }
             parameterType = parameterType.GetElementType();
         }
         else if (isLastParameter && parameterType.IsArray)
         {
             object[] customAttributes = parameterInfo.GetCustomAttributes(typeof(ParamArrayAttribute), false);
             if ((customAttributes != null) && (customAttributes.Length > 0))
             {
                 toolTipText.Append("params ");
             }
         }
         toolTipText.Append(RuleDecompiler.DecompileType(parameterType));
         toolTipText.Append(" ");
     }
     toolTipText.Append(parameterInfo.Name);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:IntellisenseTextBox.cs

示例5: GetARFetch

 public virtual string GetARFetch(ParameterInfo p)
 {
     var db = p.GetCustomAttributes<ARFetchAttribute>();
     if (db.Length == 0)
         return null;
     return db[0].RequestParameterName ?? p.Name;
 }
开发者ID:ruanzx,项目名称:mausch,代码行数:7,代码来源:ARUtils.cs

示例6: TryGetDefaultValue

        public static bool TryGetDefaultValue(ParameterInfo parameterInfo, out object value)
        {
            // this will get the default value as seen by the VB / C# compilers
            // if no value was baked in, RawDefaultValue returns DBNull.Value
            object rawDefaultValue = null;
            try {
              rawDefaultValue = parameterInfo.RawDefaultValue;
            }
            catch (NotImplementedException) {
              rawDefaultValue = null;
            }
            if (rawDefaultValue != DBNull.Value) {
                value = rawDefaultValue;
                return true;
            }

            // if the compiler did not bake in a default value, check the [DefaultValue] attribute
            DefaultValueAttribute[] attrs = (DefaultValueAttribute[])parameterInfo.GetCustomAttributes(typeof(DefaultValueAttribute), false);
            if (attrs == null || attrs.Length == 0) {
                value = default(object);
                return false;
            }
            else {
                value = attrs[0].Value;
                return true;
            }
        }
开发者ID:sztupy,项目名称:monosystemwebmvc,代码行数:27,代码来源:ParameterInfoUtil.cs

示例7: ResolveValue

    /// <summary>
    /// Resolves the value for the parameter.
    /// </summary>
    /// <param name="value">The initial value.</param>
    /// <param name="parameter">The parameter.</param>
    /// <returns>The new value.</returns>
    protected override object ResolveValue(object value, ParameterInfo parameter)
    {
      SitecoreConfigurationMapAttribute mapping = parameter.GetCustomAttributes(typeof(SitecoreConfigurationMapAttribute)).Cast<SitecoreConfigurationMapAttribute>().SingleOrDefault(map => map.ArgumentType == parameter.ParameterType);

      if (mapping == null)
      {
        mapping = parameter.Member.GetCustomAttributes(typeof(SitecoreConfigurationMapAttribute)).Cast<SitecoreConfigurationMapAttribute>().SingleOrDefault(map => map.ArgumentType == parameter.ParameterType);
      }

      if (mapping == null)
      {
        mapping = parameter.Member.ReflectedType.GetCustomAttributes(typeof(SitecoreConfigurationMapAttribute)).Cast<SitecoreConfigurationMapAttribute>().SingleOrDefault(map => map.ArgumentType == parameter.ParameterType);
      }

      if (mapping == null)
      {
        mapping = parameter.Member.ReflectedType.Assembly.GetCustomAttributes(typeof(SitecoreConfigurationMapAttribute)).Cast<SitecoreConfigurationMapAttribute>().SingleOrDefault(map => map.ArgumentType == parameter.ParameterType);
      }

      if (mapping == null)
      {
        return null;
      }

      return Factory.CreateObject(mapping.ConfigurationNode, true);
    }
开发者ID:maxshell,项目名称:Sitecore.LiveTesting,代码行数:32,代码来源:SitecoreArgumentProvider.cs

示例8: GetCustomAttribute

 internal static object GetCustomAttribute(Type type, ParameterInfo pi)
 {
     object [] attributes = pi.GetCustomAttributes (type, true);
     if (attributes.Length < 1)
         return null;
     return attributes [0];
 }
开发者ID:arifbudiman,项目名称:TridionMinifier,代码行数:7,代码来源:CliHelper.cs

示例9: GetServiceName

        /// <summary>
        /// Gets the service name based on the given <paramref name="parameter"/>.
        /// </summary>
        /// <param name="parameter">The <see cref="ParameterInfo"/> for which to get the service name.</param>
        /// <returns>The name of the service for the given <paramref name="parameter"/>.</returns>
        private string GetServiceName(ParameterInfo parameter)
        {
            var injectAttribute =
                      (InjectAttribute)
                      parameter.GetCustomAttributes(typeof(InjectAttribute), true).FirstOrDefault();

            return injectAttribute != null ? injectAttribute.ServiceName : parameter.Name;
        }
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:13,代码来源:AnnotatedConstructorSelector.cs

示例10: GetAttributesForParameter

        /// <summary>
        /// Gets the attributes for the given <paramref name="parameter"/>.
        /// </summary>
        /// <param name="parameter">A <see cref="ParameterInfo"/> for which attributes need to be resolved.
        /// </param>
        /// <returns>An <see cref="IEnumerable{object}"/> containing the attributes on the
        /// <paramref name="parameter"/> before the attributes on the <paramref name="parameter"/> type.</returns>
        public static IEnumerable<object> GetAttributesForParameter(ParameterInfo parameter)
        {
            // Return the parameter attributes first.
            var parameterAttributes = parameter.GetCustomAttributes();
            var typeAttributes = parameter.ParameterType.GetTypeInfo().GetCustomAttributes();

            return parameterAttributes.Concat(typeAttributes);
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:15,代码来源:ModelAttributes.cs

示例11: XlParameterInfo

        // allowing Custom Marshaling to be injected
        public XlParameterInfo(ParameterInfo paramInfo)
        {
            // Add Name and Description
            // CONSIDER: Override Marshaler for row/column arrays according to some attribute

            // Some pre-checks
            if (paramInfo.ParameterType.IsByRef)
                throw new DnaMarshalException("Parameter is ByRef: " + paramInfo.Name);

            // Default Name and Description
            Name = paramInfo.Name;
            Description = "";
            AllowReference = false;

            // Get Description
            object[] attribs = paramInfo.GetCustomAttributes(false);
            // Search through attribs for Description
            foreach (object attrib in attribs)
            {
                System.ComponentModel.DescriptionAttribute desc =
                    attrib as System.ComponentModel.DescriptionAttribute;
                if (desc != null)
                {
                    Description = desc.Description;
                }
                //// HACK: Some problem with library references -
                //// For now relax the assembly reference and use late-bound
                Type attribType = attrib.GetType();
                if (TypeHelper.TypeHasAncestorWithFullName(attribType, "ExcelDna.Integration.ExcelArgumentAttribute"))
                {
                    string name = (string)attribType.GetField("Name").GetValue(attrib);
                    string description = (string)attribType.GetField("Description").GetValue(attrib);
                    object allowReference = attribType.GetField("AllowReference").GetValue(attrib);

                    if (name != null)
                        Name = name;
                    if (description != null)
                        Description = description;
                    if (allowReference != null)
                        AllowReference = (bool)allowReference;
                }
                // HACK: Here is the other code:
                //ExcelArgumentAttribute xlparam = attrib as ExcelArgumentAttribute;
                //if (xlparam != null)
                //{
                //    if (xlparam.Name != null)
                //    {
                //        Name = xlparam.Name;
                //    }
                //    if (xlparam.Description != null)
                //    {
                //        Description = xlparam.Description;
                //    }
                //    AllowReference = xlparam.AllowReference;
                //}
            }
            SetTypeInfo(paramInfo.ParameterType, false, false);
        }
开发者ID:cortpcl,项目名称:ddsc-excel-import,代码行数:59,代码来源:XlParameterInfo.cs

示例12: ChangeToCompatibleType

 /// <summary>
 /// Converts an object to a type compatible with a given parameter.
 /// </summary>
 /// <param name="value">The object value to convert.</param>
 /// <param name="destinationType">The destination <see cref="Type"/> to which <paramref name="value"/> should be converted.</param>
 /// <param name="memberInfo">The parameter for which the <paramref name="value"/> is being converted.</param>
 /// <returns>
 /// An <see cref="Object"/> of type <paramref name="destinationType"/>, converted using
 /// type converters specified on <paramref name="memberInfo"/> if available. If <paramref name="value"/>
 /// is <see langword="null"/> then the output will be <see langword="null"/> for reference
 /// types and the default value for value types.
 /// </returns>
 /// <exception cref="InvalidOperationException">
 /// Thrown if conversion of the value fails.
 /// </exception>
 public static object ChangeToCompatibleType(object value, Type destinationType, ParameterInfo memberInfo)
 {
     TypeConverterAttribute attrib = null;
     if (memberInfo != null)
     {
         attrib = memberInfo.GetCustomAttributes(typeof(TypeConverterAttribute), true).Cast<TypeConverterAttribute>().FirstOrDefault();
     }
     return ChangeToCompatibleType(value, destinationType, attrib);
 }
开发者ID:MyLobin,项目名称:Autofac.Configuration,代码行数:24,代码来源:TypeManipulation.cs

示例13: GetFromParameter

		public static TemplateDefaultValueAttribute GetFromParameter(ParameterInfo parameter)
		{
			object[] attributes = parameter.GetCustomAttributes(typeof(TemplateDefaultValueAttribute), true);

			if (attributes == null || attributes.Length == 0)
				return null;

			return (TemplateDefaultValueAttribute)attributes[0];
		}
开发者ID:huchao007,项目名称:bbsmax,代码行数:9,代码来源:TemplateDefaultValueAttribute.cs

示例14: DescribeParameter

 public static string DescribeParameter(ParameterInfo parameter)
 {
     var result = string.Empty;
     if (parameter.IsOut) result += "out ";
     if (parameter.IsRetval) result += "ref ";
     if (parameter.GetCustomAttributes(typeof(ParamArrayAttribute), true).Length > 0) result += "params ";
     result += DescribeType(parameter.ParameterType);
     return result.Trim();
 }
开发者ID:PaulStovell,项目名称:bindable,代码行数:9,代码来源:ReflectionHelper.cs

示例15: 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


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