public FieldDefinition InsertField (FieldDefinition field, bool clone) { if (fields.ContainsKey (field.Name)) { Console.Error.WriteLine ("Error: duplicated field {0}", field.Name); return null; } else { if (clone) { field = field.Clone (); } fields [field.Name] = field; return field; } }
static FieldDefinition ImportFieldDefinition(FieldDefinition field, ImportContext context) { return(FieldDefinition.Clone(field, context)); }
internal static TypeDefinition Clone(TypeDefinition type, ImportContext context) { TypeDefinition nt = new TypeDefinition( type.Name, type.Namespace, type.Attributes); context.GenericContext.Type = nt; foreach (GenericParameter p in type.GenericParameters) { nt.GenericParameters.Add(GenericParameter.Clone(p, context)); } if (type.BaseType != null) { nt.BaseType = context.Import(type.BaseType); } if (type.HasLayoutInfo) { nt.ClassSize = type.ClassSize; nt.PackingSize = type.PackingSize; } foreach (FieldDefinition field in type.Fields) { nt.Fields.Add(FieldDefinition.Clone(field, context)); } foreach (MethodDefinition ctor in type.Constructors) { nt.Constructors.Add(MethodDefinition.Clone(ctor, context)); } foreach (MethodDefinition meth in type.Methods) { nt.Methods.Add(MethodDefinition.Clone(meth, context)); } foreach (EventDefinition evt in type.Events) { nt.Events.Add(EventDefinition.Clone(evt, context)); } foreach (PropertyDefinition prop in type.Properties) { nt.Properties.Add(PropertyDefinition.Clone(prop, context)); } foreach (TypeReference intf in type.Interfaces) { nt.Interfaces.Add(context.Import(intf)); } foreach (TypeDefinition nested in type.NestedTypes) { nt.NestedTypes.Add(Clone(nested, context)); } foreach (CustomAttribute ca in type.CustomAttributes) { nt.CustomAttributes.Add(CustomAttribute.Clone(ca, context)); } foreach (SecurityDeclaration dec in type.SecurityDeclarations) { nt.SecurityDeclarations.Add(SecurityDeclaration.Clone(dec)); } return(nt); }