internal void GenerateRegexType(String pattern, RegexOptions opts, String name, bool ispublic, RegexCode code, RegexTree tree, Type factory) {
FieldInfo patternF = RegexField("pattern");
FieldInfo optionsF = RegexField("roptions");
FieldInfo factoryF = RegexField("factory");
FieldInfo capsF = RegexField("caps");
FieldInfo capnamesF = RegexField("capnames");
FieldInfo capslistF = RegexField("capslist");
FieldInfo capsizeF = RegexField("capsize");
Type[] noTypeArray = new Type[0];
ConstructorBuilder cbuilder;
DefineType(name, ispublic, typeof(Regex));
{
// define constructor
_methbuilder = null;
MethodAttributes ma = System.Reflection.MethodAttributes.Public;
cbuilder = _typebuilder.DefineConstructor(ma, CallingConventions.Standard, noTypeArray);
_ilg = cbuilder.GetILGenerator();
{
// call base constructor
Ldthis();
_ilg.Emit(OpCodes.Call, typeof(Regex).GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
null, new Type[0], new ParameterModifier[0]));
// set pattern
Ldthis();
Ldstr(pattern);
Stfld(patternF);
// set options
Ldthis();
Ldc((int) opts);
Stfld(optionsF);
// set factory
Ldthis();
Newobj(factory.GetConstructor(noTypeArray));
Stfld(factoryF);
// set caps
if (code._caps != null)
GenerateCreateHashtable(capsF, code._caps);
// set capnames
if (tree._capnames != null)
GenerateCreateHashtable(capnamesF, tree._capnames);
// set capslist
if (tree._capslist != null) {
Ldthis();
Ldc(tree._capslist.Length);
_ilg.Emit(OpCodes.Newarr, typeof(String)); // create new string array
Stfld(capslistF);
for (int i=0; i< tree._capslist.Length; i++) {
Ldthisfld(capslistF);
Ldc(i);
Ldstr(tree._capslist[i]);
_ilg.Emit(OpCodes.Stelem_Ref);
}
}
// set capsize
Ldthis();
Ldc(code._capsize);
Stfld(capsizeF);
// set runnerref and replref by calling InitializeReferences()
Ldthis();
Call(typeof(Regex).GetMethod("InitializeReferences", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
Ret();
}
}
// bake the constructor and type, then save the assembly
cbuilder = null;
_typebuilder.CreateType();
_ilg = null;
_typebuilder = null;
}