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


C# ConstructorInfo.GetParameters方法代码示例

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


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

示例1: IsBetterChoice

        private bool IsBetterChoice(ConstructorInfo current, ConstructorInfo candidate)
        {
            if (candidate.GetParameters().Any(x => x.ParameterType.IsSealed))
                return false;

            return current == null || current.GetParameters().Length < candidate.GetParameters().Length;
        }
开发者ID:gregkowalski,项目名称:Moq.AutoMocker,代码行数:7,代码来源:ConstructorSelector.cs

示例2: ResolveConstructorArguments

        private static ResolvedConstructor ResolveConstructorArguments(ConstructorInfo constructor, IDummyValueCreationSession session)
        {
            Logger.Debug("Beginning to resolve constructor with {0} arguments.", constructor.GetParameters().Length);

            var resolvedArguments = new List<ResolvedArgument>();

            foreach (var argument in constructor.GetParameters())
            {
                object result = null;

                var resolvedArgument = new ResolvedArgument
                                           {
                                               WasResolved = session.TryResolveDummyValue(argument.ParameterType, out result),
                                               ResolvedValue = result,
                                               ArgumentType = argument.ParameterType
                                           };

                Logger.Debug("Was able to resolve {0}: {1}.", argument.ParameterType, resolvedArgument.WasResolved);
                resolvedArguments.Add(resolvedArgument);
            }

            return new ResolvedConstructor
                       {
                           Arguments = resolvedArguments.ToArray()
                       };
        }
开发者ID:jszumigaj,项目名称:FakeItEasy,代码行数:26,代码来源:FakeObjectCreator.cs

示例3: GetConstructor

        public ConstructorMethod GetConstructor(ConstructorInfo constructor)
        {
            DynamicMethod dynamicConstructor = CreateDynamicConstructor(constructor);
            ILGenerator il = dynamicConstructor.GetILGenerator();
            ParameterInfo[] parameters = constructor.GetParameters();
            for (int i = 0; i < parameters.Length; i++)
            {
                il.Emit(OpCodes.Ldarg_0);
                switch (i)
                {
                    case 0: il.Emit(OpCodes.Ldc_I4_0); break;
                    case 1: il.Emit(OpCodes.Ldc_I4_1); break;
                    case 2: il.Emit(OpCodes.Ldc_I4_2); break;
                    case 3: il.Emit(OpCodes.Ldc_I4_3); break;
                    case 4: il.Emit(OpCodes.Ldc_I4_4); break;
                    case 5: il.Emit(OpCodes.Ldc_I4_5); break;
                    case 6: il.Emit(OpCodes.Ldc_I4_6); break;
                    case 7: il.Emit(OpCodes.Ldc_I4_7); break;
                    case 8: il.Emit(OpCodes.Ldc_I4_8); break;
                    default: il.Emit(OpCodes.Ldc_I4, i); break;
                }
                il.Emit(OpCodes.Ldelem_Ref);
                Type paramType = parameters[i].ParameterType;
                il.Emit(paramType.IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass, paramType);
            }
            il.Emit(OpCodes.Newobj, constructor);
            il.BoxIfNeeded(constructor.DeclaringType);
            il.Emit(OpCodes.Ret);

            return (ConstructorMethod)dynamicConstructor.CreateDelegate(typeof(ConstructorMethod));
        }
开发者ID:soxtoby,项目名称:ForSerial,代码行数:31,代码来源:DynamicMethodProvider.cs

示例4: GetParameterCount

 /// <summary>
 /// Gets the number of parameters that the system recognizes
 /// </summary>
 /// <param name="Constructor">Constructor to check</param>
 /// <param name="MappingManager">Mapping manager</param>
 /// <returns>The number of parameters that it has knoweledge of</returns>
 private static int GetParameterCount(ConstructorInfo Constructor, MappingManager MappingManager)
 {
     int Count = 0;
     ParameterInfo[] Parameters = Constructor.GetParameters();
     foreach (ParameterInfo Parameter in Parameters)
     {
         bool Inject = true;
         object[] Attributes = Parameter.GetCustomAttributes(false);
         if (Attributes.Length > 0)
         {
             foreach (Attribute Attribute in Attributes)
             {
                 if (MappingManager.GetMapping(Parameter.ParameterType, Attribute.GetType()) != null)
                 {
                     ++Count;
                     Inject = false;
                     break;
                 }
             }
         }
         if (Inject)
         {
             if (MappingManager.GetMapping(Parameter.ParameterType) != null)
                 ++Count;
         }
     }
     if (Count == Parameters.Length)
         return Count;
     return int.MinValue;
 }
