//----------------------------------------------------------------------------------------------------------------------------------------------------- internal protected FieldMember DefineField(string name, Type fieldType, bool isStatic, bool isPublic = false) { var field = new FieldMember(m_OwnerClass, name, fieldType, isStatic, isPublic); m_OwnerClass.AddMember(field); return(field); }
public override object Exec(ClassType ct) { // * Without type variables, no clone is necessary if (!ct.HasTypeVariables()) { return(ct); } // * Let's check recursion if (!this.clonedClasses.Contains(ct)) { this.clonedClasses.Add(ct); } else // * Recursion { return(new ClassTypeProxy(ct, this.typeVariableMappings, this.equivalenceClasses)); } // * We clone the members of the ClassType ClassType newClassType = new ClassType(ct.FullName); newClassType.ConcreteType = ct.ConcreteType; newClassType.IsDynamic = ct.IsDynamic; Dictionary <string, AccessModifier> oldFields = ct.Fields; newClassType.fieldList = new Dictionary <string, AccessModifier>(); // * We must create new type variables for fields foreach (KeyValuePair <string, AccessModifier> pair in oldFields) { // * Every type variable is cloned to a new one, adding both to typesVariables, // inserting its equivalence classes in the equivalenceClasses parameter and updating the // typeVariableMappings dictionary (<oldvariable,newVariable> FieldType fieldType = (FieldType)pair.Value.Type.Exec(this); fieldType.MemberInfo.Class = newClassType; newClassType.AddMember(pair.Key, fieldType.MemberInfo); } // * We must create new attribute info (access modifiers) but without clonning methods foreach (KeyValuePair <string, AccessModifier> pair in ct.Methods) { AccessModifier accesModifier = (AccessModifier)pair.Value.Clone(); accesModifier.Class = newClassType; newClassType.AddMember(pair.Key, accesModifier); } // * The same with the base class newClassType.baseClass = (ClassType)ct.baseClass.CloneType(typeVariableMappings); newClassType.ValidTypeExpression = false; // * The new class type is returned return(newClassType); }
//------------------------------------------------------------------------------------------------------------------------------------------------- private ImplementationClassWriter <TBase> DefineEventImplementations <TWriter>( Func <EventMember, AttributeWriter> attributes, Func <EventMember, TWriter> writerFactory) where TWriter : EventWriterBase { var eventsToImplement = m_OwnerClass.TakeNotImplementedMembers(m_SelectedEvents); foreach (var singleEvent in eventsToImplement) { var eventMember = new EventMember(m_OwnerClass, singleEvent); m_OwnerClass.AddMember(eventMember); var writer = writerFactory(eventMember); writer.AddAttributes(attributes); } return(m_ClassWriter); }
//------------------------------------------------------------------------------------------------------------------------------------------------- private ImplementationClassWriter <TBase> DefinePropertyImplementations <TWriter>( Func <PropertyMember, AttributeWriter> attributes, Func <PropertyMember, TWriter> writerFactory, FieldMember backingField = null) where TWriter : PropertyWriterBase { var propertiesToImplement = m_OwnerClass.TakeNotImplementedMembers(m_SelectedProperties); foreach (var property in propertiesToImplement) { var propertyMember = new PropertyMember(m_OwnerClass, property, backingField); m_OwnerClass.AddMember(propertyMember); var writer = writerFactory(propertyMember); writer.AddAttributes(attributes); } return(m_ClassWriter); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- #region IAnonymousMethodOperand Members public void CreateAnonymousMethod(ClassType ownerClass, ClosureDefinition closure, bool isStatic, bool isPublic) { Debug.Assert(m_Method == null, "CreateAnonymousMethod was already called."); var methodFactory = new AnonymousMethodFactory( ownerClass, hostMethod: m_HomeScopeBlock.OwnerMethod, argumentTypes: m_Signature.ArgumentType, returnType: m_Signature.ReturnType, isStatic: isStatic, isPublic: isPublic); m_Method = new MethodMember(ownerClass, methodFactory, closure); m_Method.SetBody(m_Statements); ownerClass.AddMember(m_Method); m_Signature = m_Method.Signature; var operandBinder = new BindToMethodOperandVisitor(m_Method); m_Method.AcceptVisitor(operandBinder); }