本文整理汇总了C#中System.Reflection.ConstructorInfo类的典型用法代码示例。如果您正苦于以下问题:C# ConstructorInfo类的具体用法?C# ConstructorInfo怎么用?C# ConstructorInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstructorInfo类属于System.Reflection命名空间,在下文中一共展示了ConstructorInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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
示例2: CustomAttributeData
internal CustomAttributeData(Module scope, CustomAttributeRecord caRecord)
{
this.m_scope = scope;
this.m_ctor = (ConstructorInfo) RuntimeType.GetMethodBase(scope, (int) caRecord.tkCtor);
ParameterInfo[] parametersNoCopy = this.m_ctor.GetParametersNoCopy();
this.m_ctorParams = new CustomAttributeCtorParameter[parametersNoCopy.Length];
for (int i = 0; i < parametersNoCopy.Length; i++)
{
this.m_ctorParams[i] = new CustomAttributeCtorParameter(InitCustomAttributeType(parametersNoCopy[i].ParameterType, scope));
}
FieldInfo[] fields = this.m_ctor.DeclaringType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
PropertyInfo[] properties = this.m_ctor.DeclaringType.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
this.m_namedParams = new CustomAttributeNamedParameter[properties.Length + fields.Length];
for (int j = 0; j < fields.Length; j++)
{
this.m_namedParams[j] = new CustomAttributeNamedParameter(fields[j].Name, CustomAttributeEncoding.Field, InitCustomAttributeType(fields[j].FieldType, scope));
}
for (int k = 0; k < properties.Length; k++)
{
this.m_namedParams[k + fields.Length] = new CustomAttributeNamedParameter(properties[k].Name, CustomAttributeEncoding.Property, InitCustomAttributeType(properties[k].PropertyType, scope));
}
this.m_members = new MemberInfo[fields.Length + properties.Length];
fields.CopyTo(this.m_members, 0);
properties.CopyTo(this.m_members, fields.Length);
CustomAttributeEncodedArgument.ParseAttributeArguments(caRecord.blob, ref this.m_ctorParams, ref this.m_namedParams, this.m_scope);
}
开发者ID:randomize,项目名称:VimConfig,代码行数:26,代码来源:CustomAttributeData.cs
示例3: 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
示例4: NewExpression
internal NewExpression (ConstructorInfo constructor, ReadOnlyCollection<Expression> arguments, ReadOnlyCollection<MemberInfo> members)
: base (ExpressionType.New, constructor.DeclaringType)
{
this.constructor = constructor;
this.arguments = arguments;
this.members = members;
}
开发者ID:superyfwy,项目名称:db4o,代码行数:7,代码来源:NewExpression.cs
示例5: 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
示例6: AliasToBeanResultTransformer
public AliasToBeanResultTransformer(System.Type resultClass)
{
if (resultClass == null)
{
throw new ArgumentNullException("resultClass");
}
this.resultClass = resultClass;
constructor = resultClass.GetConstructor(flags, null, System.Type.EmptyTypes, null);
// if resultClass is a ValueType (struct), GetConstructor will return null...
// in that case, we'll use Activator.CreateInstance instead of the ConstructorInfo to create instances
if (constructor == null && resultClass.IsClass)
{
throw new ArgumentException("The target class of a AliasToBeanResultTransformer need a parameter-less constructor",
"resultClass");
}
propertyAccessor =
new ChainedPropertyAccessor(new[]
{
PropertyAccessorFactory.GetPropertyAccessor(null),
PropertyAccessorFactory.GetPropertyAccessor("field")
});
}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:25,代码来源:AliasToBeanResultTransformer.cs
示例7: Check
public void Check(ConstructorInfo info, Dependency parent)
{
if (info.IsPrivate && !info.ReflectedType.IsAbstract)
{
parent.Add(new ProblemDependency(string.Format("This is a private constructor")));
}
}
开发者ID:royosherove,项目名称:dotnet-depender,代码行数:7,代码来源:FindPrivateConstructorsOnNonAbstractClassesRule.cs
示例8: ConstructorMap
public ConstructorMap(ConstructorInfo ctor, IEnumerable<ConstructorParameterMap> ctorParams)
{
Ctor = ctor;
CtorParams = ctorParams;
_runtimeCtor = DelegateFactory.CreateCtor(ctor, CtorParams);
}
开发者ID:sclcwwl,项目名称:Gimela,代码行数:7,代码来源:ConstructorMap.cs
示例9: 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
示例10: 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
示例11: GetCtorArgumentsAndBaseCtorToCall
protected override ArgumentReference[] GetCtorArgumentsAndBaseCtorToCall(Type targetFieldType, ProxyGenerationOptions proxyGenerationOptions,out ConstructorInfo baseConstructor)
{
if (proxyGenerationOptions.Selector == null)
{
baseConstructor = InvocationMethods.CompositionInvocationConstructorNoSelector;
return new[]
{
new ArgumentReference(targetFieldType),
new ArgumentReference(typeof(object)),
new ArgumentReference(typeof(IInterceptor[])),
new ArgumentReference(typeof(MethodInfo)),
new ArgumentReference(typeof(object[])),
};
}
baseConstructor = InvocationMethods.CompositionInvocationConstructorWithSelector;
return new[]
{
new ArgumentReference(targetFieldType),
new ArgumentReference(typeof(object)),
new ArgumentReference(typeof(IInterceptor[])),
new ArgumentReference(typeof(MethodInfo)),
new ArgumentReference(typeof(object[])),
new ArgumentReference(typeof(IInterceptorSelector)),
new ArgumentReference(typeof(IInterceptor[]).MakeByRefType())
};
}
开发者ID:JulianBirch,项目名称:Castle.Core,代码行数:27,代码来源:InterfaceInvocationTypeGenerator.cs
示例12: DemandMemberAccessIfNeeded
private static void DemandMemberAccessIfNeeded(ConstructorInfo constructor)
{
if (!constructor.IsVisible())
{
DemandMemberAccess(constructor);
}
}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:ReflectionInvoke.cs
示例13: InvokeBaseConstructor
internal void InvokeBaseConstructor(ConstructorInfo constructor, params ArgumentReference[] arguments)
{
AddStatement(
new ExpressionStatement(
new ConstructorInvocationExpression(constructor,
ArgumentsUtil.ConvertArgumentReferenceToExpression(arguments))));
}
开发者ID:superliujian,项目名称:Sxta,代码行数:7,代码来源:ConstructorCodeBuilder.cs
示例14: CustomAttributeBuilder
// public constructor to form the custom attribute with constructor and constructor
// parameters.
public CustomAttributeBuilder(ConstructorInfo con, Object[] constructorArgs,
PropertyInfo[] namedProperties, Object[] propertyValues,
FieldInfo[] namedFields, Object[] fieldValues)
{
InitCustomAttributeBuilder(con, constructorArgs, namedProperties,
propertyValues, namedFields, fieldValues);
}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:9,代码来源:customattributebuilder.cs
示例15: GenerateConstructor
/// <summary>
/// Generates one public constructor receiving
/// the <see cref="IInterceptor"/> instance and instantiating a hashtable
/// </summary>
protected virtual EasyConstructor GenerateConstructor( ConstructorInfo baseConstructor )
{
ArrayList arguments = new ArrayList();
ArgumentReference arg1 = new ArgumentReference( Context.Interceptor );
ArgumentReference arg2 = new ArgumentReference( typeof(object[]) );
arguments.Add( arg1 );
ParameterInfo[] parameters = baseConstructor.GetParameters();
if (Context.HasMixins)
{
arguments.Add( arg2 );
}
ArgumentReference[] originalArguments =
ArgumentsUtil.ConvertToArgumentReference(parameters);
arguments.AddRange(originalArguments);
EasyConstructor constructor = MainTypeBuilder.CreateConstructor(
(ArgumentReference[]) arguments.ToArray( typeof(ArgumentReference) ) );
GenerateConstructorCode(constructor.CodeBuilder, arg1, SelfReference.Self, arg2);
constructor.CodeBuilder.InvokeBaseConstructor( baseConstructor, originalArguments );
constructor.CodeBuilder.AddStatement( new ReturnStatement() );
return constructor;
}
开发者ID:atczyc,项目名称:castle,代码行数:36,代码来源:ClassProxyGenerator.cs
示例16: InitializeInvoker
private Func<object[], object> InitializeInvoker(ConstructorInfo constructorInfo)
{
// Target: (object)new T((T0)parameters[0], (T1)parameters[1], ...)
// parameters to execute
var parametersParameter = Expression.Parameter(typeof(object[]), "parameters");
// build parameter list
var parameterExpressions = new List<Expression>();
var paramInfos = constructorInfo.GetParameters();
for (int i = 0; i < paramInfos.Length; i++)
{
// (Ti)parameters[i]
var valueObj = Expression.ArrayIndex(parametersParameter, Expression.Constant(i));
var valueCast = Expression.Convert(valueObj, paramInfos[i].ParameterType);
parameterExpressions.Add(valueCast);
}
// new T((T0)parameters[0], (T1)parameters[1], ...)
var instanceCreate = Expression.New(constructorInfo, parameterExpressions);
// (object)new T((T0)parameters[0], (T1)parameters[1], ...)
var instanceCreateCast = Expression.Convert(instanceCreate, typeof(object));
var lambda = Expression.Lambda<Func<object[], object>>(instanceCreateCast, parametersParameter);
return lambda.Compile();
}
开发者ID:Dason1986,项目名称:Lib,代码行数:29,代码来源:ConstructorInvoker.cs
示例17: GetArguments
public IEnumerable<object> GetArguments(ConstructorInfo constructorInfo)
{
if (!_constructorArguments.ContainsKey(constructorInfo))
return null;
return _constructorArguments[constructorInfo];
}
开发者ID:PapaMufflon,项目名称:ConstructorTester,代码行数:7,代码来源:ArgumentsForConstructors.cs
示例18: ConstructorMap
public ConstructorMap(ConstructorInfo ctor, IEnumerable<ConstructorParameterMap> ctorParams)
{
Ctor = ctor;
CtorParams = ctorParams;
_runtimeCtor = new Lazy<LateBoundParamsCtor>(() => DelegateFactory.CreateCtor(ctor, CtorParams));
}
开发者ID:garora,项目名称:AutoMapper,代码行数:7,代码来源:ConstructorMap.cs
示例19: MapDestinationCtorToSource
private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeInfo sourceTypeInfo,
IMappingOptions options)
{
var parameters = new List<ConstructorParameterMap>();
var ctorParameters = destCtor.GetParameters();
if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
return false;
foreach (var parameter in ctorParameters)
{
var members = new LinkedList<MemberInfo>();
if (!MapDestinationPropertyToSource(members, sourceTypeInfo, parameter.Name, options))
return false;
var resolvers = members.Select(mi => mi.ToMemberGetter());
var param = new ConstructorParameterMap(parameter, resolvers.ToArray());
parameters.Add(param);
}
typeMap.AddConstructorMap(destCtor, parameters);
return true;
}
开发者ID:EdsonF,项目名称:AutoMapper,代码行数:27,代码来源:TypeMapFactory.cs
示例20: GetParameters
public object[] GetParameters(IBuilderContext context, Type type, string id, ConstructorInfo constructor)
{
ParameterInfo[] parms = constructor.GetParameters();
object[] parmsValueArray = new object[parms.Length];
for (int i = 0; i < parms.Length; ++i)
{
if (typeof(IEnumerable).IsAssignableFrom(parms[i].ParameterType))
{
Type genericList = typeof(List<>);
Type fullType = genericList.MakeGenericType(parms[i].ParameterType.GetGenericArguments()[0]);
parmsValueArray[i] = Activator.CreateInstance(fullType);
foreach (object o in Core.Objects.ObjectFactory.BuildAll(parms[i].ParameterType.GetGenericArguments()[0]))
{
((IList)parmsValueArray[i]).Add(o);
}
}
else
{
parmsValueArray[i] = Core.Objects.ObjectFactory.BuildUp(parms[i].ParameterType);
}
}
return parmsValueArray;
}
开发者ID:erwinbovendeur,项目名称:ADF,代码行数:25,代码来源:CreationPolicy.cs
注:本文中的System.Reflection.ConstructorInfo类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论