本文整理汇总了C#中IKVM.Reflection.Type.GetConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetConstructor方法的具体用法?C# Type.GetConstructor怎么用?C# Type.GetConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IKVM.Reflection.Type
的用法示例。
在下文中一共展示了Type.GetConstructor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteConstructors
private void WriteConstructors(TypeBuilder type, ref int index, SerializerPair[] methodPairs, ref ILGenerator il, int knownTypesCategory, FieldBuilder knownTypes, Type knownTypesLookupType, Compiler.CompilerContext ctx)
{
type.DefineDefaultConstructor(MethodAttributes.Public);
il = type.DefineTypeInitializer().GetILGenerator();
switch (knownTypesCategory)
{
case KnownTypes_Array:
{
Compiler.CompilerContext.LoadValue(il, types.Count);
il.Emit(OpCodes.Newarr, ctx.MapType(typeof(System.Type)));
index = 0;
foreach (SerializerPair pair in methodPairs)
{
il.Emit(OpCodes.Dup);
Compiler.CompilerContext.LoadValue(il, index);
il.Emit(OpCodes.Ldtoken, pair.Type.Type);
il.EmitCall(OpCodes.Call, ctx.MapType(typeof(System.Type)).GetMethod("GetTypeFromHandle"), null);
il.Emit(OpCodes.Stelem_Ref);
index++;
}
il.Emit(OpCodes.Stsfld, knownTypes);
il.Emit(OpCodes.Ret);
}
break;
case KnownTypes_Dictionary:
{
Compiler.CompilerContext.LoadValue(il, types.Count);
//LocalBuilder loc = il.DeclareLocal(knownTypesLookupType);
il.Emit(OpCodes.Newobj, knownTypesLookupType.GetConstructor(new Type[] { MapType(typeof(int)) }));
il.Emit(OpCodes.Stsfld, knownTypes);
int typeIndex = 0;
foreach (SerializerPair pair in methodPairs)
{
il.Emit(OpCodes.Ldsfld, knownTypes);
il.Emit(OpCodes.Ldtoken, pair.Type.Type);
il.EmitCall(OpCodes.Call, ctx.MapType(typeof(System.Type)).GetMethod("GetTypeFromHandle"), null);
int keyIndex = typeIndex++, lastKey = pair.BaseKey;
if (lastKey != pair.MetaKey) // not a base-type; need to give the index of the base-type
{
keyIndex = -1; // assume epic fail
for (int j = 0; j < methodPairs.Length; j++)
{
if (methodPairs[j].BaseKey == lastKey && methodPairs[j].MetaKey == lastKey)
{
keyIndex = j;
break;
}
}
}
Compiler.CompilerContext.LoadValue(il, keyIndex);
il.EmitCall(OpCodes.Callvirt, knownTypesLookupType.GetMethod("Add", new Type[] { MapType(typeof(System.Type)), MapType(typeof(int)) }), null);
}
il.Emit(OpCodes.Ret);
}
break;
case KnownTypes_Hashtable:
{
Compiler.CompilerContext.LoadValue(il, types.Count);
il.Emit(OpCodes.Newobj, knownTypesLookupType.GetConstructor(new Type[] { MapType(typeof(int)) }));
il.Emit(OpCodes.Stsfld, knownTypes);
int typeIndex = 0;
foreach (SerializerPair pair in methodPairs)
{
il.Emit(OpCodes.Ldsfld, knownTypes);
il.Emit(OpCodes.Ldtoken, pair.Type.Type);
il.EmitCall(OpCodes.Call, ctx.MapType(typeof(System.Type)).GetMethod("GetTypeFromHandle"), null);
int keyIndex = typeIndex++, lastKey = pair.BaseKey;
if (lastKey != pair.MetaKey) // not a base-type; need to give the index of the base-type
{
keyIndex = -1; // assume epic fail
for (int j = 0; j < methodPairs.Length; j++)
{
if (methodPairs[j].BaseKey == lastKey && methodPairs[j].MetaKey == lastKey)
{
keyIndex = j;
break;
}
}
}
Compiler.CompilerContext.LoadValue(il, keyIndex);
il.Emit(OpCodes.Box, MapType(typeof(int)));
il.EmitCall(OpCodes.Callvirt, knownTypesLookupType.GetMethod("Add", new Type[] { MapType(typeof(object)), MapType(typeof(object)) }), null);
}
il.Emit(OpCodes.Ret);
}
break;
default:
throw new InvalidOperationException();
}
}
示例2: SetMain
internal void SetMain(MethodInfo m, PEFileKinds target, Dictionary<string, string> props, bool noglobbing, Type apartmentAttributeType)
{
MethodBuilder mainStub = this.GetTypeWrapperFactory().ModuleBuilder.DefineGlobalMethod("main", MethodAttributes.Public | MethodAttributes.Static, Types.Int32, new Type[] { Types.String.MakeArrayType() });
if(apartmentAttributeType != null)
{
mainStub.SetCustomAttribute(new CustomAttributeBuilder(apartmentAttributeType.GetConstructor(Type.EmptyTypes), new object[0]));
}
CodeEmitter ilgen = CodeEmitter.Create(mainStub);
CodeEmitterLocal rc = ilgen.DeclareLocal(Types.Int32);
TypeWrapper startupType = LoadClassByDottedName("ikvm.runtime.Startup");
if(props.Count > 0)
{
ilgen.Emit(OpCodes.Newobj, JVM.Import(typeof(System.Collections.Generic.Dictionary<string, string>)).GetConstructor(Type.EmptyTypes));
foreach(KeyValuePair<string, string> kv in props)
{
ilgen.Emit(OpCodes.Dup);
ilgen.Emit(OpCodes.Ldstr, kv.Key);
ilgen.Emit(OpCodes.Ldstr, kv.Value);
if(kv.Value.IndexOf('%') < kv.Value.LastIndexOf('%'))
{
ilgen.Emit(OpCodes.Call, JVM.Import(typeof(Environment)).GetMethod("ExpandEnvironmentVariables", new Type[] { Types.String }));
}
ilgen.Emit(OpCodes.Callvirt, JVM.Import(typeof(System.Collections.Generic.Dictionary<string, string>)).GetMethod("Add"));
}
startupType.GetMethodWrapper("setProperties", "(Lcli.System.Collections.IDictionary;)V", false).EmitCall(ilgen);
}
ilgen.BeginExceptionBlock();
startupType.GetMethodWrapper("enterMainThread", "()V", false).EmitCall(ilgen);
ilgen.Emit(OpCodes.Ldarg_0);
if (!noglobbing)
{
ilgen.Emit(OpCodes.Ldc_I4_0);
startupType.GetMethodWrapper("glob", "([Ljava.lang.String;I)[Ljava.lang.String;", false).EmitCall(ilgen);
}
ilgen.Emit(OpCodes.Call, m);
CodeEmitterLabel label = ilgen.DefineLabel();
ilgen.Emit(OpCodes.Leave, label);
ilgen.BeginCatchBlock(Types.Exception);
LoadClassByDottedName("ikvm.runtime.Util").GetMethodWrapper("mapException", "(Ljava.lang.Throwable;)Ljava.lang.Throwable;", false).EmitCall(ilgen);
CodeEmitterLocal exceptionLocal = ilgen.DeclareLocal(Types.Exception);
ilgen.Emit(OpCodes.Stloc, exceptionLocal);
TypeWrapper threadTypeWrapper = ClassLoaderWrapper.LoadClassCritical("java.lang.Thread");
CodeEmitterLocal threadLocal = ilgen.DeclareLocal(threadTypeWrapper.TypeAsLocalOrStackType);
threadTypeWrapper.GetMethodWrapper("currentThread", "()Ljava.lang.Thread;", false).EmitCall(ilgen);
ilgen.Emit(OpCodes.Stloc, threadLocal);
ilgen.Emit(OpCodes.Ldloc, threadLocal);
threadTypeWrapper.GetMethodWrapper("getThreadGroup", "()Ljava.lang.ThreadGroup;", false).EmitCallvirt(ilgen);
ilgen.Emit(OpCodes.Ldloc, threadLocal);
ilgen.Emit(OpCodes.Ldloc, exceptionLocal);
ClassLoaderWrapper.LoadClassCritical("java.lang.ThreadGroup").GetMethodWrapper("uncaughtException", "(Ljava.lang.Thread;Ljava.lang.Throwable;)V", false).EmitCallvirt(ilgen);
ilgen.Emit(OpCodes.Ldc_I4_1);
ilgen.Emit(OpCodes.Stloc, rc);
ilgen.Emit(OpCodes.Leave, label);
ilgen.BeginFinallyBlock();
startupType.GetMethodWrapper("exitMainThread", "()V", false).EmitCall(ilgen);
ilgen.Emit(OpCodes.Endfinally);
ilgen.EndExceptionBlock();
ilgen.MarkLabel(label);
ilgen.Emit(OpCodes.Ldloc, rc);
ilgen.Emit(OpCodes.Ret);
ilgen.DoEmit();
assemblyBuilder.SetEntryPoint(mainStub, target);
}
示例3: ThrowException
internal void ThrowException(Type excType)
{
Emit(OpCodes.Newobj, excType.GetConstructor(Type.EmptyTypes));
Emit(OpCodes.Throw);
}
示例4: Emit
public override void Emit(CodeGen g, Type from, Type to)
{
_fromConv?.Emit(g, from, Helpers.GetNullableUnderlyingType(to));
g.IL.Emit(
OpCodes.Newobj,
to.GetConstructor(new[] { from }));
}
示例5: InitializeJavaClassLoader
private void InitializeJavaClassLoader(JavaClassLoaderConstructionInProgress jclcip, Type customClassLoaderClass)
{
Assembly assembly = assemblyLoader.Assembly;
{
if (customClassLoaderClass != null)
{
try
{
if (!customClassLoaderClass.IsPublic && !customClassLoaderClass.Assembly.Equals(assembly))
{
throw new Exception("Type not accessible");
}
ConstructorInfo customClassLoaderCtor = customClassLoaderClass.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(Assembly) }, null);
if (customClassLoaderCtor == null)
{
throw new Exception("No constructor");
}
if (!customClassLoaderCtor.IsPublic && !customClassLoaderClass.Assembly.Equals(assembly))
{
customClassLoaderCtor = null;
throw new Exception("Constructor not accessible");
}
// NOTE we're creating an uninitialized instance of the custom class loader here, so that getClassLoader will return the proper object
// when it is called during the construction of the custom class loader later on. This still doesn't make it safe to use the custom
// class loader before it is constructed, but at least the object instance is available and should anyone cache it, they will get the
// right object to use later on.
// Note that creating the unitialized instance will (unfortunately) trigger the static initializer. The static initializer can
// trigger a call to getClassLoader(), which means we can end up here recursively.
java.lang.ClassLoader newJavaClassLoader = (java.lang.ClassLoader)GetUninitializedObject(customClassLoaderClass);
if (jclcip.javaClassLoader == null) // check if we weren't invoked recursively and the nested invocation already did the work
{
jclcip.javaClassLoader = newJavaClassLoader;
SetWrapperForClassLoader(jclcip.javaClassLoader, this);
DoPrivileged(new CustomClassLoaderCtorCaller(customClassLoaderCtor, jclcip.javaClassLoader, assembly));
Tracer.Info(Tracer.Runtime, "Created custom assembly class loader {0} for assembly {1}", customClassLoaderClass.FullName, assembly);
}
else
{
// we didn't initialize the object, so there is no need to finalize it
GC.SuppressFinalize(newJavaClassLoader);
}
}
catch (Exception x)
{
Tracer.Error(Tracer.Runtime, "Unable to create custom assembly class loader {0} for {1}: {2}", customClassLoaderClass.FullName, assembly, x);
}
}
}
if (jclcip.javaClassLoader == null)
{
jclcip.javaClassLoader = new ikvm.runtime.AssemblyClassLoader();
SetWrapperForClassLoader(jclcip.javaClassLoader, this);
}
// finally we publish the class loader for other threads to see
Thread.MemoryBarrier();
javaClassLoader = jclcip.javaClassLoader;
}
示例6: GetConstructor
internal static ConstructorInfo GetConstructor(Type type, Type[] parameterTypes, bool nonPublic)
{
#if PORTABLE
// pretty sure this will only ever return public, but...
ConstructorInfo ctor = type.GetConstructor(parameterTypes);
return (ctor != null && (nonPublic || ctor.IsPublic)) ? ctor : null;
#else
return type.GetConstructor(
nonPublic ? BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
: BindingFlags.Instance | BindingFlags.Public,
null, parameterTypes, null);
#endif
}