本文整理汇总了C#中TypeBuilder类的典型用法代码示例。如果您正苦于以下问题:C# TypeBuilder类的具体用法?C# TypeBuilder怎么用?C# TypeBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeBuilder类属于命名空间,在下文中一共展示了TypeBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
override internal IntPtr Create(TypeBuilder builder)
{
if (Type.IsNullable)
return builder.GetRuntimeTypeHandle(Type.Instantiation[0]).ToIntPtr();
else
return builder.GetRuntimeTypeHandle(Type).ToIntPtr();
}
示例2: MethodBuilder
/// <summary>
/// Default ctor
/// </summary>
private MethodBuilder(MethodDefinition javaMethod, TypeBuilder declaringTypeBuilder, SignedByteMode signedByteMode)
{
this.javaMethod = javaMethod;
this.declaringTypeBuilder = declaringTypeBuilder;
this.signedByteMode = signedByteMode;
this.addJavaPrefix = signedByteMode == SignedByteMode.HasUnsignedPartnerOnlyInReturnType;
}
示例3: AddAutomagicSerialization
internal static ConstructorInfo AddAutomagicSerialization(DynamicTypeWrapper wrapper, TypeBuilder typeBuilder)
{
ConstructorInfo serializationCtor = null;
if (wrapper.GetClassLoader().NoAutomagicSerialization)
{
// do nothing
}
else if ((wrapper.Modifiers & IKVM.Attributes.Modifiers.Enum) != 0)
{
MarkSerializable(typeBuilder);
}
else if (wrapper.IsSubTypeOf(serializable) && IsSafeForAutomagicSerialization(wrapper))
{
if (wrapper.IsSubTypeOf(externalizable))
{
MethodWrapper ctor = wrapper.GetMethodWrapper("<init>", "()V", false);
if (ctor != null && ctor.IsPublic)
{
MarkSerializable(typeBuilder);
ctor.Link();
serializationCtor = AddConstructor(typeBuilder, ctor, null, true);
if (!wrapper.BaseTypeWrapper.IsSubTypeOf(serializable))
{
AddGetObjectData(typeBuilder);
}
if (wrapper.BaseTypeWrapper.GetMethodWrapper("readResolve", "()Ljava.lang.Object;", true) != null)
{
RemoveReadResolve(typeBuilder);
}
}
}
else if (wrapper.BaseTypeWrapper.IsSubTypeOf(serializable))
{
ConstructorInfo baseCtor = wrapper.GetBaseSerializationConstructor();
if (baseCtor != null && (baseCtor.IsFamily || baseCtor.IsFamilyOrAssembly))
{
MarkSerializable(typeBuilder);
serializationCtor = AddConstructor(typeBuilder, null, baseCtor, false);
AddReadResolve(wrapper, typeBuilder);
}
}
else
{
MethodWrapper baseCtor = wrapper.BaseTypeWrapper.GetMethodWrapper("<init>", "()V", false);
if (baseCtor != null && baseCtor.IsAccessibleFrom(wrapper.BaseTypeWrapper, wrapper, wrapper))
{
MarkSerializable(typeBuilder);
AddGetObjectData(typeBuilder);
#if STATIC_COMPILER
// because the base type can be a __WorkaroundBaseClass__, we may need to replace the constructor
baseCtor = ((AotTypeWrapper)wrapper).ReplaceMethodWrapper(baseCtor);
#endif
baseCtor.Link();
serializationCtor = AddConstructor(typeBuilder, baseCtor, null, true);
AddReadResolve(wrapper, typeBuilder);
}
}
}
return serializationCtor;
}
示例4: AddMethodDynamically
public void AddMethodDynamically (ref TypeBuilder myTypeBld,
string mthdName,
Type [] mthdParams,
Type returnType,
string mthdAction)
{
MethodBuilder myMthdBld = myTypeBld.DefineMethod (
mthdName,
MethodAttributes.Public |
MethodAttributes.Static,
returnType,
mthdParams);
ILGenerator ILout = myMthdBld.GetILGenerator ();
int numParams = mthdParams.Length;
for (byte x = 0; x < numParams; x++)
ILout.Emit (OpCodes.Ldarg_S, x);
if (numParams > 1) {
for (int y = 0; y < (numParams - 1); y++) {
switch (mthdAction) {
case "A": ILout.Emit (OpCodes.Add);
break;
case "M": ILout.Emit (OpCodes.Mul);
break;
default: ILout.Emit (OpCodes.Add);
break;
}
}
}
ILout.Emit (OpCodes.Ret);
}
示例5: GetRuntimeTypeHandleWithNullableTransform
// Helper method for nullable transform. Ideally, we would do the nullable transform upfront before
// the types is build. Unfortunately, there does not seem to be easy way to test for Nullable<> type definition
// without introducing type builder recursion
private static RuntimeTypeHandle GetRuntimeTypeHandleWithNullableTransform(TypeBuilder builder, TypeDesc type)
{
RuntimeTypeHandle th = builder.GetRuntimeTypeHandle(type);
if (RuntimeAugments.IsNullable(th))
th = builder.GetRuntimeTypeHandle(((DefType)type).Instantiation[0]);
return th;
}
示例6: NestedTypeBuilder
/// <summary>
/// Default ctor
/// </summary>
protected NestedTypeBuilder(TypeBuilder parent, string parentFullName, ClassFile cf, InnerClass inner)
{
this.parent = parent;
this.parentFullName = parentFullName;
this.cf = cf;
this.inner = inner;
}
示例7: MethodBuilder
/// <summary>
/// Default ctor
/// </summary>
private MethodBuilder(MethodDefinition javaMethod, TypeBuilder declaringTypeBuilder, bool convertSignedBytes, bool addJavaPrefix)
{
this.javaMethod = javaMethod;
this.declaringTypeBuilder = declaringTypeBuilder;
this.convertSignedBytes = convertSignedBytes;
this.addJavaPrefix = addJavaPrefix;
}
示例8: ImplementMembersForm
public ImplementMembersForm(NemerleSource source, TypeBuilder ty, IEnumerable<IGrouping<FixedType.Class, IMember>> unimplementedMembers)
{
_source = source;
_ty = ty;
_unimplementedMembers = unimplementedMembers;
InitializeComponent();
#region Init events hendlers
_grid.CellPainting += CellPainting;
_grid.CellValueChanged += CellValueChanged;
_grid.CellValidating += CellValidating;
_grid.CurrentCellDirtyStateChanged += CurrentCellDirtyStateChanged;
#endregion
#region Init ImageList
imageList1.Images.AddStrip(Resources.SO_TreeViewIcons);
_imageSize = imageList1.ImageSize.Width;
Debug.Assert(imageList1.ImageSize.Width == imageList1.ImageSize.Height);
#endregion
if (_unimplementedMembers == null)
return;
FillTable(MakeTypeMembersMap());
}
示例9: Prepare
override internal void Prepare(TypeBuilder builder)
{
if (Type.IsCanonicalSubtype(CanonicalFormKind.Any))
Environment.FailFast("Canonical types do not have EETypes");
builder.RegisterForPreparation(Type);
}
示例10: CreateProperty
private static void CreateProperty(TypeBuilder tb, string propertyName, Type propertyType)
{
FieldBuilder fieldBuilder = tb.DefineField("_" + propertyName, propertyType, FieldAttributes.Private);
PropertyBuilder propertyBuilder = tb.DefineProperty(propertyName, PropertyAttributes.HasDefault, propertyType, null);
MethodBuilder getPropMthdBldr = tb.DefineMethod("get_" + propertyName, MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig, propertyType, Type.EmptyTypes);
ILGenerator getIl = getPropMthdBldr.GetILGenerator();
getIl.Emit(OpCodes.Ldarg_0);
getIl.Emit(OpCodes.Ldfld, fieldBuilder);
getIl.Emit(OpCodes.Ret);
MethodBuilder setPropMthdBldr =
tb.DefineMethod("set_" + propertyName,
MethodAttributes.Public |
MethodAttributes.SpecialName |
MethodAttributes.HideBySig,
null, new[] { propertyType });
ILGenerator setIl = setPropMthdBldr.GetILGenerator();
Label modifyProperty = setIl.DefineLabel();
Label exitSet = setIl.DefineLabel();
setIl.MarkLabel(modifyProperty);
setIl.Emit(OpCodes.Ldarg_0);
setIl.Emit(OpCodes.Ldarg_1);
setIl.Emit(OpCodes.Stfld, fieldBuilder);
setIl.Emit(OpCodes.Nop);
setIl.MarkLabel(exitSet);
setIl.Emit(OpCodes.Ret);
propertyBuilder.SetGetMethod(getPropMthdBldr);
propertyBuilder.SetSetMethod(setPropMthdBldr);
}
示例11: Create
internal static IEnumerable<NestedTypeBuilder> Create(TypeBuilder parent, string parentFullName, ClassFile cf, InnerClass inner)
{
if (cf.IsInterface && cf.Fields.Any())
{
yield return new NestedInterfaceConstantsTypeBuilder(parent, parentFullName, cf, inner);
}
yield return new NestedTypeBuilder(parent, parentFullName, cf, inner);
}
示例12: FieldBuilder
/// <summary>
/// Default ctor
/// </summary>
public FieldBuilder(FieldDefinition javaField, TypeBuilder declaringTypeBuilder)
{
if (javaField == null)
throw new ArgumentNullException("javaField");
if (declaringTypeBuilder == null)
throw new ArgumentNullException("declaringTypeBuilder");
this.javaField = javaField;
this.declaringTypeBuilder = declaringTypeBuilder;
}
示例13: Finish
public unsafe void Finish(TypeBuilder typeBuilder)
{
Debug.Assert(_cells.Length == 0 || _addressOfFirstCellSlot != IntPtr.Zero);
IntPtr* realCells = (IntPtr*)_addressOfFirstCellSlot;
for (int i = 0; i < _cells.Length; i++)
{
realCells[i] = _cells[i].Create(typeBuilder);
}
}
示例14: BuildEntitySets
private void BuildEntitySets(EdmEntityContainer container, IEnumerable<EntityElement> rootElements, TypeBuilder typeBuilder)
{
foreach (var rootEntity in rootElements)
{
var entitySetName = rootEntity.EntitySetName ?? rootEntity.ResolveName();
var schemaType = typeBuilder.BuildSchemaType(rootEntity);
container.AddEntitySet(entitySetName, (IEdmEntityType)schemaType);
}
}
示例15: FieldBuilder
/// <summary>
/// Constructor
/// </summary>
/// <param name="TypeBuilder">Type builder</param>
/// <param name="Name">Name of the method</param>
/// <param name="Attributes">Attributes for the field (public, private, etc.)</param>
/// <param name="FieldType">Type for the field</param>
public FieldBuilder(TypeBuilder TypeBuilder, string Name, Type FieldType, FieldAttributes Attributes)
: base()
{
Contract.Requires<ArgumentNullException>(TypeBuilder!=null,"TypeBuilder");
Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(Name),"Name");
this.Name = Name;
this.Type = TypeBuilder;
this.DataType = FieldType;
this.Attributes = Attributes;
Builder = Type.Builder.DefineField(Name, FieldType, Attributes);
}