开发者ID:jerrymds,项目名称:Concord,代码行数:36,代码来源:ConstructorList.cs

示例5: ToDescription

        public static string ToDescription(ConstructorInfo constructor)
        {
            var parameters = constructor.GetParameters();
            var paramList = parameters.Select(x => {
                if (x.ParameterType.IsSimple())
                {
                    return "{0} {1}".ToFormat(x.ParameterType.GetTypeName(), x.Name);
                }
                else
                {
                    if (parameters.Where(p => p.ParameterType == x.ParameterType).Count() > 1)
                    {
                        return "{0} {1}".ToFormat(x.ParameterType.GetTypeName(), x.Name);
                    }
                    else
                    {
                        return x.ParameterType.GetTypeName();
                    }
                }
            }).ToArray();



            return "new {0}({1})".ToFormat(constructor.DeclaringType.GetTypeName(), string.Join(", ", paramList));
        }
开发者ID:Kingefosa,项目名称:structuremap,代码行数:25,代码来源:ConstructorStep.cs

示例6: ConstructorMetadata

        /// <summary>
        /// Initializes a new instance of the <see cref="ConstructorMetadata"/> class.
        /// </summary>
        /// <param name="constructorInfo">The constructor information.</param>
        internal ConstructorMetadata(ConstructorInfo constructorInfo)
        {
            ConstructorInfo = constructorInfo;

            Signature = constructorInfo.GetParameters().Select(p => p.ParameterType).ToImmutableArray();
            ParameterNames = constructorInfo.GetParameters().Select(p => p.Name).ToImmutableArray();
        }
开发者ID:docevaad,项目名称:Anchor,代码行数:11,代码来源:ConstructorMetadata.cs

示例7: CtorInfo

        public CtorInfo(ConstructorInfo constructorInfo)
        {
            Contract.Requires<ArgumentNullException>(constructorInfo != null);

            this.constructorInfo = constructorInfo;
            this.parameters = constructorInfo.GetParameters();
            this.paramTypes = constructorInfo.GetParameters().Select(p => p.ParameterType).ToArray();
        }
开发者ID:gordonc64,项目名称:AOtomation.AutoFactory,代码行数:8,代码来源:CtorInfo.cs

示例8: IsBetterChoice

        private bool IsBetterChoice(ConstructorInfo current, ConstructorInfo candidate, Type[] existingTypes)
        {
            if (current == null)
                return true;

            if (candidate.GetParameters()
                         .Where(x => !existingTypes.Contains(x.ParameterType))
                         .Any(x => x.ParameterType.IsSealed && !x.ParameterType.IsArray))
                return false;

            return current.GetParameters().Length < candidate.GetParameters().Length;
        }
开发者ID:BrainCrumbz,项目名称:Moq.AutoMocker,代码行数:12,代码来源:ConstructorSelector.cs

示例9: CanUseConstructor

 protected virtual bool CanUseConstructor(ConstructorInfo constructor, Type viewType, Type pageDataType)
 {
     var constructorParameters = constructor.GetParameters();
     return constructorParameters[0].ParameterType.IsAssignableFrom(viewType) &&
            constructorParameters[1].ParameterType.IsAssignableFrom(pageDataType) &&
            constructorParameters.Length == 2;
 }
开发者ID:MikeHook,项目名称:EPiServer-MVP,代码行数:7,代码来源:EPiPresenterFactory.cs

示例10: HasMissingPrimitives

 public static bool HasMissingPrimitives(ConstructorInfo ctor, DependencyCollection dependencies)
 {
     return ctor
         .GetParameters()
         .Where(x => x.ParameterType.IsSimple())
         .Any(param => dependencies.FindByTypeOrName(param.ParameterType, param.Name) == null);
 }
