コード例 #1
0
        public ITranslatedTypeMetadata Process(Type specificEnumType)
        {
            Debug.Assert(CanProcess(specificEnumType));

            var symbol = SymbolNamer.GetNameFor(specificEnumType.GetTypeInfo());

            var definition = GetDefinitionForEnum(symbol, specificEnumType);

            TranslatedTypeMetadata.Symbol     = symbol;
            TranslatedTypeMetadata.Definition = definition;
            return(TranslatedTypeMetadata);
        }
コード例 #2
0
        public ITranslatedTypeMetadata Process(Type specificTargetType)
        {
            Debug.Assert(CanProcess(specificTargetType));
            var genericArgumentTypes = specificTargetType.GetGenericArguments();

            IsProcessed = true;

            TranslatedTypeMetadata.Symbol = SymbolNamer.GetNameFor(TypeInfo, genericArgumentTypes);

            var sb = new StringBuilder();

            // TODO Class case only now, think of interfaces
            sb.Append(Commenter.TypeCommentFor(TypeInfo));
            sb.Append(Expression.NewLine());
            sb.Append(Expression.ClassNameExpression(TranslatedTypeMetadata.Symbol));
            if (SourceTypeMetadata.BaseType != null)
            {
                var baseTypeType = SourceTypeMetadata.BaseType.AsType();

                var typeTranslationContext     = TranslationContext.GetByType(baseTypeType);
                var translatedBaseTypeMetadata = typeTranslationContext.Process(baseTypeType);

                var baseTypeSymbol = translatedBaseTypeMetadata.Symbol;
                sb.Append(Expression.InheritedClassExpression(baseTypeSymbol));
            }

            sb.Append(Expression.BlockBegin());

            foreach (var memberName in SourceTypeMetadata.Members)
            {
                var sourceMemberInfo = SourceTypeMetadata[memberName];
                if (SkipTypeRule.AppliesTo(sourceMemberInfo))
                {
                    continue;
                }

                var type = ((sourceMemberInfo as PropertyInfo)?.PropertyType)
                           .NullTo((sourceMemberInfo as FieldInfo)?.FieldType);
                Debug.Assert(type != null, $"sourceMemberInfo is supposed to be either a PropertyInfo or FieldInfo but was {sourceMemberInfo.GetType()}");

                var memberTypeTranslationContext = TranslationContext.GetByType(type);
                var translatedMemberTypeMetadata = memberTypeTranslationContext.Process(type); // TODO Process is not needed as a part of Interface!!!

                var sourceTypeComment = Commenter.TypeCommentFor(type.GetTypeInfo());
                sb.Append(Expression.MemberDefinitionExpression(sourceMemberInfo.Name, translatedMemberTypeMetadata.Symbol, sourceTypeComment));
            }

            sb.Append(Expression.BlockEnd());

            TranslatedTypeMetadata.Definition = sb.ToString();

            return(TranslatedTypeMetadata);
        }