本文整理汇总了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;
}
示例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()
};
}
示例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));
}
示例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;
}
示例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));
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例11: GetArgs
private IEnumerable<object> GetArgs(ConstructorInfo constructor, Property property)
{
foreach (var parameter in constructor.GetParameters())
{
yield return GetArg(parameter.ParameterType, property);
}
}
示例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;
}
示例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;
}
}
}
示例14: IsParameterMatch
private static bool IsParameterMatch(ConstructorInfo ctor, Type[] expectedParamters)
{
var ctorParams = ctor.GetParameters();
return ctorParams.Select(p => p.ParameterType)
.ToArray()
.IsSequenceEqual(expectedParamters);
}
示例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);
}