本文整理汇总了C#中ConstructorInfo类的典型用法代码示例。如果您正苦于以下问题:C# ConstructorInfo类的具体用法?C# ConstructorInfo怎么用?C# ConstructorInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstructorInfo类属于命名空间,在下文中一共展示了ConstructorInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AssemblyLoaderImporter
public AssemblyLoaderImporter(ModuleReader moduleReader, AssemblyResolver assemblyResolver, EmbedTask embedTask)
{
instructionConstructorInfo = typeof (Instruction).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] {typeof (OpCode), typeof (object)}, null);
this.moduleReader = moduleReader;
this.assemblyResolver = assemblyResolver;
this.embedTask = embedTask;
}
开发者ID:sachhi,项目名称:costura,代码行数:7,代码来源:AssemblyLoaderImporter.cs
示例2: Test_Load
private void Test_Load(object sender, EventArgs e)
{
_attType = typeof(AsyncStateMachineAttribute);
_assemblies = AppDomain.CurrentDomain.GetAssemblies();
_ignoreList = new[] { "Equals", "GetHashCode", "GetType", "ToString" };
_cboCategories = new Dictionary<int, string> { { 1, "EF" }, { 2, "RPC" }, { 3, "BAL" } };
cboCategories.DataSource = new BindingSource(_cboCategories, null);
cboCategories.DisplayMember = "Value";
cboCategories.ValueMember = "Key";
//cboCategories.SelectedIndex = 0;
_state = new State();
var uow = new TekTak.iLoop.UOW.UnitOfWork();
_constorInfo = new ConstructorInfo
{
ConstorParamType = new[] { uow.GetServices().GetType() },
ConstorParams = new object[] { uow.GetServices() }
};
LoadState();
_samples = API.SampleConfig.GetSamples();
cboClasses.SelectedIndex = cboClasses.Items.Count >= _state.Combo ? _state.Combo : 0;
if (treeMethods.Nodes.Count > 0) treeMethods.SelectedNode = treeMethods.Nodes.Count > _state.Node ? treeMethods.Nodes[_state.Node] : treeMethods.Nodes[0];
treeMethods.Focus();
}
开发者ID:tektak-abhisheksth,项目名称:Web-API,代码行数:26,代码来源:Test.cs
示例3: ItGoodConstructor
public static bool ItGoodConstructor(ConstructorInfo C)
{
ParameterInfo[] ps = C.GetParameters();
var cs = from p in ps
let prms = p.ParameterType.GetConstructor
(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null)
let pms = p.ParameterType.IsValueType
where ((prms != null) || pms)
select p;
return (cs.Count() == ps.Length);
}
开发者ID:Martmath,项目名称:ExtReflection_Convert,代码行数:11,代码来源:CLS_NewInstance.cs
示例4: TupleSerializer
public TupleSerializer(RuntimeTypeModel model, ConstructorInfo ctor, MemberInfo[] members)
{
if (ctor == null) throw new ArgumentNullException("ctor");
if (members == null) throw new ArgumentNullException("members");
this.ctor = ctor;
this.members = members;
this.tails = new IProtoSerializer[members.Length];
ParameterInfo[] parameters = ctor.GetParameters();
for (int i = 0; i < members.Length; i++)
{
WireType wireType;
Type finalType = parameters[i].ParameterType;
Type itemType = null, defaultType = null;
MetaType.ResolveListTypes(model, finalType, ref itemType, ref defaultType);
Type tmp = itemType == null ? finalType : itemType;
bool asReference = false;
int typeIndex = model.FindOrAddAuto(tmp, false, true, false);
if (typeIndex >= 0)
{
asReference = model[tmp].AsReferenceDefault;
}
IProtoSerializer tail = ValueMember.TryGetCoreSerializer(model, DataFormat.Default, tmp, out wireType,
asReference, false, false, true),
serializer;
if (tail == null)
{
throw new InvalidOperationException("No serializer defined for type: " + tmp.FullName);
}
tail = new TagDecorator(i + 1, wireType, false, tail);
if (itemType == null)
{
serializer = tail;
}
else
{
if (finalType.IsArray)
{
serializer = new ArrayDecorator(model, tail, i + 1, false, wireType, finalType, false, false);
}
else
{
serializer = ListDecorator.Create(model, finalType, defaultType, tail, i + 1, false, wireType,
true, false, false);
}
}
tails[i] = serializer;
}
}
开发者ID:he0x,项目名称:xRAT,代码行数:53,代码来源:TupleSerializer.cs
示例5: BuildConstructors
public static StringBuilder BuildConstructors(Type type, ConstructorInfo[] constructors, int slot, int howmanyConstructors)
{
string fmt = @"
_jstype.definition.{0} = function({1}) [[ CS.Call({2}); ]]";
StringBuilder sb = new StringBuilder();
var argActual = new cg.args();
var argFormal = new cg.args();
for (int i = 0; i < constructors.Length; i++)
{
ConstructorInfo con = constructors[i];
ParameterInfo[] ps = con == null? new ParameterInfo[0] : con.GetParameters();
argActual.Clear().Add(
(int)JSVCall.Oper.CONSTRUCTOR, // OP
slot,
i, // NOTICE
"true", // IsStatics
"this"
);
argFormal.Clear();
// add T to formal param
if (type.IsGenericTypeDefinition)
{
// TODO check
int TCount = type.GetGenericArguments().Length;
for (int j = 0; j < TCount; j++)
{
argFormal.Add("t" + j + "");
argActual.Add("t" + j + ".getNativeType()");
}
}
//StringBuilder sbFormalParam = new StringBuilder();
//StringBuilder sbActualParam = new StringBuilder();
for (int j = 0; j < ps.Length; j++)
{
argFormal.Add("a" + j.ToString());
argActual.Add("a" + j.ToString());
}
sb.AppendFormat(fmt,
SharpKitMethodName("ctor", ps, howmanyConstructors > 1), // [0]
argFormal, // [1]
argActual); // [2]
}
return sb;
}
开发者ID:shuidong,项目名称:qjsbunitynew,代码行数:50,代码来源:JSGenerator.cs
示例6: ObjectFromConstructor
public static object ObjectFromConstructor(ConstructorInfo C)
{
ParameterInfo[] ps = C.GetParameters();
List<object> o = new List<object>();
for (int i = 0; i < ps.Length; i++)
{
// if (ps[i].DefaultValue != null) o.Add(ps[i].DefaultValue); else
if (ps[i].ParameterType.IsValueType) o.Add(Activator.CreateInstance(ps[i].ParameterType));
else
o.Add(ps[i].ParameterType.GetConstructor
(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null).Invoke(null));
}
return C.Invoke(o.ToArray());
}
开发者ID:Martmath,项目名称:ExtReflection_Convert,代码行数:14,代码来源:CLS_NewInstance.cs
示例7: AddAutomagicSerializationToWorkaroundBaseClass
internal static ConstructorInfo AddAutomagicSerializationToWorkaroundBaseClass(TypeBuilder typeBuilderWorkaroundBaseClass, ConstructorInfo baseCtor)
{
if (typeBuilderWorkaroundBaseClass.BaseType.IsSerializable)
{
typeBuilderWorkaroundBaseClass.SetCustomAttribute(serializableAttribute);
if (baseCtor != null && (baseCtor.IsFamily || baseCtor.IsFamilyOrAssembly))
{
return AddConstructor(typeBuilderWorkaroundBaseClass, null, baseCtor, false);
}
}
return null;
}
开发者ID:ikvm,项目名称:IKVM.NET-cvs-clone,代码行数:12,代码来源:Serialization.cs
示例8: BuildConstructors
public static StringBuilder BuildConstructors(Type type, ConstructorInfo[] constructors, int[] constructorsIndex, ClassCallbackNames ccbn)
{
/*
* methods
* 0 function name
* 1 list<CSParam> generation
* 2 function call
*/
string fmt = @"
static bool {0}(JSVCall vc, int argc)
[[
{1}
return true;
]]
";
StringBuilder sb = new StringBuilder();
/*if (constructors.Length == 0 && JSBindingSettings.IsGeneratedDefaultConstructor(type) &&
(type.IsValueType || (type.IsClass && !type.IsAbstract && !type.IsInterface)))
{
int olIndex = 1;
bool returnVoid = false;
string functionName = type.Name + "_" + type.Name +
(olIndex > 0 ? olIndex.ToString() : "") + "";// (cons.IsStatic ? "_S" : "");
sb.AppendFormat(fmt, functionName,
BuildNormalFunctionCall(0, new ParameterInfo[0], type.Name, type.Name, false, returnVoid, null, true));
ccbn.constructors.Add(functionName);
ccbn.constructorsCSParam.Add(GenListCSParam2(new ParameterInfo[0]).ToString());
}*/
// increase index if adding default constructor
// int deltaIndex = 0;
if (JSBindingSettings.NeedGenDefaultConstructor(type))
{
// deltaIndex = 1;
}
for (int i = 0; i < constructors.Length; i++)
{
ConstructorInfo cons = constructors[i];
if (cons == null)
{
sb.AppendFormat("public static ConstructorID constructorID{0} = new ConstructorID({1});\n", i, "null, null");
// this is default constructor
//bool returnVoid = false;
//string functionName = type.Name + "_" + type.Name + "1";
int olIndex = i + 1; // for constuctors, they are always overloaded
string functionName = JSNameMgr.HandleFunctionName(type.Name + "_" + type.Name + (olIndex > 0 ? olIndex.ToString() : ""));
sb.AppendFormat(fmt, functionName,
BuildNormalFunctionCall(0, new ParameterInfo[0], type.Name, false, null, true));
ccbn.constructors.Add(functionName);
ccbn.constructorsCSParam.Add(GenListCSParam2(new ParameterInfo[0]).ToString());
}
else
{
ParameterInfo[] paramS = cons.GetParameters();
int olIndex = i + 1; // for constuctors, they are always overloaded
int methodTag = i/* + deltaIndex*/;
for (int j = 0; j < paramS.Length; j++)
{
if (JSDataExchangeEditor.IsDelegateDerived(paramS[j].ParameterType))
{
StringBuilder sbD = JSDataExchangeEditor.Build_DelegateFunction(type, cons, paramS[j].ParameterType, methodTag, j);
sb.Append(sbD);
}
}
// ConstructorID
if (type.IsGenericTypeDefinition)
{
cg.args arg = new cg.args();
cg.args arg1 = new cg.args();
cg.args arg2 = new cg.args();
foreach (ParameterInfo p in cons.GetParameters())
{
cg.args argFlag = ParameterInfo2TypeFlag(p);
arg1.AddFormat("\"{0}\"", p.ParameterType.Name);
arg2.Add(argFlag.Format(cg.args.ArgsFormat.Flag));
}
if (arg1.Count > 0)
arg.AddFormat("new string[]{0}", arg1.Format(cg.args.ArgsFormat.Brace));
else
arg.Add("null");
if (arg2.Count > 0)
arg.AddFormat("new TypeFlag[]{0}", arg2.Format(cg.args.ArgsFormat.Brace));
else
arg.Add("null");
sb.AppendFormat("public static ConstructorID constructorID{0} = new ConstructorID({1});\n", i, arg.ToString());
}
string functionName = JSNameMgr.HandleFunctionName(type.Name + "_" + type.Name + (olIndex > 0 ? olIndex.ToString() : "") + (cons.IsStatic ? "_S" : ""));
sb.AppendFormat(fmt, functionName,
//.........这里部分代码省略.........
开发者ID:shuidong,项目名称:qjsbunitynew,代码行数:101,代码来源:CSGenerator.cs
示例9: SmartConstructorMethodWrapper
internal SmartConstructorMethodWrapper(TypeWrapper declaringType, string name, string sig, ConstructorInfo method, TypeWrapper[] parameterTypes, Modifiers modifiers, MemberFlags flags)
: base(declaringType, name, sig, method, PrimitiveTypeWrapper.VOID, parameterTypes, modifiers, flags)
{
}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:4,代码来源:MemberWrapper.cs
示例10: GetAllConstructors
static ConstructorInfo [] GetAllConstructors (Type t)
{
BindingFlags static_flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly |BindingFlags.Static;
BindingFlags instance_flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly |BindingFlags.Instance;
ConstructorInfo [] static_members = t.GetConstructors (static_flag);
ConstructorInfo [] instance_members = t.GetConstructors (instance_flag);
if (static_members == null && instance_members == null)
return null;
ConstructorInfo [] all_members = new ConstructorInfo [static_members.Length + instance_members.Length];
static_members.CopyTo (all_members, 0); // copy all static members
instance_members.CopyTo (all_members, static_members.Length); // copy all instance members
return all_members;
}
开发者ID:emtees,项目名称:old-code,代码行数:17,代码来源:updater.cs
示例11: GetConstructor
public static ConstructorInfo GetConstructor(Type type, ConstructorInfo constructor)
{
return new ConstructorInfoImpl(GetMethod(type, constructor.GetMethodInfo()));
}
开发者ID:,项目名称:,代码行数:4,代码来源:
示例12: CustomClassLoaderCtorCaller
internal CustomClassLoaderCtorCaller(ConstructorInfo ctor, object classLoader, Assembly assembly)
{
this.ctor = ctor;
this.classLoader = classLoader;
this.assembly = assembly;
}
开发者ID:LogosBible,项目名称:ikvm-fork,代码行数:6,代码来源:AssemblyClassLoader.cs
示例13: Initialize
void Initialize(Type targetType, string methodName)
{
if (!_delegateType.IsSubclassOf(_typeMapper.MapType(typeof(Delegate))))
throw new ArgumentException(Properties.Messages.ErrInvalidDelegateType, "delegateType");
IMemberInfo delegateInvocationMethod = null;
foreach (IMemberInfo mi in _typeMapper.TypeInfo.GetMethods(_delegateType))
{
if (mi.Name == "Invoke")
{
if (delegateInvocationMethod != null)
throw new ArgumentException(Properties.Messages.ErrInvalidDelegateType, "delegateType");
delegateInvocationMethod = mi;
}
}
if (delegateInvocationMethod == null)
throw new ArgumentException(Properties.Messages.ErrInvalidDelegateType, "delegateType");
foreach (IMemberInfo mi in _typeMapper.TypeInfo.GetConstructors(_delegateType))
{
if (mi.IsStatic)
continue;
Type[] ctorParamTypes = mi.ParameterTypes;
if (ctorParamTypes.Length == 2 && ctorParamTypes[0] == _typeMapper.MapType(typeof(object)) && ctorParamTypes[1] == _typeMapper.MapType(typeof(IntPtr)))
{
if (_delegateConstructor != null)
throw new ArgumentException(Properties.Messages.ErrInvalidDelegateType, "delegateType");
_delegateConstructor = (ConstructorInfo)mi.Member;
}
}
if (_delegateConstructor == null)
throw new ArgumentException(Properties.Messages.ErrInvalidDelegateType, "delegateType");
Type retType = delegateInvocationMethod.ReturnType;
Type[] parameterTypes = delegateInvocationMethod.ParameterTypes;
for ( ; targetType != null; targetType = targetType.BaseType)
{
foreach (IMemberInfo mi in _typeMapper.TypeInfo.Filter(_typeMapper.TypeInfo.GetMethods(targetType), methodName, false, (object)_target == null, false))
{
if (mi.ReturnType == retType && ArrayUtils.Equals(mi.ParameterTypes, parameterTypes))
{
if (_method == null)
_method = (MethodInfo)mi.Member;
else
throw new AmbiguousMatchException(Properties.Messages.ErrAmbiguousBinding);
}
}
if (_method != null)
break;
}
if (_method == null)
throw new MissingMethodException(Properties.Messages.ErrMissingMethod);
}
开发者ID:AqlaSolutions,项目名称:runsharp,代码行数:63,代码来源:NewDelegate.cs
示例14: HasMissingType
static bool HasMissingType (ConstructorInfo ctor)
{
#if STATIC
//
// Mimic odd csc behaviour where missing type on predefined
// attributes means the attribute is silently ignored. This can
// happen with PCL facades
//
foreach (var p in ctor.GetParameters ()) {
if (p.ParameterType.__ContainsMissingType)
return true;
}
#endif
return false;
}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:16,代码来源:import.cs
示例15: GetConstructors
internal static void GetConstructors(Type type, out ConstructorInfo defCtor, out ConstructorInfo singleOneArgCtor)
{
defCtor = null;
int oneArgCtorCount = 0;
ConstructorInfo oneArgCtor = null;
ConstructorInfo[] constructors = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
// HACK we have a special rule to make some additional custom attributes from mscorlib usable:
// Attributes that have two constructors, one an enum and another one taking a byte, short or int,
// we only expose the enum constructor.
if (constructors.Length == 2 && type.Assembly == Types.Object.Assembly)
{
ParameterInfo[] p0 = constructors[0].GetParameters();
ParameterInfo[] p1 = constructors[1].GetParameters();
if (p0.Length == 1 && p1.Length == 1)
{
Type t0 = p0[0].ParameterType;
Type t1 = p1[0].ParameterType;
bool swapped = false;
if (t1.IsEnum)
{
Type tmp = t0;
t0 = t1;
t1 = tmp;
swapped = true;
}
if (t0.IsEnum && (t1 == Types.Byte || t1 == Types.Int16 || t1 == Types.Int32))
{
if (swapped)
{
singleOneArgCtor = constructors[1];
}
else
{
singleOneArgCtor = constructors[0];
}
return;
}
}
}
if (type.Assembly == Types.Object.Assembly)
{
if (type.FullName == "System.Runtime.CompilerServices.MethodImplAttribute")
{
foreach (ConstructorInfo ci in constructors)
{
ParameterInfo[] p = ci.GetParameters();
if (p.Length == 1 && p[0].ParameterType.IsEnum)
{
singleOneArgCtor = ci;
return;
}
}
}
}
foreach (ConstructorInfo ci in constructors)
{
ParameterInfo[] args = ci.GetParameters();
if (args.Length == 0)
{
defCtor = ci;
}
else if (args.Length == 1)
{
if (IsSupportedType(args[0].ParameterType))
{
oneArgCtor = ci;
oneArgCtorCount++;
}
else
{
// set to two to make sure we don't see the oneArgCtor as viable
oneArgCtorCount = 2;
}
}
}
singleOneArgCtor = oneArgCtorCount == 1 ? oneArgCtor : null;
}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:77,代码来源:DotNetTypeWrapper.cs
示例16: EmitCtor
public void EmitCtor(ConstructorInfo ctor)
{
if (ctor == null) throw new ArgumentNullException("ctor");
CheckAccessibility(ctor);
il.Emit(OpCodes.Newobj, ctor);
#if DEBUG_COMPILE
Helpers.DebugWriteLine(OpCodes.Newobj + ": " + ctor.DeclaringType);
#endif
}
开发者ID:banksyhf,项目名称:Auxilium-2,代码行数:9,代码来源:CompilerContext.cs
示例17: AddConstructor
private static ConstructorInfo AddConstructor(TypeBuilder tb, MethodWrapper defaultConstructor, ConstructorInfo serializationConstructor, bool callReadObject)
{
ConstructorBuilder ctor = tb.DefineConstructor(MethodAttributes.Family, CallingConventions.Standard, new Type[] { JVM.Import(typeof(SerializationInfo)), JVM.Import(typeof(StreamingContext)) });
AttributeHelper.HideFromJava(ctor);
ctor.AddDeclarativeSecurity(SecurityAction.Demand, psetSerializationFormatter);
CodeEmitter ilgen = CodeEmitter.Create(ctor);
ilgen.Emit(OpCodes.Ldarg_0);
if (defaultConstructor != null)
{
defaultConstructor.EmitCall(ilgen);
}
else
{
ilgen.Emit(OpCodes.Ldarg_1);
ilgen.Emit(OpCodes.Ldarg_2);
ilgen.Emit(OpCodes.Call, serializationConstructor);
}
if (callReadObject)
{
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Ldarg_1);
TypeWrapper serializationHelper = ClassLoaderWrapper.LoadClassCritical("ikvm.internal.Serialization");
MethodWrapper mw = serializationHelper.GetMethodWrapper("readObject", "(Ljava.lang.Object;Lcli.System.Runtime.Serialization.SerializationInfo;)V", false);
mw.Link();
mw.EmitCall(ilgen);
}
ilgen.Emit(OpCodes.Ret);
return ctor;
}
开发者ID:ikvm,项目名称:IKVM.NET-cvs-clone,代码行数:29,代码来源:Serialization.cs
示例18: SetCustomAttribute
public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
{
methodBuilder.SetCustomAttribute(con, binaryAttribute);
}
开发者ID:,项目名称:,代码行数:4,代码来源:
示例19: Emit
internal void Emit(OpCode opcode, ConstructorInfo con)
{
EmitOpCode(opcode, con);
}
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:4,代码来源:CodeEmitter.cs
示例20: Equals
public void Equals(ConstructorInfo constructorInfo1, ConstructorInfo constructorInfo2, bool expected)
{
Assert.Equal(expected, constructorInfo1.Equals(constructorInfo2));
}
开发者ID:dotnet,项目名称:corefx,代码行数:4,代码来源:ConstructorInfoTests.cs
注:本文中的ConstructorInfo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论