/// <summary> /// Checks for errors before applying a rule. /// </summary> /// <param name="node">The node instance to check.</param> /// <param name="dataList">Optional data collected during inspection of sources.</param> /// <param name="data">Private data to give to Apply() upon return.</param> /// <returns>True if an error occured.</returns> public override bool CheckConsistency(IInheritance node, IDictionary <ISourceTemplate, object> dataList, out object data) { bool Success = true; data = null; IClassType ParentTypeWithRename = null; IClassType ResolvedParent = node.ResolvedClassParentType.Item; ISealableDictionary <string, string> SourceIdentifierTable = new SealableDictionary <string, string>(); // string (source) -> string (destination) ISealableDictionary <string, string> DestinationIdentifierTable = new SealableDictionary <string, string>(); // string (destination) -> string (source) ISealableDictionary <IFeatureName, ISealableDictionary <string, IClass> > RenamedExportTable = ResolvedParent.ExportTable.CloneUnsealed(); ISealableDictionary <IFeatureName, ITypedefType> RenamedTypedefTable = ResolvedParent.TypedefTable.CloneUnsealed(); ISealableDictionary <IFeatureName, IDiscrete> RenamedDiscreteTable = ResolvedParent.DiscreteTable.CloneUnsealed(); ISealableDictionary <IFeatureName, IFeatureInstance> RenamedFeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>(); foreach (KeyValuePair <IFeatureName, IFeatureInstance> Entry in ResolvedParent.FeatureTable) { IFeatureName AncestorFeatureName = Entry.Key; IFeatureInstance AncestorFeatureInstance = Entry.Value; RenamedFeatureTable.Add(AncestorFeatureName, AncestorFeatureInstance.Clone(ResolvedParent)); } foreach (IRename RenameItem in node.RenameList) { Success &= RenameItem.CheckGenericRename(new IDictionaryIndex <IFeatureName>[] { RenamedExportTable, RenamedTypedefTable, RenamedDiscreteTable, RenamedFeatureTable }, SourceIdentifierTable, DestinationIdentifierTable, (IFeatureName item) => item.Name, (string name) => new FeatureName(name), ErrorList); } if (Success) { Success &= ResolveInstancingAfterRename(node, RenamedExportTable, RenamedTypedefTable, RenamedDiscreteTable, RenamedFeatureTable); if (Success) { IClass EmbeddingClass = node.EmbeddingClass; ParentTypeWithRename = ClassType.Create(ResolvedParent.BaseClass, ResolvedParent.TypeArgumentTable, EmbeddingClass.ResolvedClassType.Item); ParentTypeWithRename.ExportTable.Merge(RenamedExportTable); ParentTypeWithRename.ExportTable.Seal(); ParentTypeWithRename.TypedefTable.Merge(RenamedTypedefTable); ParentTypeWithRename.TypedefTable.Seal(); ParentTypeWithRename.DiscreteTable.Merge(RenamedDiscreteTable); ParentTypeWithRename.DiscreteTable.Seal(); ParentTypeWithRename.FeatureTable.Merge(RenamedFeatureTable); ParentTypeWithRename.FeatureTable.Seal(); } } if (Success) { data = ParentTypeWithRename; } return(Success); }