예제 #1
0
        private RawUsedItem CreateUsedItem([NotNull] ItemType itemType, [NotNull] TypeReference typeReference, [NotNull] string memberName, [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(RawUsedItem.New(itemType, namespaceName, className, assemblyName, assemblyVersion, assemblyCulture, memberName, markers, readingGraph));
        }
 public new RawUsedItem ToRawUsedItem()
 {
     // ReSharper disable once ConvertIfStatementToNullCoalescingExpression
     if (_usedItem == null)
     {
         _usedItem = base.ToRawUsedItem();
     }
     return(_usedItem);
 }
        [CanBeNull] // null (I think) if assemblies do not match (different compiles) and hence a used item is not found in target reader.
        protected Item GetFullItemFor(WorkingGraph readingGraph, RawUsedItem rawUsedItem, int depth)
        {
            if (_rawItems2Items == null)
            {
                _rawItems2Items = new Dictionary <RawUsedItem, Item>();
                foreach (var u in ReadUsingItems(depth + 1, readingGraph))
                {
                    RawUsedItem usedItem = u.ToRawUsedItem();
                    _rawItems2Items[usedItem] = u.ToItem();
                }
            }
            Item result;

            _rawItems2Items.TryGetValue(rawUsedItem, out result);
            return(result);
        }
 public RawDependency([NotNull] RawUsingItem usingItem, [NotNull] RawUsedItem usedItem,
                      DotNetUsage usage, [CanBeNull] SequencePoint sequencePoint, AbstractDotNetAssemblyDependencyReader readerForUsedItem)
 {
     if (usingItem == null)
     {
         throw new ArgumentNullException(nameof(usingItem));
     }
     if (usedItem == null)
     {
         throw new ArgumentNullException(nameof(usedItem));
     }
     UsingItem          = usingItem;
     UsedItem           = usedItem;
     Usage              = usage;
     _readerForUsedItem = readerForUsedItem;
     _sequencePoint     = sequencePoint;
 }
예제 #5
0
        /// <summary>
        /// Create a single dependency to the calledType or (if passed) calledType+method.
        /// Create additional dependencies for each generic parameter type of calledType.
        /// </summary>
        private IEnumerable <RawDependency> CreateTypeAndMethodDependencies([NotNull] RawUsingItem usingItem,
                                                                            [NotNull] ItemType usedItemType, [CanBeNull, ItemNotNull] string[] usedMarkers, [NotNull] TypeReference usedType,
                                                                            DotNetUsage usage, [CanBeNull] SequencePoint sequencePoint, [NotNull] string memberName, WorkingGraph readingGraph)
        {
            if (usedType is TypeSpecification)
            {
                // E.g. the reference type System.int&, which is used for out parameters.
                // or an arraytype?!?
                usedType = ((TypeSpecification)usedType).ElementType;
            }
            if (!(usedType is GenericInstanceType) && !(usedType is GenericParameter))
            {
                // Here, we do not look at generic type parameters; we would have to
                // untangle the usage of an actual (non-type-parameter) type's member
                // to get a useful Dependency for the user.
                // Generic parameters and their constraints are handled above.

                RawUsedItem usedItem = CreateUsedItem(usedItemType, usedType, memberName, usedMarkers, readingGraph);

                yield return(new RawDependency(usingItem, usedItem, usage, sequencePoint,
                                               _readingContext.ReaderGang.OfType <AbstractDotNetAssemblyDependencyReader>().FirstOrDefault(r => r.AssemblyName == usedItem.AssemblyName)));
            }

            var genericInstanceType = usedType as GenericInstanceType;

            if (genericInstanceType != null)
            {
                foreach (TypeReference genericArgument in genericInstanceType.GenericArguments)
                {
                    foreach (var dependency in CreateTypeAndMethodDependencies(usingItem, DOTNETTYPE,
                                                                               GetMemberMarkers(Resolve(genericArgument), _typeDefinitionMarkers), genericArgument,
                                                                               usage: DotNetUsage._usesasgenericargument, sequencePoint: sequencePoint, memberName: genericArgument.Name,
                                                                               readingGraph: readingGraph))
                    {
                        yield return(dependency);
                    }
                }
            }
        }
예제 #6
0
        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);
                }
            }
        }
 protected RawUsedItem ToRawUsedItem()
 {
     return(RawUsedItem.New(ItemType, NamespaceName, ClassName, AssemblyName, _assemblyVersion, _assemblyCulture, MemberName, _markers, _readingGraph));
 }