本文整理汇总了C#中CodeGen.EmitArgGet方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGen.EmitArgGet方法的具体用法?C# CodeGen.EmitArgGet怎么用?C# CodeGen.EmitArgGet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGen
的用法示例。
在下文中一共展示了CodeGen.EmitArgGet方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OverrideConstructor
private ConstructorBuilder OverrideConstructor(ConstructorInfo parentConstructor)
{
ParameterInfo[] pis = parentConstructor.GetParameters();
ParameterInfo[] overrideParams = GetOverrideCtorSignature(pis);
Type[] argTypes = new Type[overrideParams.Length];
string[] paramNames = new string[overrideParams.Length];
for (int i = 0; i < overrideParams.Length; i++) {
argTypes[i] = overrideParams[i].ParameterType;
paramNames[i] = overrideParams[i].Name;
}
ConstructorBuilder cb = tg.myType.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, argTypes);
for (int i = 0; i < overrideParams.Length; i++) {
ParameterBuilder pb = cb.DefineParameter(i + 1,
overrideParams[i].Attributes,
overrideParams[i].Name);
int origIndex = i - (overrideParams.Length - pis.Length);
if (origIndex >= 0) {
if (pis[origIndex].IsDefined(typeof(ParamArrayAttribute), false)) {
pb.SetCustomAttribute(new CustomAttributeBuilder(
typeof(ParamArrayAttribute).GetConstructor(Type.EmptyTypes), Ops.EMPTY));
} else if (pis[origIndex].IsDefined(typeof(ParamDictAttribute), false)) {
pb.SetCustomAttribute(new CustomAttributeBuilder(
typeof(ParamDictAttribute).GetConstructor(Type.EmptyTypes), Ops.EMPTY));
}
}
}
CodeGen cg = new CodeGen(tg, cb, cb.GetILGenerator(), argTypes);
// <typeField> = <arg0>
cg.EmitArgGet(0);
typeField.EmitSet(cg);
// initialize all slots to Uninitialized.instance
if (slots != null) {
for (int i = 0; i < slots.Count; i++) {
if (slots[i] != "__weakref__" && slots[i] != "__dict__") {
cg.EmitUninitialized();
} else {
cg.Emit(OpCodes.Ldnull);
}
slotsSlots[i].EmitSet(cg);
}
}
CallBaseConstructor(parentConstructor, overrideParams.Length - pis.Length, overrideParams, cg);
return cb;
}
示例2: CallBaseConstructor
private static void CallBaseConstructor(ConstructorInfo parentConstructor, int offset, ParameterInfo[] pis, CodeGen cg)
{
cg.EmitThis();
for (int i = offset; i < pis.Length; i++) {
cg.EmitArgGet(i);
}
cg.Emit(OpCodes.Call, parentConstructor);
cg.Emit(OpCodes.Ret);
}
示例3: EmitArgsToTuple
private static void EmitArgsToTuple(FunctionDefinition fd, CodeGen icg, SignatureInfo sigInfo, int cnt)
{
if ((fd.Flags & FunctionAttributes.ArgumentList) != 0) {
// transform params object[] into tuple on call...
LocalBuilder lb = icg.DeclareLocal(typeof(object));
Slot argsSlot = new LocalSlot(lb, icg);
int index;
if ((fd.Flags & FunctionAttributes.KeywordDictionary) != 0) {
index = sigInfo.ParamNames.Length - 2;
icg.EmitArgGet(cnt - 2);
} else {
index = sigInfo.ParamNames.Length - 1;
icg.EmitArgGet(cnt - 1);
}
icg.EmitCall(typeof(Tuple), "MakeTuple");
argsSlot.EmitSet(icg);
lb.SetLocalSymInfo(sigInfo.ParamNames[index].GetString());
icg.Names.SetSlot(sigInfo.ParamNames[index], argsSlot);
}
}