Beispiel #1
0
        private MetadataItem MapItem(MethodMetadataDto objectToMap)
        {
            bool hasChildren =
                objectToMap.GenericArguments.Any() ||
                objectToMap.Parameters.Any();

            return(new MetadataItem(
                       $"{objectToMap.Modifiers.Item1} " +
                       $"{objectToMap.ReturnType?.TypeName ?? "void"} " +
                       $"{objectToMap.Name}",
                       hasChildren));
        }
Beispiel #2
0
        private IEnumerable <Relation> GetRelations(MethodMetadataDto parent)
        {
            foreach (var argument in parent.GenericArguments)
            {
                yield return(new Relation(parent.Id, argument.Id));
            }

            foreach (var parameter in parent.Parameters)
            {
                yield return(new Relation(parent.Id, parameter.Id));
            }

            if (parent.ReturnType != null)
            {
                yield return(new Relation(parent.Id, parent.ReturnType.Id));
            }
        }
Beispiel #3
0
        internal MethodMetadataDto LoadMethodMetadataDto(MethodBase method, AssemblyMetadataStorage metaStore)
        {
            if (method == null)
            {
                throw new ArgumentNullException($"{nameof(method)} argument is null.");
            }

            MethodMetadataDto methodMetadataDto = new MethodMetadataDto()
            {
                Name      = method.Name,
                Modifiers = EmitModifiers(method),
                Extension = IsExtension(method)
            };

            methodMetadataDto.GenericArguments = !method.IsGenericMethodDefinition ? new List <TypeMetadataDto>() : EmitGenericArguments(method.GetGenericArguments(), metaStore);
            methodMetadataDto.ReturnType       = EmitReturnType(method, metaStore);
            methodMetadataDto.Parameters       = EmitParameters(method.GetParameters(), metaStore).ToList();

            string parameters = methodMetadataDto.Parameters.Any()
                ? methodMetadataDto.Parameters.Select(methodInstance => methodInstance.Name)
                                .Aggregate((current, next) => current + ", " + next)
                : "none";

            string generics = methodMetadataDto.GenericArguments.Any()
                ? methodMetadataDto.GenericArguments.Select(typeInstance => typeInstance.Id)
                              .Aggregate((c, n) => $"{c}, {n}")
                : "none";

            methodMetadataDto.Id = $"{method.DeclaringType.FullName}{method.Name} args {parameters} generics {generics} declaredBy {method.DeclaringType.FullName}";

            if (!metaStore.MethodsDictionary.ContainsKey(methodMetadataDto.Id))
            {
                _logger.Trace("Adding method to dictionary: Id =" + methodMetadataDto.Id);
                metaStore.MethodsDictionary.Add(methodMetadataDto.Id, methodMetadataDto);
                return(methodMetadataDto);
            }
            else
            {
                _logger.Trace("Using method already added to dictionary: Id =" + methodMetadataDto.Id);
                return(metaStore.MethodsDictionary[methodMetadataDto.Id]);
            }
        }
Beispiel #4
0
        protected void With_VoidMethodMetadata(IEnumerable <ParameterMetadataDto> parameters)
        {
            TypeMetadataDto typeMetadata = _storage.TypesDictionary[_typeName];

            typeMetadata.TypeKind = TypeKind.ClassType;

            MethodMetadataDto methodMetadata = new MethodMetadataDto()
            {
                Id               = _methodName,
                Name             = _methodName,
                GenericArguments = new List <TypeMetadataDto>(),
                Modifiers        = new Tuple <AccessLevel, AbstractEnum, StaticEnum, VirtualEnum>(
                    _methodAccessLevel,
                    default(AbstractEnum),
                    default(StaticEnum),
                    default(VirtualEnum)),
                ReturnType = null,
                Parameters = parameters
            };

            (typeMetadata.Methods as List <MethodMetadataDto>).Add(methodMetadata);
            _storage.MethodsDictionary.Add(methodMetadata.Id, methodMetadata);
        }