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


C# ConstructorInfo.GetCustomAttributes方法代码示例

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


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

示例1: WriteCustomAttributes

		private void WriteCustomAttributes(XmlWriter writer, ConstructorInfo constructorInfo)
		{
			try
			{
				WriteCustomAttributes(writer, constructorInfo.GetCustomAttributes(this.rep.DocumentInheritedAttributes), "");
			}
			catch (Exception e)
			{
				TraceErrorOutput("Error retrieving custom attributes for " + MemberID.GetMemberID(constructorInfo), e);
			}
		}
开发者ID:ceefour,项目名称:aphrodox,代码行数:11,代码来源:ReflectionEngine.cs

示例2: FormatConstructor

        /// <summary>
        /// Formats the constructor.
        /// </summary>
        /// <param name="constructor">The constructor.</param>
        /// <param name="sw">The string writer.</param>
        private static void FormatConstructor(ConstructorInfo constructor, StringWriter sw)
        {
            foreach (Attribute attribute in constructor.GetCustomAttributes(false))
            {
                FormatAttribute(sw, attribute);
            }

            sw.Write(constructor.DeclaringType.GetTypeInfo().Name);
            sw.Write("(");
            foreach (var parameterInfo in constructor.GetParameters())
            {
                foreach (Attribute attribute in parameterInfo.GetCustomAttributes(false))
                {
                    FormatAttribute(sw, attribute);
                }

                sw.Write(parameterInfo.ParameterType.Format());
                sw.Write(" ");
                sw.Write(parameterInfo.Name);
            }

            sw.WriteLine(")");
        }
开发者ID:remogloor,项目名称:ninject,代码行数:28,代码来源:ExceptionFormatter.cs

示例3: IsConstructable

		public static bool IsConstructable( ConstructorInfo ctor, AccessLevel accessLevel )
		{
			object[] attrs = ctor.GetCustomAttributes( m_ConstructableType, false );

			if ( attrs.Length == 0 )
				return false;

			return accessLevel >= ((ConstructableAttribute)attrs[0]).AccessLevel;
		}
开发者ID:nathanvy,项目名称:runuo,代码行数:9,代码来源:Add.cs

示例4: HasInjectAttribute

 private bool HasInjectAttribute(ConstructorInfo constructor)
 {
     return constructor.GetCustomAttributes(false).Any(a => a.GetType().Name.ToLower().Contains("inject"));
 }
开发者ID:yln,项目名称:Nukito,代码行数:4,代码来源:SingleCtorWithInjectAttributeConstructorChooser.cs

