protected void ConvertFieldReferencesInConstructors(FilteredTypeMembers constructors, string oldName, string newName) { // Do this for all constructors we have. foreach(CodeTypeMemberExtension ctorExtension in constructors) { // Get a reference to the actual constructor object. CodeConstructor constructor = (CodeConstructor)ctorExtension.ExtendedObject; // Do this for all statements we have in the constructor. foreach (CodeStatement statement in constructor.Statements) { // Is this an assign statement? CodeAssignStatement assignStatement = statement as CodeAssignStatement; if (assignStatement != null) { // Do we have a field reference on the left side of the assignment statement? CodeFieldReferenceExpression fieldRef = assignStatement.Left as CodeFieldReferenceExpression; if (fieldRef != null) { // Does the referenced field belong to the this object? if (typeof(CodeThisReferenceExpression) == fieldRef.TargetObject.GetType()) { // Change the field name if it's changed. if (fieldRef.FieldName == oldName) { fieldRef.FieldName = newName; } } } } } } }
private void ConvertMembers(FilteredTypeMembers filteredTypeMembers) { foreach (CodeTypeMemberExtension memberExt in filteredTypeMembers) { // Move to the next item if this is not convertible. if (!IsConvertibleMemeber(memberExt)) { continue; } if (memberExt.Kind == CodeTypeMemberKind.Field) { CodeMemberField field = (CodeMemberField)memberExt.ExtendedObject; field.Type = GetCollectionTypeReference(field.Type); HandleShouldSerialize(memberExt); } else if (memberExt.Kind == CodeTypeMemberKind.Property) { CodeMemberProperty property = (CodeMemberProperty)memberExt.ExtendedObject; property.Type = GetCollectionTypeReference(property.Type); HandleShouldSerialize(memberExt); } else if (memberExt.Kind == CodeTypeMemberKind.Method || memberExt.Kind == CodeTypeMemberKind.Constructor || memberExt.Kind == CodeTypeMemberKind.StaticConstructor) { CodeMemberMethod method = (CodeMemberMethod)memberExt.ExtendedObject; ProcessMethod(method); } } }
private void RefactorFields(FilteredTypeMembers fields, string oldName, string newName) { foreach (CodeTypeMemberExtension memberExtension in fields) { CodeMemberField field = (CodeMemberField)memberExtension.ExtendedObject; RefactorCodeTypeReference(field.Type, oldName, newName); RefactorCodeTypeReferencesInAttributes(field.CustomAttributes, oldName, newName); } }
public CodeTypeExtension(CodeTypeDeclaration codeTypeDeclaration) : base((CodeTypeMember)codeTypeDeclaration) { this.fields = new FilteredTypeMembers(codeTypeDeclaration.Members); this.properties = new FilteredTypeMembers(codeTypeDeclaration.Members); this.methods = new FilteredTypeMembers(codeTypeDeclaration.Members); this.constructors = new FilteredTypeMembers(codeTypeDeclaration.Members); this.events = new FilteredTypeMembers(codeTypeDeclaration.Members); this.unknown = new FilteredTypeMembers(codeTypeDeclaration.Members); }
private void RefactorProperties(FilteredTypeMembers properties, string oldName, string newName) { foreach (CodeTypeMemberExtension memberExtension in properties) { CodeMemberProperty property = (CodeMemberProperty)memberExtension.ExtendedObject; // Update the property type. RefactorCodeTypeReference(property.Type, oldName, newName); // Update the type references in attributes. RefactorCodeTypeReferencesInAttributes(property.CustomAttributes, oldName, newName); } }
/// <summary> /// This method updates the references in methods. /// </summary> private void RefactorMethods(FilteredTypeMembers methods, string oldName, string newName) { // Do this for all member extensions wrapping methods. foreach (CodeTypeMemberExtension memberExtension in methods) { // Get a reference to the underlying CodeMemberMethod object. CodeMemberMethod method = (CodeMemberMethod)memberExtension.ExtendedObject; // Update the parameters types. RefactorMethodParameterReferences(method.Parameters, oldName, newName); // Do we have a return type? if (method.ReturnType != null) { // Update the return type if necessary. RefactorCodeTypeReference(method.ReturnType, oldName, newName); } // Update method attributes. RefactorCodeTypeReferencesInAttributes(method.CustomAttributes, oldName, newName); // Update the statements. RefactorCodeStatements(method.Statements, oldName, newName); } }