public override IComparerResult Compare() { ComparerContext.LogInfo(string.Format("Comparing assemblies '{0}' and '{1}'", ReferenceType.FullName, NewType.FullName)); CompareAssemblyInformation(); CompareTypes(); return(ComparerResult); }
protected void CompareParameters() { IEnumerable<Tuple<ParameterInfo, ParameterInfo>> parameterPairs = ReferenceType.GetParameters().Zip(NewType.GetParameters(), (refParam, newParam) => new Tuple<ParameterInfo, ParameterInfo>(refParam, newParam)); foreach (Tuple<ParameterInfo, ParameterInfo> parameterPair in parameterPairs) { ComparerResult.AddComparerResult(ComparerContext.CreateComparer(parameterPair.Item1, parameterPair.Item2).Compare()); } }
public override IComparerResult Compare() { ComparerContext.LogDetail(string.Format("Comparing parameter '{0}'", ReferenceType.ParameterType)); CompareAttributes(); CompareName(); CompareDefaultValue(); return(ComparerResult); }
public override IComparerResult Compare() { ComparerContext.LogDetail(string.Format("Comparing method '{0}'", ReferenceType)); CompareAttributes(); CompareReturnType(); CompareParameters(); return(ComparerResult); }
public override IComparerResult Compare() { ComparerContext.LogDetail(string.Format("Comparing {0} '{1}'", GetItemType(ReferenceType), ReferenceType.GetCompareableName())); CompareAttributes(); CompareInterfaces(); CompareBase(); CompareMethods(type => type.GetApiMethods().Where(method => ComparerContext.IsNotIgnored(method)).Cast <MethodBase>().ToArray(), (type, name, types) => type.GetMethod(name, types), ResultContext.Method); CompareMethods(type => type.GetApiConstructors().Where(ctor => ComparerContext.IsNotIgnored(ctor)).Cast <MethodBase>().ToArray(), (type, name, types) => type.GetApiConstructor(name, types), ResultContext.Constructor); CompareProperties(); CompareEvents(); CompareFields(); return(ComparerResult); }
public override IComparerResult Compare() { ComparerContext.LogDetail(string.Format("Comparing event '{0}'", ReferenceType)); if (ReferenceType.EventHandlerType.GetCompareableName() != NewType.EventHandlerType.GetCompareableName()) { ComparerResult.AddChangedProperty("Type", ReferenceType.EventHandlerType.GetCompareableName(), NewType.EventHandlerType.GetCompareableName(), Severity.Error); } bool referenceStatic = (ReferenceType.AddMethod != null && ReferenceType.AddMethod.IsStatic) || (ReferenceType.RaiseMethod != null && ReferenceType.RaiseMethod.IsStatic); bool newStatic = (NewType.AddMethod != null && NewType.AddMethod.IsStatic) || (NewType.RaiseMethod != null && NewType.RaiseMethod.IsStatic); if (referenceStatic != newStatic) { ComparerResult.AddChangedFlag("Static", referenceStatic, Severity.Error); } return(ComparerResult); }
private void CompareEvents() { IEnumerable <string> referenceEvents = GetEvents(ReferenceType).ToList(); IEnumerable <string> newEvents = GetEvents(NewType).ToList(); // missing event foreach (string @event in referenceEvents.Except(newEvents)) { ComparerResult.AddRemovedItem(ResultContext.Event, @event, Severity.Error); } // new event foreach (string @event in newEvents.Except(referenceEvents)) { ComparerResult.AddAddedItem(ResultContext.Event, @event, Severity.Warning); } // equal events foreach (string @event in newEvents.Intersect(referenceEvents)) { ComparerResult.AddComparerResult(ComparerContext.CreateComparer(ReferenceType.GetEvent(@event), NewType.GetEvent(@event)).Compare()); } }
public override IComparerResult Compare() { ComparerContext.LogDetail(string.Format("Comparing field '{0}'", ReferenceType)); if (ReferenceType.FieldType.GetCompareableName() != NewType.FieldType.GetCompareableName()) { ComparerResult.AddChangedProperty("Type", ReferenceType.FieldType.GetCompareableName(), NewType.FieldType.GetCompareableName(), Severity.Error); } if (ReferenceType.IsStatic != NewType.IsStatic) { ComparerResult.AddChangedFlag("Static", ReferenceType.IsStatic, Severity.Error); } if (ReferenceType.IsStatic && NewType.IsStatic && ReferenceType.FieldType.IsEnum) { // compare numeric enum values object referenceValue = ReferenceType.GetRawConstantValue(); object newValue = NewType.GetRawConstantValue(); if (Convert.ToInt32(referenceValue) != Convert.ToInt32(newValue)) { ComparerResult.AddChangedProperty("Value", referenceValue.ToString(), newValue.ToString(), Severity.Error); } } return(ComparerResult); }
private void CompareFields() { IEnumerable <string> referenceFields = GetFields(ReferenceType).ToList(); IEnumerable <string> newFields = GetFields(NewType).ToList(); // missing fields foreach (string field in referenceFields.Except(newFields)) { ComparerResult.AddRemovedItem(ResultContext.Field, field, Severity.Error); } // new fields foreach (string field in newFields.Except(referenceFields)) { ComparerResult.AddAddedItem(ResultContext.Field, field, Severity.Warning); } // equal fields foreach (string field in referenceFields.Intersect(newFields)) { ComparerResult.AddComparerResult(ComparerContext.CreateComparer(ReferenceType.GetField(field), NewType.GetField(field)).Compare()); } }
private void CompareTypes() { IEnumerable <string> referenceTypes = GetTypeNames(() => ReferenceType.DefinedTypes).ToList(); IEnumerable <string> newTypes = GetTypeNames(() => NewType.DefinedTypes).ToList(); // Missing types foreach (string type in referenceTypes.Except(newTypes)) { ComparerResult.AddRemovedItem(GetItemType(ReferenceType.GetType(type)), type, Severities.TypeRemoved); } // New types foreach (string type in newTypes.Except(referenceTypes)) { ComparerResult.AddAddedItem(GetItemType(NewType.GetType(type)), type, Severities.TypeAdded); } // Equal types foreach (string type in referenceTypes.Intersect(newTypes)) { ComparerResult.AddComparerResult(ComparerContext.CreateComparer(ReferenceType.GetType(type), NewType.GetType(type)).Compare()); } }
private void CompareProperties() { PairList <Item> pairList = new PairList <Item>(); GetProperties(ReferenceType).ForEach(property => pairList.AddReferenceItem(new Item(property.Name, property.GetIndexParameterTypes()))); GetProperties(NewType).ForEach(property => pairList.AddNewItem(new Item(property.Name, property.GetIndexParameterTypes()))); foreach (Item property in pairList.RemovedItems) { ComparerResult.AddRemovedItem(ResultContext.Property, ReferenceType.GetApiProperty(property.Name, property.Types).ToString(), Severity.Error); } foreach (Item property in pairList.AddedItems) { ComparerResult.AddAddedItem(ResultContext.Property, NewType.GetApiProperty(property.Name, property.Types).ToString(), Severity.Warning); } foreach (ItemPair <Item> property in pairList.EqualItems) { PropertyInfo referenceProperty = ReferenceType.GetApiProperty(property.ReferenceItem.Name, property.ReferenceItem.Types); PropertyInfo newProperty = NewType.GetApiProperty(property.NewItem.Name, property.NewItem.Types); ComparerResult.AddComparerResult(ComparerContext.CreateComparer(referenceProperty, newProperty).Compare()); } }
public override IComparerResult Compare() { ComparerContext.LogDetail(string.Format("Comparing property '{0}'", ReferenceType)); if (ReferenceType.PropertyType.GetCompareableName() != NewType.PropertyType.GetCompareableName()) { ComparerResult.AddChangedProperty("Type", ReferenceType.PropertyType.GetCompareableName(), NewType.PropertyType.GetCompareableName(), Severity.Error); } if (ReferenceType.CanWrite != NewType.CanWrite) { ComparerResult.AddChangedFlag("Setter", ReferenceType.CanWrite, Severity.Error); } if (ReferenceType.CanRead != NewType.CanRead) { ComparerResult.AddChangedFlag("Getter", ReferenceType.CanRead, Severity.Error); } bool referenceStatic = (ReferenceType.GetMethod != null && ReferenceType.GetMethod.IsStatic) || (ReferenceType.SetMethod != null && ReferenceType.SetMethod.IsStatic); bool newStatic = (NewType.GetMethod != null && NewType.GetMethod.IsStatic) || (NewType.SetMethod != null && NewType.SetMethod.IsStatic); if (referenceStatic != newStatic) { ComparerResult.AddChangedFlag("Static", referenceStatic, Severity.Error); } return(ComparerResult); }
private void CompareMethods(Func <Type, MethodBase[]> getMethods, ResultContext resultContext) { PairList <MethodItem> pairList = new PairList <MethodItem>(); getMethods(ReferenceType).ToList().ForEach(m => pairList.AddReferenceItem(new MethodItem(m))); getMethods(NewType).ToList().ForEach(m => pairList.AddNewItem(new MethodItem(m))); foreach (MethodItem item in pairList.RemovedItems) { ComparerResult.AddRemovedItem(resultContext, item.Method.ToString(), Severities.MethodRemoved); } foreach (MethodItem item in pairList.AddedItems) { ComparerResult.AddAddedItem(resultContext, item.Method.ToString(), Severities.MethodAdded); } foreach (ItemPair <MethodItem> itemPair in pairList.EqualItems) { MethodBase referenceMethod = itemPair.ReferenceItem.Method; MethodBase newMethod = itemPair.NewItem.Method; ComparerResult.AddComparerResult(ComparerContext.CreateComparer(referenceMethod, newMethod).Compare()); } }
private void CompareMethods(Func <Type, MethodBase[]> getMethods, Func <Type, string, Type[], MethodBase> getMethod, ResultContext resultContext) { PairList <Item> pairList = new PairList <Item>(); AddMethodsToPairList(pairList.AddReferenceItem, () => getMethods(ReferenceType)); AddMethodsToPairList(pairList.AddNewItem, () => getMethods(NewType)); foreach (Item method in pairList.RemovedItems) { ComparerResult.AddRemovedItem(resultContext, getMethod(ReferenceType, method.Name, method.Types).ToString(), Severity.Error); } foreach (Item method in pairList.AddedItems) { ComparerResult.AddAddedItem(resultContext, getMethod(NewType, method.Name, method.Types).ToString(), Severity.Warning); } foreach (ItemPair <Item> methodPair in pairList.EqualItems) { MethodBase referenceMethod = getMethod(ReferenceType, methodPair.ReferenceItem.Name, methodPair.ReferenceItem.Types); MethodBase newMethod = getMethod(NewType, methodPair.NewItem.Name, methodPair.NewItem.Types); ComparerResult.AddComparerResult(ComparerContext.CreateComparer(referenceMethod, newMethod).Compare()); } }
private IEnumerable <string> GetInterfaces(TypeInfo typeInfo) { return(typeInfo.GetInterfaces().Where(@interface => ComparerContext.IsNotIgnored(@interface.GetTypeInfo())).Select(@interface => @interface.GetCompareableName())); }
public override IComparerResult Compare() { ComparerContext.LogDetail(string.Format("Comparing constructor '{0}'", ReferenceType)); CompareParameters(); return(ComparerResult); }
private IEnumerable <string> GetTypeNames(Func <IEnumerable <TypeInfo> > getTypes) { return(getTypes().Where(type => type.IsVisible && ComparerContext.IsNotIgnored(type)).Select(type => type.GetCompareableName())); }
private IEnumerable <string> GetEvents(TypeInfo typeInfo) { return(typeInfo.GetApiEvents().Where(@event => ComparerContext.IsNotIgnored(@event)).Select(@event => @event.Name)); }
private IEnumerable <PropertyInfo> GetProperties(TypeInfo typeInfo) { return(typeInfo.GetApiProperties().Where(property => ComparerContext.IsNotIgnored(property))); }
private IEnumerable <string> GetFields(TypeInfo typeInfo) { return(typeInfo.GetApiFields().Where(field => ComparerContext.IsNotIgnored(field)).Select(field => field.Name)); }