示例5: GetConstructorExpression

            public Expression GetConstructorExpression(out ConstructorInfo constructorInfo, out IEnumerable<Expression> constructorParameters)
            {
                CompiledExportDelegateInfo exportDelegateInfo = _instanceCompiledExport.exportDelegateInfo;

                constructorInfo = _instanceCompiledExport.exportDelegateInfo.ImportConstructor ??
                                  _instanceCompiledExport.PickConstructor(exportDelegateInfo.ActivationType);

                if (constructorInfo == null)
                {
                    throw new PublicConstructorNotFoundException(exportDelegateInfo.ActivationType);
                }

                List<Expression> parameters = new List<Expression>();
                constructorParameters = parameters;

                Attribute[] constructorAttributes = constructorInfo.GetCustomAttributes(true).ToArray();

                if (constructorAttributes.Length == 0)
                {
                    constructorAttributes = EmptyAttributesArray;
                }

                foreach (ParameterInfo parameterInfo in constructorInfo.GetParameters())
                {
                    Attribute[] parameterAttributes = parameterInfo.GetCustomAttributes(true).ToArray();

                    if (parameterAttributes.Length == 0)
                    {
                        parameterAttributes = EmptyAttributesArray;
                    }

                    IExportValueProvider valueProvider = null;
                    ExportStrategyFilter exportStrategyFilter = null;
                    string importName = null;
                    object comparerObject = null;
                    ILocateKeyValueProvider locateKey = null;

                    if (exportDelegateInfo.ConstructorParams != null)
                    {
                        foreach (ConstructorParamInfo constructorParamInfo in exportDelegateInfo.ConstructorParams)
                        {
                            if (string.Compare(parameterInfo.Name,
                                constructorParamInfo.ParameterName,
                                StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                importName = constructorParamInfo.ImportName;
                                exportStrategyFilter = constructorParamInfo.ExportStrategyFilter;
                                valueProvider = constructorParamInfo.ValueProvider;
                                comparerObject = constructorParamInfo.ComparerObject;
                                locateKey = constructorParamInfo.LocateKeyProvider;
                                break;
                            }
                        }

                        if (valueProvider == null)
                        {
                            foreach (ConstructorParamInfo constructorParamInfo in exportDelegateInfo.ConstructorParams)
                            {
                                if (string.IsNullOrEmpty(constructorParamInfo.ParameterName) &&
                                    parameterInfo.ParameterType.GetTypeInfo().IsAssignableFrom(
                                        constructorParamInfo.ParameterType.GetTypeInfo()))
                                {
                                    importName = constructorParamInfo.ImportName;
                                    exportStrategyFilter = constructorParamInfo.ExportStrategyFilter;
                                    valueProvider = constructorParamInfo.ValueProvider;
                                    comparerObject = constructorParamInfo.ComparerObject;
                                    locateKey = constructorParamInfo.LocateKeyProvider;
                                    break;
                                }
                            }
                        }
                    }

                    InjectionTargetInfo targetInfo = null;

                    if (importName != null)
                    {
                        targetInfo = new InjectionTargetInfo(exportDelegateInfo.ActivationType,
                            _instanceCompiledExport.activationTypeAttributes,
                            parameterInfo,
                            parameterAttributes,
                            constructorAttributes,
                            importName,
                            null);
                    }
                    else if (InjectionKernel.ImportTypeByName(parameterInfo.ParameterType))
                    {
                        targetInfo = new InjectionTargetInfo(exportDelegateInfo.ActivationType,
                            _instanceCompiledExport.activationTypeAttributes,
                            parameterInfo,
                            parameterAttributes,
                            constructorAttributes,
                            parameterInfo.Name,
                            null);
                    }
                    else
                    {
                        targetInfo = new InjectionTargetInfo(exportDelegateInfo.ActivationType,
                            _instanceCompiledExport.activationTypeAttributes,
                            parameterInfo,
//.........这里部分代码省略.........
开发者ID:jrjohn,项目名称:Grace,代码行数:101,代码来源:InstanceCompiledExportDelegate.cs

示例6: Constructor

        public Constructor(ConstructorInfo constructorInfo, Dictionary<string, object> parameterDictionary)
        {
            _constructorInfo = constructorInfo;
            _parameterNames = new List<string>();
            _parameterTypes = new List<Type>();
            _match = true;
            _usedAllParameters = true;

            // look through the constructor attributes for a RegisterConstructorAttribute
            // if this attribute exists, the factory is allowed to use the constructor.
            var registerConstructorAttributes = (RegisterConstructorAttribute[])_constructorInfo.GetCustomAttributes(typeof(RegisterConstructorAttribute), false);
            if (registerConstructorAttributes.Length == 0)
            {
                _match = false;
                _usedAllParameters = false;
                return;
            }

            // populate _parameterNames and _parameterTypes from _constructorInfo
            ParameterInfo[] parameterInfos = _constructorInfo.GetParameters();
            foreach (ParameterInfo parameterInfo in parameterInfos)
            {
                var factoryParameterAttributes = (FactoryParameterAttribute[])parameterInfo.GetCustomAttributes(typeof(FactoryParameterAttribute),false);

                string parameterName = parameterInfo.Name.ToLower(); // use raw parameter name
                if (factoryParameterAttributes.Length == 1) parameterName = factoryParameterAttributes[0].RegisteredName; // replace with friendly name for the parameter.
                else if (factoryParameterAttributes.Length > 1) throw new Exception("Parameter can have at most one FactoryParameterAttribute");
                _parameterNames.Add(parameterName);
                _parameterTypes.Add(parameterInfo.ParameterType);
            }

            // populate _parameterValues from parameterDictionary
            _parameterValues = new object[_parameterNames.Count];
            for (int i = 0; i < _parameterNames.Count; ++i)
            {
                string parameterName = _parameterNames[i].ToLower();
                Type parameterType = _parameterTypes[i];
                object parameterValue;
                if (parameterDictionary.ContainsKey(parameterName))
                {
                    parameterValue = parameterDictionary[parameterName];
                    if (!parameterType.IsInstanceOfType(parameterValue)) // Parameter parameterName has the wrong type
                    {
                        if (parameterValue.GetType() == typeof(Dictionary<string, object>))
                        {
                            var dictionary = (Dictionary<string, object>) parameterValue;
                            MethodInfo factoryGetInstanceMethod = typeof(Factory).GetMethod("GetInstance").MakeGenericMethod(parameterType);
                            try
                            {
                                parameterValue = factoryGetInstanceMethod.Invoke(null, new object[] { dictionary });
                            }
                            catch (TargetInvocationException e)
                            {
                                throw new Exception(e.InnerException.Message);
                            }
                        }
                        else
                            _match = false;
                    }
                }
                else // Can't find parameter parameterName in parameterDictionary
                {
                    _match = false;
                    parameterValue = new object();
                }
                _parameterValues[i] = parameterValue;
            }

            // check to see whether all parameters in parameterDictionary have been used up
            foreach (KeyValuePair<string, object> entry in parameterDictionary.Where(entry => entry.Key != "name" && !_parameterNames.Contains(entry.Key)))
                _usedAllParameters = false;
        }
开发者ID:Laeeth,项目名称:d_excelsdk,代码行数:72,代码来源:Constructor.cs

示例7: GetCAL

		public static CAL GetCAL(ConstructorInfo ctor)
		{
			object[] attrs = ctor.GetCustomAttributes(m_ConstructableAccessLevel, false);

			if (attrs.Length == 0)
				return null;

			return attrs[0] as CAL;
		}
开发者ID:kamronbatman,项目名称:DefianceUO-Pre1.10,代码行数:9,代码来源:Add.cs

示例8: PublicConstructor_IsTaggedWithPublicAPIAttribute

 public void PublicConstructor_IsTaggedWithPublicAPIAttribute(ConstructorInfo constructor)
 {
     bool attributeIsPresent = constructor.GetCustomAttributes(typeof(PublicAPIAttribute), true).Any();
     Assume.That(constructor.DeclaringType != null);
     Assert.That(attributeIsPresent, "Constructor (" + string.Join(", ", constructor.GetParameters().Select(p => p.ParameterType.Name)) + " of type " + constructor.DeclaringType.Name + " is not tagged with [PublicAPI]");
 }
开发者ID:modulexcite,项目名称:commander,代码行数:6,代码来源:PublicAPITests.cs

示例9: GetAttribute

        public static ExcelObjectConstructorAttribute GetAttribute(ConstructorInfo ci)
        {
            object[] o = ci.GetCustomAttributes(typeof(ExcelObjectConstructorAttribute), false);
            ExcelObjectConstructorAttribute r = (ExcelObjectConstructorAttribute)o[0];

            return r;
        }
开发者ID:robhowley,项目名称:xldna-object-handler,代码行数:7,代码来源:CacheUtilities.cs

示例10: BuildConstructorDefinition

 private static ConstructorDefinition BuildConstructorDefinition(ConstructorInfo constructorInfo)
 {
     IEnumerable<ParameterDefinition> parameters = constructorInfo
         .GetParameters()
         .Select(p => new ParameterDefinition(p.Name, p.ParameterType));
     ConstructorMethod constructorMethod = ObjectInterfaceProvider.GetConstructor(constructorInfo);
     bool isPreferredConstructor = constructorInfo.GetCustomAttributes(typeof(SerializationConstructorAttribute), true).Any();
     return new ConstructorDefinition(constructorMethod, parameters, isPreferredConstructor);
 }
开发者ID:soxtoby,项目名称:ForSerial,代码行数:9,代码来源:TypeDefinition.cs


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