private IEnumerable <RawUsingItem> AnalyzeType(TypeDefinition type, ItemTail parentCustomSections, WorkingGraph readingGraph) { ItemTail typeCustomSections = GetCustomSections(readingGraph, type.CustomAttributes, parentCustomSections); yield return(GetClassItem(type, typeCustomSections, readingGraph)); foreach (PropertyDefinition property in type.Properties) { foreach (var usingItem in AnalyzeProperty(property, typeCustomSections, readingGraph)) { yield return(usingItem); } } foreach (MethodDefinition method in type.Methods) { ItemTail methodCustomSections = GetCustomSections(readingGraph, method.CustomAttributes, typeCustomSections); yield return(GetFullNameItem(type, method.Name, markers: null, customSections: methodCustomSections, readingGraph: readingGraph)); } foreach (TypeDefinition nestedType in type.NestedTypes) { foreach (var usingItem in AnalyzeType(nestedType, typeCustomSections, readingGraph)) { yield return(usingItem); } } }
protected IEnumerable <RawDependency> ReadRawDependencies(int depth, WorkingGraph readingGraph) { Log.WriteInfo(new string(' ', 2 * depth) + "Reading " + FullFileName); var resolver = new DefaultAssemblyResolver(); resolver.AddSearchDirectory(Path.GetDirectoryName(FullFileName)); // readingGraph: Additional search directories should be specifiable in options resolver.AddSearchDirectory(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0"); AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(FullFileName, new ReaderParameters { AssemblyResolver = resolver }); try { assembly.MainModule.ReadSymbols(); } catch (Exception ex) { Log.WriteWarning($"Loading symbols for assembly {FullFileName} failed - maybe .PDB file is missing. ({ex.Message})", FullFileName, 0); } ItemTail customSections = GetCustomSections(readingGraph, assembly.CustomAttributes, null); foreach (TypeDefinition type in assembly.MainModule.Types) { if (type.Name == "<Module>") { continue; } foreach (var dependency in AnalyzeType(type, customSections, readingGraph)) { yield return(dependency); } } }
private ItemTail ExtractCustomSections(WorkingGraph readingGraph, CustomAttribute customAttribute, ItemTail parent) { TypeReference customAttributeTypeReference = customAttribute.AttributeType; TypeDefinition attributeType = Resolve(customAttributeTypeReference); bool isSectionAttribute = attributeType != null && attributeType.Interfaces.Any(i => i.FullName == "NDepCheck.ISectionAttribute"); if (isSectionAttribute) { string[] keys = attributeType.Properties.Select(property => property.Name).ToArray(); FieldDefinition itemTypeNameField = attributeType.Fields.FirstOrDefault(f => f.Name == "ITEM_TYPE"); if (itemTypeNameField == null) { //??? Log.WriteError(); throw new Exception("string constant ITEM_TYPE not defined in " + attributeType.FullName); } else { string itemTypeName = "" + itemTypeNameField.Constant; ItemType itemType = GetOrDeclareType(itemTypeName, Enumerable.Repeat("CUSTOM", keys.Length), keys.Select(k => "." + k)); var args = keys.Select((k, i) => new { Key = k, Index = i, Property = customAttribute.Properties.FirstOrDefault(p => p.Name == k) }); string[] values = args.Select(a => a.Property.Name == null ? parent?.Values[a.Index] : "" + a.Property.Argument.Value).ToArray(); return(ItemTail.New(readingGraph.ItemTailCache, itemType, values)); } } else { return(parent); } }
protected override IEnumerable <RawUsingItem> ReadUsingItems(int depth, WorkingGraph readingGraph) { Log.WriteInfo("Reading " + FullFileName); AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(FullFileName); try { assembly.MainModule.ReadSymbols(); } catch (Exception ex) { Log.WriteWarning( $"Loading symbols for assembly {FullFileName} failed - maybe .PDB file is missing. ({ex.Message})", FullFileName, 0); } ItemTail customSections = GetCustomSections(readingGraph, assembly.CustomAttributes, null); foreach (TypeDefinition type in assembly.MainModule.Types) { if (type.Name == "<Module>") { continue; } foreach (var usingItem in AnalyzeType(type, customSections, readingGraph)) { yield return(usingItem); } } AssemblyNameDefinition currentAssembly = assembly.Name; yield return(RawUsingItem.New(_rawUsingItemsCache, DOTNETASSEMBLY, namespaceName: "", className: "", assemblyName: currentAssembly.Name, assemblyVersion: currentAssembly.Version.ToString(), assemblyCulture: currentAssembly.Culture, memberName: "", markers: null, tail: null, readingGraph: readingGraph)); }
private IEnumerable <RawUsingItem> AnalyzeProperty(PropertyDefinition property, ItemTail typeCustomSections, WorkingGraph readingGraph) { ItemTail propertyCustomSections = GetCustomSections(readingGraph, property.CustomAttributes, typeCustomSections); yield return(GetFullNameItem(property.DeclaringType, property.Name, GET_MARKER, propertyCustomSections, readingGraph)); yield return(GetFullNameItem(property.DeclaringType, property.Name, SET_MARKER, propertyCustomSections, readingGraph)); }
private RawUsingItem CreateUsingItem([NotNull] ItemType itemType, [NotNull] TypeReference typeReference, [CanBeNull] ItemTail customSections, [CanBeNull, ItemNotNull] string[] markers, WorkingGraph readingGraph) { string namespaceName, className, assemblyName, assemblyVersion, assemblyCulture; GetTypeInfo(typeReference, out namespaceName, out className, out assemblyName, out assemblyVersion, out assemblyCulture); return(RawUsingItem.New(_rawUsingItemsCache, itemType, namespaceName, className, assemblyName, assemblyVersion, assemblyCulture, "", markers, customSections, readingGraph)); }
private RawUsingItem([NotNull] ItemType itemType, [NotNull] string namespaceName, [NotNull] string className, [NotNull] string assemblyName, [CanBeNull] string assemblyVersion, [CanBeNull] string assemblyCulture, [CanBeNull] string memberName, [CanBeNull, ItemNotNull] string[] markers, [CanBeNull] ItemTail tail, [NotNull] WorkingGraph readingGraph) : base(itemType, namespaceName, className, assemblyName, assemblyVersion, assemblyCulture, memberName, markers, readingGraph) { _tail = tail; }
private RawUsingItem GetClassItem(TypeReference typeReference, ItemTail customSections, WorkingGraph readingGraph) { string namespaceName, className, assemblyName, assemblyVersion, assemblyCulture; GetTypeInfo(typeReference, out namespaceName, out className, out assemblyName, out assemblyVersion, out assemblyCulture); return(RawUsingItem.New(_rawUsingItemsCache, DotNetAssemblyDependencyReaderFactory.DOTNETTYPE, namespaceName, className, assemblyName, assemblyVersion, assemblyCulture, memberName: "", markers: null, tail: customSections, readingGraph: readingGraph)); }
protected ItemTail GetCustomSections(WorkingGraph readingGraph, Collection <CustomAttribute> customAttributes, [CanBeNull] ItemTail customSections) { ItemTail result = customSections; foreach (var customAttribute in customAttributes) { result = ExtractCustomSections(readingGraph, customAttribute, null) ?? result; } return(result); }
private IEnumerable <RawDependency> AnalyzeProperty([NotNull] TypeDefinition owner, [NotNull] RawUsingItem usingItem, [NotNull] PropertyDefinition property, [CanBeNull] ItemTail typeCustomSections, WorkingGraph readingGraph) { ItemTail propertyCustomSections = GetCustomSections(readingGraph, property.CustomAttributes, typeCustomSections); foreach (var dependency_ in AnalyzeCustomAttributes(usingItem, property.CustomAttributes, readingGraph)) { yield return(dependency_); } foreach (ParameterDefinition parameter in property.Parameters) { foreach (var dependency_ in CreateTypeAndMethodDependencies(usingItem, DOTNETPARAMETER, GetParameterMarkers(parameter, _parameterDefinitionMarkers), parameter.ParameterType, usage: DotNetUsage._declaresparameter, sequencePoint: null, memberName: parameter.Name, readingGraph: readingGraph)) { yield return(dependency_); } } if (property.PropertyType != null) { foreach (var dependency_ in CreateTypeAndMethodDependencies(usingItem, DOTNETTYPE, GetMemberMarkers(property, _propertyDefinitionMarkers), property.PropertyType, usage: DotNetUsage._declaresreturntype, sequencePoint: null, memberName: property.Name, readingGraph: readingGraph)) { yield return(dependency_); } } foreach (var dependency in AnalyzeGetterSetter(owner, property, GET_MARKER, propertyCustomSections, property.GetMethod, readingGraph)) { yield return(dependency); } foreach (var dependency in AnalyzeGetterSetter(owner, property, SET_MARKER, propertyCustomSections, property.SetMethod, readingGraph)) { yield return(dependency); } }
private IEnumerable <RawDependency> AnalyzeGetterSetter([NotNull] TypeDefinition owner, [NotNull] PropertyDefinition property, [NotNull] string[] markers, [CanBeNull] ItemTail propertyCustomSections, [CanBeNull] MethodDefinition getterSetter, WorkingGraph readingGraph) { if (getterSetter != null) { RawUsingItem usingItem = CreateUsingItem(DOTNETPROPERTY, property.DeclaringType, property.Name, markers, propertyCustomSections, readingGraph); // readingGraph: WHY???yield return new RawDependency(DOTNETITEM, usingItem, null, null); foreach (var dependency in AnalyzeMethod(owner, usingItem, getterSetter, readingGraph)) { yield return(dependency); } } }
private IEnumerable <RawDependency> AnalyzeType([NotNull] TypeDefinition type, [CanBeNull] ItemTail parentCustomSections, WorkingGraph readingGraph) { ItemTail typeCustomSections = GetCustomSections(readingGraph, type.CustomAttributes, parentCustomSections); { RawUsingItem usingItem = CreateUsingItem(DOTNETTYPE, type, typeCustomSections, GetMemberMarkers(type, _typeDefinitionMarkers), readingGraph); // readingGraph: WHY???yield return new RawDependency(DOTNETITEM, usingItem, null, null); foreach (var dependency_ in AnalyzeCustomAttributes(usingItem, type.CustomAttributes, readingGraph)) { yield return(dependency_); } if (type.BaseType != null && !IsLinked(type.BaseType, type.DeclaringType)) { foreach (var dependency_ in CreateTypeAndMethodDependencies(usingItem, DOTNETTYPE, GetMemberMarkers(type, _typeDefinitionMarkers), type.BaseType, usage: DotNetUsage._directlyderivedfrom, sequencePoint: null, memberName: "", readingGraph: readingGraph)) { yield return(dependency_); } } foreach (TypeReference interfaceRef in type.Interfaces) { foreach (var dependency_ in CreateTypeAndMethodDependencies(usingItem, DOTNETTYPE, GetMemberMarkers(Resolve(interfaceRef), _typeDefinitionMarkers), interfaceRef, usage: DotNetUsage._directlyimplements, sequencePoint: null, memberName: "", readingGraph: readingGraph)) { yield return(dependency_); } } foreach (FieldDefinition field in type.Fields) { //if (IsLinked(field.FieldType, type.DeclaringType)) { ItemTail fieldCustomSections = GetCustomSections(readingGraph, field.CustomAttributes, typeCustomSections); // readingGraph: WHY??? yield return new RawDependency(DOTNETITEM, GetFullnameItem(type, field.Name, "", fieldCustomSections), null, null); foreach (var dependency_ in CreateTypeAndMethodDependencies(usingItem, DOTNETFIELD, GetMemberMarkers(field, _fieldDefinitionMarkers), field.FieldType, usage: DotNetUsage._declaresfield, sequencePoint: null, memberName: field.Name, readingGraph: readingGraph)) { yield return(dependency_); } //} } foreach (EventDefinition @event in type.Events) { ItemTail eventCustomSections = GetCustomSections(readingGraph, @event.CustomAttributes, typeCustomSections); // readingGraph: WHY??? yield return new RawDependency(DOTNETITEM, GetFullnameItem(type, @event.Name, "", eventCustomSections), null, null); foreach (var dependency_ in CreateTypeAndMethodDependencies(usingItem, DOTNETEVENT, GetMemberMarkers(@event, _eventDefinitionMarkers), @event.EventType, usage: DotNetUsage._declaresevent, sequencePoint: null, memberName: @event.Name, readingGraph: readingGraph)) { yield return(dependency_); } } foreach (var property in type.Properties) { //if (!IsLinked(property.PropertyType, type.DeclaringType)) { foreach (var dependency_ in AnalyzeProperty(type, usingItem, property, typeCustomSections, readingGraph)) { yield return(dependency_); } //} } } foreach (MethodDefinition method in type.Methods) { ItemTail methodCustomSections = GetCustomSections(readingGraph, method.CustomAttributes, typeCustomSections); RawUsingItem usingItem = CreateUsingItem(DOTNETMETHOD, type, method.Name, GetMemberMarkers(method, _methodDefinitionMarkers), methodCustomSections, readingGraph); // readingGraph: WHY???yield return new RawDependency(DOTNETITEM, usingItem, null, null); foreach (var dependency_ in AnalyzeMethod(type, usingItem, method, readingGraph)) { yield return(dependency_); } } foreach (TypeDefinition nestedType in type.NestedTypes) { foreach (var dependency_ in AnalyzeType(nestedType, typeCustomSections, readingGraph)) { yield return(dependency_); } } }
private IEnumerable <RawDependency> AnalyzeType([NotNull] TypeDefinition type, [CanBeNull] ItemTail parentCustomSections, WorkingGraph readingGraph) { ItemTail typeCustomSections = GetCustomSections(readingGraph, type.CustomAttributes, parentCustomSections); RawUsingItem usingItem = CreateUsingItem(DOTNETTYPE, type, typeCustomSections, GetMemberMarkers(type, _typeDefinitionMarkers), readingGraph); // readingGraph: WHY???yield return new RawDependency(DOTNETITEM, usingItem, null, null); foreach (var dependency in AnalyzeCustomAttributes(usingItem, type.CustomAttributes, readingGraph)) { yield return(dependency); } foreach (var genericParameter in type.GenericParameters) { RawUsedItem usedItem = CreateUsedItem(DOTNETGENERICPARAMETER, genericParameter, genericParameter.Name, NO_MARKERS, readingGraph); yield return(new RawDependency(usingItem, usedItem, DotNetUsage._usesasgenericargument, sequencePoint: null, readerForUsedItem: _readingContext.ReaderGang.OfType <AbstractDotNetAssemblyDependencyReader>() .FirstOrDefault(r => r.AssemblyName == usedItem.AssemblyName))); RawUsingItem usingParameter = CreateUsingItem(DOTNETGENERICPARAMETER, genericParameter, genericParameter.Name, NO_MARKERS, customSections: null, readingGraph: readingGraph); foreach (var rawDependency in AnalyzeGenericParameter(usingParameter, genericParameter, readingGraph)) { yield return(rawDependency); } } if (type.BaseType != null && !IsLinked(type.BaseType, type.DeclaringType)) { foreach (var dependency in CreateTypeAndMethodDependencies(usingItem, type.BaseType, DotNetUsage._directlyderivedfrom, readingGraph)) { yield return(dependency); } } foreach (TypeReference interfaceRef in type.Interfaces) { foreach (var dependency in CreateTypeAndMethodDependencies(usingItem, interfaceRef, DotNetUsage._directlyimplements, readingGraph)) { yield return(dependency); } } foreach (FieldDefinition field in type.Fields) { //if (IsLinked(field.FieldType, type.DeclaringType)) { ItemTail fieldCustomSections = GetCustomSections(readingGraph, field.CustomAttributes, typeCustomSections); // readingGraph: WHY??? yield return new RawDependency(DOTNETITEM, GetFullnameItem(type, field.Name, "", fieldCustomSections), null, null); foreach (var dependency in CreateTypeAndMethodDependencies(usingItem, DOTNETFIELD, GetMemberMarkers(field, _fieldDefinitionMarkers), field.FieldType, usage: DotNetUsage._declaresfield, sequencePoint: null, memberName: field.Name, readingGraph: readingGraph)) { yield return(dependency); } //} } foreach (EventDefinition @event in type.Events) { ItemTail eventCustomSections = GetCustomSections(readingGraph, @event.CustomAttributes, typeCustomSections); // readingGraph: WHY??? yield return new RawDependency(DOTNETITEM, GetFullnameItem(type, @event.Name, "", eventCustomSections), null, null); foreach (var dependency in CreateTypeAndMethodDependencies(usingItem, DOTNETEVENT, GetMemberMarkers(@event, _eventDefinitionMarkers), @event.EventType, usage: DotNetUsage._declaresevent, sequencePoint: null, memberName: @event.Name, readingGraph: readingGraph)) { yield return(dependency); } } foreach (var property in type.Properties) { //if (!IsLinked(property.PropertyType, type.DeclaringType)) { foreach (var dependency in AnalyzeProperty(type, usingItem, property, typeCustomSections, readingGraph)) { yield return(dependency); } //} } foreach (MethodDefinition method in type.Methods) { ItemTail methodCustomSections = GetCustomSections(readingGraph, method.CustomAttributes, typeCustomSections); RawUsedItem usedItem = CreateUsedItem(DOTNETMETHOD, type, method.Name, GetMemberMarkers(method, _methodDefinitionMarkers), readingGraph); yield return (new RawDependency(usingItem, usedItem, DotNetUsage._declaresmethod, sequencePoint: null, readerForUsedItem: _readingContext.ReaderGang.OfType <AbstractDotNetAssemblyDependencyReader>() .FirstOrDefault(r => r.AssemblyName == usedItem.AssemblyName))); RawUsingItem usingMethod = CreateUsingItem(DOTNETMETHOD, type, method.Name, GetMemberMarkers(method, _methodDefinitionMarkers), methodCustomSections, readingGraph); // readingGraph: WHY???yield return new RawDependency(DOTNETITEM, usingItem, null, null); foreach (var dependency in AnalyzeMethod(type, usingMethod, method, readingGraph)) { yield return(dependency); } } foreach (TypeDefinition nestedType in type.NestedTypes) { foreach (var dependency in AnalyzeType(nestedType, typeCustomSections, readingGraph)) { yield return(dependency); } } }
public static RawUsingItem New([NotNull] Intern <RawUsingItem> cache, [NotNull] ItemType itemType, [NotNull] string namespaceName, [NotNull] string className, [NotNull] string assemblyName, [CanBeNull] string assemblyVersion, [CanBeNull] string assemblyCulture, [CanBeNull] string memberName, [CanBeNull, ItemNotNull] string[] markers, [CanBeNull] ItemTail tail, [NotNull] WorkingGraph readingGraph) { return(cache.GetReference(new RawUsingItem(itemType, namespaceName, className, assemblyName, assemblyVersion, assemblyCulture, memberName, markers, tail, readingGraph))); }