Правильный способ генерации общего кода в генераторах исходного кодаC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Правильный способ генерации общего кода в генераторах исходного кода

Сообщение Anonymous »


I am working on a library that will use source generators to provide implementation for user defined types. Which type to generate the code for and how to generate it is provided using Attributes on the type to generate the implementation for. The generated type will use some delegates that will be the same in every generated type. In a project like this there seem to be 3 kinds of code that will be generated:
  • Code that defines the attributes that will later be used in the generator
  • Code that defines types that will be reused in the rest of the generated code
  • Code that defines actual types the user requested

From what I understood from source generator examples it is a common practice to define all types used in the user code by generating them rather than including them in own assembly.

I have some problems understanding how the generated code will behave in a multi-project solution. Suppose with have 2 assemblies A and B, where each needs my library to generate some source code. With my current implementation both assemblies will have definitions for needed attributes, delegates and partial user types.

My problem is, what happens when both assemblies have definitions for the same delegates in the same namespace(They should be in the same namespace since they are used in all generated types)? If the delegates are generated there is no compilation error, but if I define the same delegates in a different solution where they are not generated and are included in separate assemblies I get the error: CS0101 (The namespace 'MyNamespace' already contains a definition for 'MyDelegate').

This gets me to think if these types when generated in different assemblies will be interchangeable. I think my actual question is if I am generating my sources correctly. Is it right to generate everything the user assembly will need or should I provide some types in the actual assembly of my source generator library?

I am not sure if what I written above is understandable enough to provide an answer but I wouldn't know how to describe it better. If you need clarification about something please ask.


Источник: https://stackoverflow.com/questions/780 ... generators
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Как работает этот код Python о генераторах?
    Anonymous » » в форуме Python
    0 Ответы
    7 Просмотры
    Последнее сообщение Anonymous
  • Как работает этот код Python о генераторах?
    Anonymous » » в форуме Python
    0 Ответы
    10 Просмотры
    Последнее сообщение Anonymous
  • Какова цель функции «отправить» на генераторах Python?
    Anonymous » » в форуме Python
    0 Ответы
    2 Просмотры
    Последнее сообщение Anonymous
  • Псевдорамнотом и столкновение UUID: насколько вероятны столкновения в реальных генераторах UUID (JVM)?
    Anonymous » » в форуме JAVA
    0 Ответы
    2 Просмотры
    Последнее сообщение Anonymous
  • Как указать конкретный DBContext для генерации кода в инструментах генерации страниц ABP Suite?
    Anonymous » » в форуме C#
    0 Ответы
    16 Просмотры
    Последнее сообщение Anonymous

Вернуться в «C#»