コード例 #1
0
        /// <summary>
        /// Is overridden to define how the type definition is translated by this strategy.
        /// </summary>
        /// <param name="type">Type definition that should be tranlated.</param>
        /// <param name="templatingEngine">Templating engine that can be used to fill predefined code snippets.</param>
        /// <returns>Result of the translation.</returns>
        protected override CodeFragment Translate(Type type, ITemplatingEngine templatingEngine)
        {
            var decorators  = DecoratorTranslator.GenerateDecorators(type);
            var properties  = GeneratePropertyDefinitions(type, templatingEngine);
            var declaration = GenerateClassDeclaration(type);
            var deps        = declaration.dependencies.Merge(properties.dependencies).Merge(decorators.Dependencies);

            var code = templatingEngine.UseTemplate("ClassDefinition", new Dictionary <string, string>
            {
                { "Decorators", decorators.DecoratorCode },
                { "ClassName", type.GetNameWithGenericTypeParameters() },
                { "ClassDeclaration", declaration.code },
                { "Documentation", GenerateDocumentationComment(type) },
                { "Properties", properties.code.AddIndentation() },
                { "Dependencies", GenerateDependencyInitialization(deps, templatingEngine) },
                { "ConstructorCode", declaration.isDerived
                    ? $"{ Environment.NewLine }super();".AddIndentation(2)
                    : string.Empty }
            });

            return(new CodeFragment(
                       CodeFragmentId.ForClrType(type),
                       code,
                       deps));
        }
コード例 #2
0
        /// <summary>
        /// Is overridden to define how the type definition is translated by this strategy.
        /// </summary>
        /// <param name="type">Type definition that should be tranlated.</param>
        /// <param name="templatingEngine">Templating engine that can be used to fill predefined code snippets.</param>
        /// <returns>Result of the translation.</returns>
        protected override CodeFragment Translate(Type type, ITemplatingEngine templatingEngine)
        {
            var code = templatingEngine.UseTemplate("EnumDefinition", new Dictionary <string, string>
            {
                { "EnumName", type.Name },
                { "Documentation", GenerateDocumentationComment(type) },
                { "EnumValues", GenerateEnumValues(type, templatingEngine).AddIndentation() },
                { "EnumAttributeMaps", GenerateEnumAttributeMaps(type, templatingEngine) }
            });

            return(new CodeFragment(
                       CodeFragmentId.ForClrType(type),
                       code,
                       CodeDependencies.Empty));
        }
コード例 #3
0
        /// <summary>
        /// Is overridden to define how the type definition is translated by this strategy.
        /// </summary>
        /// <param name="type">Type definition that should be tranlated.</param>
        /// <param name="templatingEngine">Templating engine that can be used to fill predefined code snippets.</param>
        /// <returns>Result of the translation.</returns>
        protected override CodeFragment Translate(Type type, ITemplatingEngine templatingEngine)
        {
            var properties  = GeneratePropertyDefinitions(type, templatingEngine, out var dependencies);
            var declaration = GenerateClassDeclaration(type);

            dependencies = dependencies.Merge(declaration.dependencies);

            var code = templatingEngine.UseTemplate("InterfaceDefinition", new Dictionary <string, string>
            {
                { "InterfaceDeclaration", declaration.code },
                { "Documentation", GenerateDocumentationComment(type) },
                { "Properties", properties.AddIndentation() }
            });

            return(new CodeFragment(
                       CodeFragmentId.ForClrType(type),
                       code,
                       dependencies));
        }
コード例 #4
0
        /// <summary>
        /// Is overridden to define how the type reference is translated by this strategy.
        /// </summary>
        /// <param name="referencedType">Type reference that should be tranlated.</param>
        /// <param name="translator">Full translator that can be used to translate parts of the complete type reference.</param>
        /// <returns>Result of the translation.</returns>
        protected override TypeReferenceTranslationResult Translate(Type referencedType, ITypeReferenceTranslator translator)
        {
            var translatedTypeArguments = referencedType.GetGenericArguments().Select(translator.Translate);
            var referencedTypeName      = referencedType.GetNameWithoutGenericTypeParameters()
                                          + $"<{ string.Join(", ", translatedTypeArguments.Select(x => x.ReferencedTypeName)) }>";

            return(new TypeReferenceTranslationResult(referencedTypeName,
                                                      CodeDependencies.FromCodeFragments(new[] { CodeFragmentId.ForClrType(referencedType.GetGenericTypeDefinition()) })
                                                      .Merge(translatedTypeArguments.Aggregate(CodeDependencies.Empty, (x, n) => x.Merge(n.Dependencies)))));
        }
コード例 #5
0
 /// <summary>
 /// Is overridden to define how the type reference is translated by this strategy.
 /// </summary>
 /// <param name="referencedType">Type reference that should be tranlated.</param>
 /// <param name="translator">Full translator that can be used to translate parts of the complete type reference.</param>
 /// <returns>Result of the translation.</returns>
 public TypeReferenceTranslationResult Translate(Type referencedType)
 => new TypeReferenceTranslationResult(
     referencedType.Name,
     CodeDependencies.FromCodeFragments(new[] { CodeFragmentId.ForClrType(referencedType) }));