Implementing traits in C# using Roslyn Source Generators
Article Sidebar
Open full text
Issue Vol. 15 No. 4 (2025)
-
Control of the magnetic levitation using a PID controller with adaptation based on linear interpolation logic and genetic algorithm
Dominik Fila, Andrzej Neumann, Bartosz Olesik, Jakub Pawelec, Kamil Przybylak, Mateusz Ungier, Dawid Wajnert5-9
-
Development of a system for predicting failures of bagging machines
Nataliia Huliieva, Nataliia Lishchyna, Viktoriya Pasternak, Zemfira Huliieva10-13
-
Development and verification of a modular object-oriented fuzzy logic controller architecture for customizable and embedded applications
Rahim Mammadzada14-24
-
Mechanical fracture energy and structural-mechanical properties of meat snacks with beekeeping additives
Artem Antoniv, Igor Palamarchuk, Leonora Adamchuk, Marija Zheplinska25-31
-
Modelling of dynamic processes in a nonholonomic system in the form of Gibbs-Appell equations on the example of a ball mill
Volodymyr Shatokhin, Yaroslav Ivanchuk, Vitaly Liman, Sergii Komar, Oleksii Kozlovskyi32-38
-
Real-time Covid-19 diagnosis on embedded IoT platforms
Elmehdi Benmalek, Wajih Rhalem, Atman Jbari, Abdelilah Jilbab, Jamal Elmhamdi39-45
-
Hybrid models for handwriting-based diagnosis of Parkinson's disease
Asma Ouabd, Achraf Benba, Abdelilah Jilbab, Ahmed Hammouch46-50
-
Computer system for diagnostic and treatment of unilateral neglect syndrome
Krzysztof Strzecha, Agata Bukalska-Strzecha, Krzysztof Kurzdym, Dominik Sankowski51-55
-
Informatics and measurement in healthcare: deep learning for diabetic patient readmission prediction
Shiva Saffari, Mahdi Bahaghighat56-64
-
Optimization of non-invasive glucose monitoring accuracy using an optical sensor
Nurzhigit Smailov, Aliya Zilgarayeva, Sergii Pavlov, Balzhan Turusbekova, Akezhan Sabibolda65-70
-
Stochastic multi-objective minimax optimization of combined electromagnetic shield based on three-dimensional modeling of overhead power lines magnetic field
Borys Kuznetsov, Tatyana Nikitina, Alexander Kutsenko, Ihor Bovdui, Kostiantyn Czunikhin, Olena Voloshko, Roman Voliansky, Viktoriia Ivannikova71-75
-
Advanced energy management strategies for AC/DC microgrids
Zouhir Boumous, Samira Boumous, Tawfik Thelaidjia76-82
-
Experimental study of a multi-stage converter circuit
Kyrmyzy Taissariyeva, Kuanysh Muslimov, Yerlan Tashtay, Gulim Jobalayeva, Lyazzat Ilipbayeva, Ingkar Issakozhayeva, Akezhan Sabibolda83-86
-
Deep learning-based prediction of structural parameters in FDTD-simulated plasmonic nanostructures
Shahed Jahidul Haque, Arman Mohammad Nakib87-94
-
Development of an algorithm for calculating ion exchange processes using the Python ecosystem
Iryna Chub, Oleksii Proskurnia, Kateryna Demchenko, Oleksandr Miroshnyk, Taras Shchur, Serhii Halko95-99
-
Intelligent model for reliability control and safety in urban transport systems
Anastasiia Kashkanova, Alexander Rotshtein, Andrii Kashkanov, Denis Katelnikov100-107
-
Analysis of the interaction of components of a modular parcel storage system using UML diagrams
Lyudmila Samchuk, Yuliia Povstiana, Anastasia Hryshchuk108-116
-
Evaluating modified pairing insertion heuristics for efficient dial-a-ride problem solutions in healthcare logistics
Rodolfo Eleazar Pérez Loaiza, Aaron Guerrero-Campanur, Edmundo Bonilla Huerta117-123
-
Analysis of modern tools, methods of audit and monitoring of database security
Kateryna Mykhailyshyn, Oleh Harasymchuk, Oleh Deineka, Yurii Dreis, Volodymyr Shulha, Yuriy Pepa124-129
-
Improving underwater visuals by fusion of Deep-Retinex and GAN for enhanced image quality in subaquatic environments
Anuradha Chinta, Bharath Kumar Surla, Chaitanya Kodali130-136
-
The mathematical method for assessing the cybersecurity state of cloud services
Yevheniia Ivanchenko, Volodymyr Shulha, Ihor Ivanchenko, Yevhenii Pedchenko, Mari Petrovska137-141
-
Evaluation of the performance of LLMs deployments in selected cloud-based container services
Mateusz Stęgierski, Piotr Szpak, Sławomir Przyłucki142-150
-
Implementing traits in C# using Roslyn Source Generators
Mykhailo Pozur, Viktoria Voitko, Svitlana Bevz, Serhii Burbelo, Olena Kosaruk151-157
-
Impact of customizable orchestrator scheduling on machine learning efficiency in edge environments
Konrad Cłapa, Krzysztof Grudzień, Artur Sierszeń158-163
-
Reconfigured CoARX architecture for implementing ARX hashing in microcontrollers of IoT systems with limited resources
Serhii Zabolotnii, Inna Rozlomii, Andrii Yarmilko, Serhii Naumenko164-169
-
Integral assessment of the spring water quality with the use of fuzzy logic toolkit
Vyacheslav Repeta, Oleksandra Krykhovets, Yurii Kukura170-176
-
Selected issues concerning fibre-optic bending sensors
Les Hotra, Jacek Klimek, Ihor Helzhynskyy, Oksana Boyko, Svitlana Kovtun177-181
Archives
-
Vol. 15 No. 4
2025-12-20 27
-
Vol. 15 No. 3
2025-09-30 24
-
Vol. 15 No. 2
2025-06-27 24
-
Vol. 15 No. 1
2025-03-31 26
-
Vol. 14 No. 4
2024-12-21 25
-
Vol. 14 No. 3
2024-09-30 24
-
Vol. 14 No. 2
2024-06-30 24
-
Vol. 14 No. 1
2024-03-31 23
-
Vol. 13 No. 4
2023-12-20 24
-
Vol. 13 No. 3
2023-09-30 25
-
Vol. 13 No. 2
2023-06-30 14
-
Vol. 13 No. 1
2023-03-31 12
-
Vol. 12 No. 4
2022-12-30 16
-
Vol. 12 No. 3
2022-09-30 15
-
Vol. 12 No. 2
2022-06-30 16
-
Vol. 12 No. 1
2022-03-31 9
-
Vol. 11 No. 4
2021-12-20 15
-
Vol. 11 No. 3
2021-09-30 10
-
Vol. 11 No. 2
2021-06-30 11
-
Vol. 11 No. 1
2021-03-31 14
Main Article Content
DOI
Authors
Abstract
The paper presents an approach to implementing traits functionality in the C# programming language through the use of Roslyn Source Generators, a compile-time metaprogramming tool introduced in .NET5. Traits, which are composable units of fine-grained reuse, can benefit the C# language by bringing a mechanism for behavior reuse in the context of single inheritance. The article describes the design and implementation of a source generator that allows to annotate classes with metadata attributes, automatically injecting the corresponding member definitions at compile time. To achieve better code generation performance at design time, Incremental Source Generators were used. The composition of trait members is described in detail, focusing on name conflict resolution and type safety by utilizing interfaces and the override mechanism. Defining non-public members in a context of a trait is also discussed and implemented, thus allowing for better code reusability. The article concludes that language-level features such as traits can be implemented in the C# language by using Roslyn Source Generators, thus demonstrating the potential of such an instrument and metaprogramming in general.
Keywords:
References
[1] Albalooshi F., Mahmood A.: A Comparative Study on the Effect of Multiple Inheritance Mechanism in Java, C++, and Python on Complexity and Reusability of Code. Int. J. Adv. Comput. Sci. Appl. 8(6), 2017, 109–116 [https://doi.org/10.14569/ijacsa.2017.080614].
[2] Arora H., Servetto M., Oliveira B. C. D. S.: Separating Use and Reuse to Improve Both. The Art, Science, and Engineering of Programming 3(3), 2019 [https://doi.org/10.22152/programming-journal.org/2019/3/12].
[3] AutoInterface, 2025 [https://github.com/beakona/AutoInterface].
[4] Bergel A. et al.: Stateful Traits. De Meuter W. (eds): Advances in Smalltalk. ISC 2006. Lecture Notes in Computer Science 4406. Springer, Berlin, Heidelberg 2007 [https://doi.org/10.1007/978-3-540-71836-9_4]
[5] Black A. P., Schärli N., Ducasse S.: Applying Traits to the Smalltalk Collection Classes. ACM SIGPLAN Not. 38(11), 2003, 47–64 [https://doi.org/10.1145/949343.949311].
[6] Cassou D., Ducasse S., Wuyts R.: Traits at work: The design of a new trait-based stream library. Comput. Lang., Syst. & Struct. 35(1), 2009, 2–20 [https://doi.org/10.1016/j.cl.2008.05.004].
[7] Ducasse S. et al.: Traits: A mechanism for fine-grained reuse. ACM Trans. Program. Lang. Syst. 28(2), 2006, 331–388 [https://doi.org/10.1145/1119479.1119483]
[8] Ducournau R., Morandat F., Privat J.: Empirical assessment of object-oriented implementations with multiple inheritance and static typing. ACM SIGPLAN Not. 44(10), 2009, 41–60 [https://doi.org/10.1145/1639949.1640093].
[9] Explicit Interface Implementation – C#, 2022 [https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/interfaces/explicit-interface-implementation].
[10] Gerr P.: Incremental Roslyn Source Generators In .NET 6: Code Sharing Of The Future – Part 1. 2022 [https://www.thinktecture.com/net/roslyn-source-generators-introduction/].
[11] Hossain M.: Understanding Traits in PHP: A Guide with Examples, 2024 [https://mohasin-dev.medium.com/understanding-traits-in-php-a-guide-with-examples-84f14f1b7b43].
[12] Immutype, 2025 [https://github.com/DevTeam/Immutype].
[13] Introducing C# Source Generators, 2025 [https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/].
[14] Lock A.: Understanding C# 8 default interface methods. 2024 [https://andrewlock.net/understanding-default-interface-methods/].
[15] Mr Prime: Mixins in Ruby, 2024 [https://medium.com/@primedruk312/mixins-in-ruby-09e58b226e50].
[16] Muniyandi V.: Harnessing Roslyn for Advanced Code Analysis and Optimization in Cloud- Based .NET Applications on Microsoft Azure. Int. J. Commun. Netw. Secur. 14(3), 2022, 979–990 [https://ijcnis.org/index.php/ijcnis/article/view/8051/2231].
[17] Nichols C., Klabnik S.: Rust Programming Language, 2nd Edition. No Starch Press, Incorporated, 2023.
[18] Partial Classes and Members – C#, 2025 [https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/partial-classes-and-methods].
[19] Schärli N. et al.: Traits: Composable Units of Behaviour. In: ECOOP 2003 – Object-Oriented Programming. Springer Berlin Heidelberg, 2003, 248–274 [https://doi.org/10.1007/978-3-540-45070-2_12].
[20] Steyaert P. et al.: Nested Mixin-Methods in Agora. Nierstrasz O. M. (eds): ECOOP’ 93 — Object-Oriented Programming. Springer Berlin Heidelberg, 1993 [https://doi.org/10.1007/3-540-47910-4_12].
[21] StrongInject, 2025 [https://github.com/YairHalberstadt/stronginject].
[22] Tesone P. et al.: A new modular implementation for stateful traits. Sci. Comput. Program. 195, 2020, 102470 [https://doi.org/10.1016/j.scico.2020.102470].
[23] Traits: Defining Shared Behavior, 2025 [https://doc.rust-lang.org/book/ch10-02-traits.html].
[24] Wampler D., Payne A.: Programming Scala. O'Reilly Media, Incorporated, 2014.
[25] Yaqoob E.: Mixins in dart, 2023 [https://medium.com/@emanyaqoob/mixins-in-dart-aed7e89de15d].
Article Details
Abstract views: 1

