/// <summary> /// Checks whether is source change EnC-valid, if so, returns null. If not, returns BuildError instance. /// </summary> /// <param name="change">SourceChange instance to be checked for validity.</param> /// <returns>Null or BuildError instance in case of not EnC valid change given.</returns> public static BuildError IsValid(SourceChange change) { if (change.IsError) { return createError(change.OldEntity, "Element cannot be changed by EnC."); } switch (change.MemberAction) { case SourceChangeAction.Created: return isValidCreation(change.NewEntity); case SourceChangeAction.ModifierChanged: return createError(change.OldEntity,"Cannot modify entities's definition with EnC."); case SourceChangeAction.TypeParameterChanged: return createError(change.OldEntity,"Cannot modify entities's definition with EnC."); case SourceChangeAction.BodyChanged: return null; case SourceChangeAction.Removed: return createError(change.OldEntity,"Cannot remove entities with EnC."); case SourceChangeAction.ReturnTypeChanged: return createError(change.OldEntity, "Cannot change type of entity or return type with EnC."); default: return new BuildError("","Cannot reckognize change."); } }
/// <summary> /// Determines if <c>change</c> represent body change of specified <c>property</c>. /// </summary> private bool bodyChangeEquals(SourceChange change, IProperty property) { return(change.OldEntity == change.NewEntity && change.NewEntity is IProperty && MemberComparator.SameProperties((IProperty)change.NewEntity, property)); }
/// <summary> /// Find differences between list of classes. /// </summary> /// <param name="classes1">First list of classes.</param> /// <param name="classes2">Seconf list of classes.</param> /// <param name="changes"><c>List</c> containing changes in classes.</param> private void diffToClasses(IEnumerable<IClass> classes1, IEnumerable<IClass> classes2,List<SourceChange> changes) { foreach (IClass element in classes1) { IClass gClass = ProjectContentCopy.GetClass(classes2, element.FullyQualifiedName, element.TypeParameters.Count); if (gClass != null) { // For classes in both this.classes and cont diffToClass(element, gClass, changes); } else { // For classes in this.classes and not in cont. SourceChange classRemoved = new SourceChange(element, element, SourceChangeMember.Class, SourceChangeAction.Removed); changes.Add(classRemoved); } } // For classes in cont and not in this.classes. foreach (IClass element in classes2) { IClass gClass = ProjectContentCopy.GetClass(classes2, element.FullyQualifiedName, element.TypeParameters.Count); if (gClass == null) { SourceChange classRemoved = new SourceChange(element, element, SourceChangeMember.Class, SourceChangeAction.Created); changes.Add(classRemoved); } } }
/// <summary> /// Determines if <c>change</c> represent body change of specified <c>method</c>. /// </summary> private bool bodyChangeEquals(SourceChange change, IMethod method) { return(change.OldEntity == change.NewEntity && change.NewEntity is IMethod && MemberComparator.SameMethodOverloads((IMethod)change.NewEntity, method)); }
/// <summary> /// Determines if <c>change</c> represent body change of specified <c>entity</c>. /// </summary> private bool bodyChangeEquals(SourceChange change, IEntity entity) { // It should always fall to overloads above. if (entity is IProperty) return bodyChangeEquals(change, (IProperty)entity); else if (entity is IMethod) return bodyChangeEquals(change, (IMethod)entity); throw new ArgumentException(); }
/// <summary> /// Determines if <c>change</c> represent body change of specified <c>property</c>. /// </summary> private bool bodyChangeEquals(SourceChange change,IProperty property) { return (change.OldEntity == change.NewEntity && change.NewEntity is IProperty && MemberComparator.SameProperties((IProperty)change.NewEntity,property)); }
/// <summary> /// Determines if <c>change</c> represent body change of specified <c>method</c>. /// </summary> private bool bodyChangeEquals(SourceChange change,IMethod method) { return (change.OldEntity == change.NewEntity && change.NewEntity is IMethod && MemberComparator.SameMethodOverloads((IMethod)change.NewEntity,method)); }
/// <summary> /// Make generic change to running assembly using EnC. /// </summary> /// <param name="change">Description of change.</param> public void MakeChange(SourceChange change) { switch (change.MemberKind) { case SourceChangeMember.Method: if (change.MemberAction == SourceChangeAction.BodyChanged) { ChangeMethod((IMethod)change.OldEntity); } else if (change.MemberAction == SourceChangeAction.Created && change.NewEntity.IsPrivate && !change.NewEntity.IsVirtual) { AddMethod((IMethod)change.NewEntity); } else { throw new TranslatingException("This kind of change is not supported by this version of EnC."); } break; case SourceChangeMember.Property: if (change.MemberAction == SourceChangeAction.BodyChanged) { ChangeProperty((IProperty)change.OldEntity, ((BodyChange)change).isGetter); } else { throw new TranslatingException("This kind of change is not supported by this version of EnC."); } break; case SourceChangeMember.Field: if (change.MemberAction == SourceChangeAction.Created) { addField((IField)change.NewEntity); } else { throw new TranslatingException("This kind of change is not supported by this version of EnC."); } break; default: throw new TranslatingException("This kind of change is not supported by this version of EnC."); } }