开发者ID:slahn,项目名称:structuremap,代码行数:7,代码来源:GreediestConstructorSelector.cs

示例11: GetArgs

 private IEnumerable<object> GetArgs(ConstructorInfo constructor, Property property)
 {
     foreach (var parameter in constructor.GetParameters())
     {
         yield return GetArg(parameter.ParameterType, property);
     }
 }
开发者ID:Thecentury,项目名称:Ilaro.Admin,代码行数:7,代码来源:FilterFactory.cs

示例12: MapDestinationCtorToSource

        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo, IProfileConfiguration options)
        {
            var parameters = new List<ConstructorParameterMap>();
            var ctorParameters = destCtor.GetParameters();

            if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
                return false;

            foreach (var parameter in ctorParameters)
            {
                var resolvers = new LinkedList<IValueResolver>();

                var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, parameter.GetType(), parameter.Name, resolvers);
                if(!canResolve && parameter.HasDefaultValue)
                {
                    canResolve = true;
                }

                var param = new ConstructorParameterMap(parameter, resolvers.ToArray(), canResolve);

                parameters.Add(param);
            }

            typeMap.AddConstructorMap(destCtor, parameters);

            return true;
        }
开发者ID:garora,项目名称:AutoMapper,代码行数:27,代码来源:TypeMapFactory.cs

示例13: ConstructorParameterBinding

        /// <summary>
        /// Construct a new ConstructorParameterBinding.
        /// </summary>
        /// <param name="ci">ConstructorInfo to bind.</param>
        /// <param name="availableParameters">Available parameters.</param>
        /// <param name="context">Context in which to construct instance.</param>
        public ConstructorParameterBinding(
            ConstructorInfo ci,
            IEnumerable<Parameter> availableParameters,
            IComponentContext context)
        {
            _canInstantiate = true;
            _ci = Enforce.ArgumentNotNull(ci, "ci");
            if (availableParameters == null) throw new ArgumentNullException("availableParameters");
            if (context == null) throw new ArgumentNullException("context");

            var parameters = ci.GetParameters();
            _valueRetrievers = new Func<object>[parameters.Length];

            for (int i = 0; i < parameters.Length; ++i)
            {
                var pi = parameters[i];
                bool foundValue = false;
                foreach (var param in availableParameters)
                {
                    Func<object> valueRetriever;
                    if (param.CanSupplyValue(pi, context, out valueRetriever))
                    {
                        _valueRetrievers[i] = valueRetriever;
                        foundValue = true;
                        break;
                    }
                }
                if (!foundValue)
                {
                    _canInstantiate = false;
                    _firstNonBindableParameter = pi;
                    break;
                }
            }
        }
开发者ID:RoymanJing,项目名称:Autofac,代码行数:41,代码来源:ConstructorParameterBinding.cs

示例14: IsParameterMatch

 private static bool IsParameterMatch(ConstructorInfo ctor, Type[] expectedParamters)
 {
     var ctorParams = ctor.GetParameters();
     return ctorParams.Select(p => p.ParameterType)
         .ToArray()
         .IsSequenceEqual(expectedParamters);
 }
开发者ID:qooroo,项目名称:HdrHistogram.NET,代码行数:7,代码来源:TypeHelper.cs

示例15: CreateConstructorCandidate

		protected virtual ConstructorCandidate CreateConstructorCandidate(ConstructorInfo constructor)
		{
			ParameterInfo[] parameters = constructor.GetParameters();

			DependencyModel[] dependencies = new DependencyModel[parameters.Length];

			for(int i = 0; i < parameters.Length; i++)
			{
				ParameterInfo parameter = parameters[i];

				Type paramType = parameter.ParameterType;

				// This approach is somewhat problematic. We should use
				// another strategy to differentiate types and classify dependencies
				if (converter.IsSupportedAndPrimitiveType(paramType))
				{
					dependencies[i] = new DependencyModel(
						DependencyType.Parameter, parameter.Name, paramType, false);
				}
				else
				{
					dependencies[i] = new DependencyModel(
						DependencyType.Service, parameter.Name, paramType, false);
				}
			}

			return new ConstructorCandidate(constructor, dependencies);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:28,代码来源:ConstructorDependenciesModelInspector.cs


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