├── .editorconfig
├── .gitattributes
├── .gitignore
├── Directory.Build.props
├── Directory.Build.targets
├── LICENSE
├── README.md
├── VariadicGenerics.sln
├── samples
├── Directory.Build.props
├── Directory.Build.targets
└── GenericMethods
│ ├── GenericMethods.csproj
│ └── Program.cs
└── src
├── VariadicGenerator.cs
└── VariadicGenerics.SourceGenerator.csproj
/.editorconfig:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # EditorConfig is awesome: http://EditorConfig.org
3 | ###############################################################################
4 |
5 | ###############################################################################
6 | # Top-most EditorConfig file
7 | ###############################################################################
8 | root = true
9 |
10 | ###############################################################################
11 | # Set default behavior to:
12 | # a UTF-8 encoding,
13 | # Unix-style line endings,
14 | # a newline ending the file,
15 | # 4 space indentation, and
16 | # trimming of trailing whitespace
17 | ###############################################################################
18 | [*]
19 | charset = utf-8
20 | end_of_line = lf
21 | insert_final_newline = true
22 | indent_style = space
23 | indent_size = 4
24 | trim_trailing_whitespace = true
25 |
26 | ###############################################################################
27 | # Set file behavior to:
28 | # 2 space indentation
29 | ###############################################################################
30 | [*.{cmd,config,csproj,cxxproj,json,nuspec,props,ps1,resx,sh,targets,yml}]
31 | indent_size = 2
32 |
33 | ###############################################################################
34 | # Set file behavior to:
35 | # Windows-style line endings, and
36 | # tabular indentation
37 | ###############################################################################
38 | [*.sln]
39 | end_of_line = crlf
40 | indent_style = tab
41 |
42 | ###############################################################################
43 | # Set dotnet naming rules to:
44 | # suggest async members be pascal case suffixed with Async
45 | # suggest const declarations be pascal case
46 | # suggest interfaces be pascal case prefixed with I
47 | # suggest parameters be camel case
48 | # suggest private and internal static fields be pascal case
49 | # suggest private and internal fields be camel case and prefixed with underscore
50 | # suggest public and protected declarations be pascal case
51 | # suggest static readonly declarations be pascal case
52 | # suggest type parameters be prefixed with T
53 | ###############################################################################
54 | [*.cs]
55 | dotnet_naming_rule.async_members_should_be_pascal_case_suffixed_with_async.severity = suggestion
56 | dotnet_naming_rule.async_members_should_be_pascal_case_suffixed_with_async.style = pascal_case_suffixed_with_async
57 | dotnet_naming_rule.async_members_should_be_pascal_case_suffixed_with_async.symbols = async_members
58 |
59 | dotnet_naming_rule.const_declarations_should_be_pascal_case.severity = suggestion
60 | dotnet_naming_rule.const_declarations_should_be_pascal_case.style = pascal_case
61 | dotnet_naming_rule.const_declarations_should_be_pascal_case.symbols = const_declarations
62 |
63 | dotnet_naming_rule.interfaces_should_be_pascal_case_prefixed_with_i.severity = suggestion
64 | dotnet_naming_rule.interfaces_should_be_pascal_case_prefixed_with_i.style = pascal_case_prefixed_with_i
65 | dotnet_naming_rule.interfaces_should_be_pascal_case_prefixed_with_i.symbols = interfaces
66 |
67 | dotnet_naming_rule.parameters_should_be_camel_case.severity = suggestion
68 | dotnet_naming_rule.parameters_should_be_camel_case.style = camel_case
69 | dotnet_naming_rule.parameters_should_be_camel_case.symbols = parameters
70 |
71 | dotnet_naming_rule.private_and_internal_static_fields_should_be_pascal_case.severity = suggestion
72 | dotnet_naming_rule.private_and_internal_static_fields_should_be_pascal_case.style = pascal_case
73 | dotnet_naming_rule.private_and_internal_static_fields_should_be_pascal_case.symbols = private_and_internal_static_fields
74 |
75 | dotnet_naming_rule.private_and_internal_fields_should_be_camel_case_prefixed_with_underscore.severity = suggestion
76 | dotnet_naming_rule.private_and_internal_fields_should_be_camel_case_prefixed_with_underscore.style = camel_case_prefixed_with_underscore
77 | dotnet_naming_rule.private_and_internal_fields_should_be_camel_case_prefixed_with_underscore.symbols = private_and_internal_fields
78 |
79 | dotnet_naming_rule.public_and_protected_declarations_should_be_pascal_case.severity = suggestion
80 | dotnet_naming_rule.public_and_protected_declarations_should_be_pascal_case.style = pascal_case
81 | dotnet_naming_rule.public_and_protected_declarations_should_be_pascal_case.symbols = public_and_protected_declarations
82 |
83 | dotnet_naming_rule.static_readonly_declarations_should_be_pascal_case.severity = suggestion
84 | dotnet_naming_rule.static_readonly_declarations_should_be_pascal_case.style = pascal_case
85 | dotnet_naming_rule.static_readonly_declarations_should_be_pascal_case.symbols = static_readonly_declarations
86 |
87 | dotnet_naming_rule.type_parameters_should_be_pascal_case_prefixed_with_t.severity = suggestion
88 | dotnet_naming_rule.type_parameters_should_be_pascal_case_prefixed_with_t.style = pascal_case_prefixed_with_t
89 | dotnet_naming_rule.type_parameters_should_be_pascal_case_prefixed_with_t.symbols = type_parameters
90 |
91 | ###############################################################################
92 | # Set dotnet naming styles to define:
93 | # camel case
94 | # camel case prefixed with _
95 | # camel case prefixed with s_
96 | # pascal case
97 | # pascal case suffixed with Async
98 | # pascal case prefixed with I
99 | # pascal case prefixed with T
100 | ###############################################################################
101 | [*.cs]
102 | dotnet_naming_style.camel_case.capitalization = camel_case
103 |
104 | dotnet_naming_style.camel_case_prefixed_with_underscore.capitalization = camel_case
105 | dotnet_naming_style.camel_case_prefixed_with_underscore.required_prefix = _
106 |
107 | dotnet_naming_style.pascal_case.capitalization = pascal_case
108 |
109 | dotnet_naming_style.pascal_case_suffixed_with_async.capitalization = pascal_case
110 | dotnet_naming_style.pascal_case_suffixed_with_async.required_suffix = Async
111 |
112 | dotnet_naming_style.pascal_case_prefixed_with_i.capitalization = pascal_case
113 | dotnet_naming_style.pascal_case_prefixed_with_i.required_prefix = I
114 |
115 | dotnet_naming_style.pascal_case_prefixed_with_t.capitalization = pascal_case
116 | dotnet_naming_style.pascal_case_prefixed_with_t.required_prefix = T
117 |
118 | ###############################################################################
119 | # Set dotnet naming symbols to:
120 | # async members
121 | # const declarations
122 | # interfaces
123 | # private and internal fields
124 | # private and internal static fields
125 | # public and protected declarations
126 | # static readonly declarations
127 | # type parameters
128 | ###############################################################################
129 | [*.cs]
130 | dotnet_naming_symbols.async_members.required_modifiers = async
131 |
132 | dotnet_naming_symbols.const_declarations.required_modifiers = const
133 |
134 | dotnet_naming_symbols.interfaces.applicable_kinds = interface
135 |
136 | dotnet_naming_symbols.parameters.applicable_kinds = parameter
137 |
138 | dotnet_naming_symbols.private_and_internal_fields.applicable_accessibilities = private, internal
139 | dotnet_naming_symbols.private_and_internal_fields.applicable_kinds = field
140 |
141 | dotnet_naming_symbols.private_and_internal_static_fields.applicable_accessibilities = private, internal
142 | dotnet_naming_symbols.private_and_internal_static_fields.applicable_kinds = field
143 | dotnet_naming_symbols.private_and_internal_static_fields.required_modifiers = static
144 |
145 | dotnet_naming_symbols.public_and_protected_declarations.applicable_accessibilities = public, protected
146 | dotnet_naming_symbols.public_and_protected_declarations.applicable_kinds = namespace, class, struct, enum, property, method, field, event, delegate, local_function
147 |
148 | dotnet_naming_symbols.static_readonly_declarations.required_modifiers = static, readonly
149 |
150 | dotnet_naming_symbols.type_parameters.applicable_kinds = type_parameter
151 |
152 | ###############################################################################
153 | # Set dotnet sort options to:
154 | # do not separate import directives into groups, and
155 | # sort system directives first
156 | ###############################################################################
157 | [*.cs]
158 | dotnet_separate_import_directive_groups = false
159 | dotnet_sort_system_directives_first = true
160 |
161 | ###############################################################################
162 | # Set dotnet style options to:
163 | # suggest null-coalescing expressions,
164 | # suggest collection-initializers,
165 | # suggest explicit tuple names,
166 | # suggest null-propogation
167 | # suggest object-initializers,
168 | # suggest parentheses in arithmetic binary operators for clarity,
169 | # suggest parentheses in other binary operators for clarity,
170 | # don't suggest parentheses in other operators if unnecessary,
171 | # suggest parentheses in relational binary operators for clarity,
172 | # suggest predefined-types for locals, parameters, and members,
173 | # suggest predefined-types of type names for member access,
174 | # don't suggest auto properties,
175 | # suggest compound assignment,
176 | # suggest conditional expression over assignment,
177 | # suggest conditional expression over return,
178 | # suggest inferred anonymous types,
179 | # suggest inferred tuple names,
180 | # suggest 'is null' checks over '== null',
181 | # don't suggest 'this.' and 'Me.' for events,
182 | # don't suggest 'this.' and 'Me.' for fields,
183 | # don't suggest 'this.' and 'Me.' for methods,
184 | # don't suggest 'this.' and 'Me.' for properties,
185 | # suggest readonly fields, and
186 | # suggest specifying accessibility modifiers
187 | ###############################################################################
188 | [*.cs]
189 | dotnet_style_coalesce_expression = true:suggestion
190 | dotnet_style_collection_initializer = true:suggestion
191 | dotnet_style_explicit_tuple_names = true:suggestion
192 | dotnet_style_null_propagation = true:suggestion
193 | dotnet_style_object_initializer = true:suggestion
194 |
195 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion
196 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
197 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
198 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion
199 |
200 | dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
201 | dotnet_style_predefined_type_for_member_access = true:suggestion
202 |
203 | dotnet_style_prefer_auto_properties = false:suggestion
204 | dotnet_style_prefer_compound_assignment = true:suggestion
205 | dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
206 | dotnet_style_prefer_conditional_expression_over_return = true:suggestion
207 | dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
208 | dotnet_style_prefer_inferred_tuple_names = true:suggestion
209 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
210 |
211 | dotnet_style_qualification_for_event = false:suggestion
212 | dotnet_style_qualification_for_field = false:suggestion
213 | dotnet_style_qualification_for_method = false:suggestion
214 | dotnet_style_qualification_for_property = false:suggestion
215 |
216 | dotnet_style_readonly_field = true:suggestion
217 | dotnet_style_require_accessibility_modifiers = always:suggestion
218 |
219 | ###############################################################################
220 | # Set dotnet style options to:
221 | # suggest removing all unused parameters
222 | ###############################################################################
223 | [*.cs]
224 | dotnet_code_quality_unused_parameters = all:suggestion
225 |
226 | ###############################################################################
227 | # Set csharp indent options to:
228 | # indent block contents,
229 | # not indent braces,
230 | # indent case contents,
231 | # not indent case contents when block,
232 | # indent labels one less than the current, and
233 | # indent switch labels
234 | ###############################################################################
235 | [*.cs]
236 | csharp_indent_block_contents = true
237 | csharp_indent_braces = false
238 | csharp_indent_case_contents = true
239 | csharp_indent_case_contents_when_block = false
240 | csharp_indent_labels = one_less_than_current
241 | csharp_indent_switch_labels = true
242 |
243 | ###############################################################################
244 | # Set csharp new-line options to:
245 | # insert a new-line before "catch",
246 | # insert a new-line before "else",
247 | # insert a new-line before "finally",
248 | # insert a new-line before members in anonymous-types,
249 | # insert a new-line before members in object-initializers,
250 | # insert a new-line before all open braces except anonymous methods, anonymous types, lambdas, and object collections and
251 | # insert a new-line within query expression clauses
252 | ###############################################################################
253 | [*.cs]
254 | csharp_new_line_before_catch = true
255 | csharp_new_line_before_else = true
256 | csharp_new_line_before_finally = true
257 |
258 | csharp_new_line_before_members_in_anonymous_types = true
259 | csharp_new_line_before_members_in_object_initializers = true
260 |
261 | csharp_new_line_before_open_brace = accessors, control_blocks, events, indexers, local_functions, methods, object_collection_array_initializers, properties, types
262 |
263 | csharp_new_line_within_query_expression_clauses = true
264 |
265 | ###############################################################################
266 | # Set csharp preserve options to:
267 | # preserve single-line blocks, and
268 | # not preserve single-line statements
269 | ###############################################################################
270 | [*.cs]
271 | csharp_preserve_single_line_blocks = true
272 | csharp_preserve_single_line_statements = false
273 |
274 | ###############################################################################
275 | # Set csharp space options to:
276 | # remove any space after a cast,
277 | # add a space after the colon in an inheritance clause,
278 | # add a space after a comma,
279 | # remove any space after a dot,
280 | # add a space after keywords in control flow statements,
281 | # add a space after a semicolon in a "for" statement,
282 | # add a space before and after binary operators,
283 | # remove space around declaration statements,
284 | # add a space before the colon in an inheritance clause,
285 | # remove any space before a comma,
286 | # remove any space before a dot,
287 | # remove any space before an open square-bracket,
288 | # remove any space before a semicolon in a "for" statement,
289 | # remove any space between empty square-brackets,
290 | # remove any space between a method call's empty parameter list parenthesis,
291 | # remove any space between a method call's name and its opening parenthesis,
292 | # remove any space between a method call's parameter list parenthesis,
293 | # remove any space between a method declaration's empty parameter list parenthesis,
294 | # remove any space between a method declaration's name and its openening parenthesis,
295 | # remove any space between a method declaration's parameter list parenthesis,
296 | # remove any space between parentheses, and
297 | # remove any space between square brackets
298 | ###############################################################################
299 | [*.cs]
300 | csharp_space_after_cast = false
301 | csharp_space_after_colon_in_inheritance_clause = true
302 | csharp_space_after_comma = true
303 | csharp_space_after_dot = false
304 | csharp_space_after_keywords_in_control_flow_statements = true
305 | csharp_space_after_semicolon_in_for_statement = true
306 |
307 | csharp_space_around_binary_operators = before_and_after
308 | csharp_space_around_declaration_statements = do_not_ignore
309 |
310 | csharp_space_before_colon_in_inheritance_clause = true
311 | csharp_space_before_comma = false
312 | csharp_space_before_dot = false
313 | csharp_space_before_open_square_brackets = false
314 | csharp_space_before_semicolon_in_for_statement = false
315 |
316 | csharp_space_between_empty_square_brackets = false
317 | csharp_space_between_method_call_empty_parameter_list_parentheses = false
318 | csharp_space_between_method_call_name_and_opening_parenthesis = false
319 | csharp_space_between_method_call_parameter_list_parentheses = false
320 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
321 | csharp_space_between_method_declaration_name_and_open_parenthesis = false
322 | csharp_space_between_method_declaration_parameter_list_parentheses = false
323 | csharp_space_between_parentheses = false
324 | csharp_space_between_square_brackets = false
325 |
326 | ###############################################################################
327 | # Set csharp style options to:
328 | # don't suggest braces,
329 | # suggest simple default expressions,
330 | # suggest a preferred modifier order,
331 | # suggest conditional delegate calls,
332 | # suggest deconstructed variable declarations,
333 | # don't suggest expression-bodied accessors,
334 | # don't suggest expression-bodied indexers,
335 | # don't suggest expression-bodied constructors,
336 | # suggest expression-bodied lambdas,
337 | # don't suggest expression-bodied methods,
338 | # don't suggest expression-bodied operators,
339 | # don't suggest expression-bodied properties,
340 | # suggest inlined variable declarations,
341 | # suggest local over anonymous functions,
342 | # suggest pattern-matching over "as" with "null" check,
343 | # suggest pattern-matching over "is" with "cast" check,
344 | # suggest throw expressions,
345 | # suggest a discard variable for unused value expression statements,
346 | # suggest a discard variable for unused assignments,
347 | # suggest var for built-in types,
348 | # suggest var when the type is not apparent, and
349 | # suggest var when the type is apparent
350 | ###############################################################################
351 | [*.cs]
352 | csharp_prefer_braces = false:suggestion
353 | csharp_prefer_simple_default_expression = true:suggestion
354 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
355 |
356 | csharp_style_conditional_delegate_call = true:suggestion
357 | csharp_style_deconstructed_variable_declaration = true:suggestion
358 |
359 | csharp_style_expression_bodied_accessors = when_on_single_line:suggestion
360 | csharp_style_expression_bodied_constructors = false:suggestion
361 | csharp_style_expression_bodied_indexers = when_on_single_line:suggestion
362 | csharp_style_expression_bodied_lambdas = true:suggestion
363 | csharp_style_expression_bodied_methods = when_on_single_line:suggestion
364 | csharp_style_expression_bodied_operators = when_on_single_line:suggestion
365 | csharp_style_expression_bodied_properties = when_on_single_line:suggestion
366 |
367 | csharp_style_inlined_variable_declaration = true:suggestion
368 |
369 | csharp_style_pattern_local_over_anonymous_function = true:suggestion
370 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
371 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
372 |
373 | csharp_style_throw_expression = true:suggestion
374 |
375 | csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion
376 | csharp_style_unused_value_assignment_preference = discard_variable:suggestion
377 |
378 | csharp_style_var_for_built_in_types = true:none
379 | csharp_style_var_elsewhere = true:suggestion
380 | csharp_style_var_when_type_is_apparent = true:suggestion
381 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Default to Unix-style text files
3 | ###############################################################################
4 | * text eol=lf
5 |
6 | ###############################################################################
7 | # Treat code and markdown as Unix-style text files
8 | ###############################################################################
9 | *.cs text eol=lf
10 | *.csproj text eol=lf
11 | *.md text eol=lf
12 | *.props text eol=lf
13 | *.targets text eol=lf
14 |
15 | ###############################################################################
16 | # Treat Solution files as Windows text files
17 | ###############################################################################
18 | *.sln text eol=crlf
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Aa][Rr][Mm]/
27 | [Aa][Rr][Mm]64/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 |
33 | # Visual Studio 2015/2017 cache/options directory
34 | .vs/
35 | # Uncomment if you have tasks that create the project's static files in wwwroot
36 | #wwwroot/
37 |
38 | # Visual Studio 2017 auto generated files
39 | Generated\ Files/
40 |
41 | # MSTest test Results
42 | [Tt]est[Rr]esult*/
43 | [Bb]uild[Ll]og.*
44 |
45 | # NUNIT
46 | *.VisualState.xml
47 | TestResult.xml
48 |
49 | # Build Results of an ATL Project
50 | [Dd]ebugPS/
51 | [Rr]eleasePS/
52 | dlldata.c
53 |
54 | # Benchmark Results
55 | BenchmarkDotNet.Artifacts/
56 |
57 | # .NET Core
58 | project.lock.json
59 | project.fragment.lock.json
60 | artifacts/
61 |
62 | # StyleCop
63 | StyleCopReport.xml
64 |
65 | # Files built by Visual Studio
66 | *_i.c
67 | *_p.c
68 | *_h.h
69 | *.ilk
70 | *.meta
71 | *.obj
72 | *.iobj
73 | *.pch
74 | *.pdb
75 | *.ipdb
76 | *.pgc
77 | *.pgd
78 | *.rsp
79 | *.sbr
80 | *.tlb
81 | *.tli
82 | *.tlh
83 | *.tmp
84 | *.tmp_proj
85 | *_wpftmp.csproj
86 | *.log
87 | *.vspscc
88 | *.vssscc
89 | .builds
90 | *.pidb
91 | *.svclog
92 | *.scc
93 |
94 | # Chutzpah Test files
95 | _Chutzpah*
96 |
97 | # Visual C++ cache files
98 | ipch/
99 | *.aps
100 | *.ncb
101 | *.opendb
102 | *.opensdf
103 | *.sdf
104 | *.cachefile
105 | *.VC.db
106 | *.VC.VC.opendb
107 |
108 | # Visual Studio profiler
109 | *.psess
110 | *.vsp
111 | *.vspx
112 | *.sap
113 |
114 | # Visual Studio Trace Files
115 | *.e2e
116 |
117 | # TFS 2012 Local Workspace
118 | $tf/
119 |
120 | # Guidance Automation Toolkit
121 | *.gpState
122 |
123 | # ReSharper is a .NET coding add-in
124 | _ReSharper*/
125 | *.[Rr]e[Ss]harper
126 | *.DotSettings.user
127 |
128 | # JustCode is a .NET coding add-in
129 | .JustCode
130 |
131 | # TeamCity is a build add-in
132 | _TeamCity*
133 |
134 | # DotCover is a Code Coverage Tool
135 | *.dotCover
136 |
137 | # AxoCover is a Code Coverage Tool
138 | .axoCover/*
139 | !.axoCover/settings.json
140 |
141 | # Visual Studio code coverage results
142 | *.coverage
143 | *.coveragexml
144 |
145 | # NCrunch
146 | _NCrunch_*
147 | .*crunch*.local.xml
148 | nCrunchTemp_*
149 |
150 | # MightyMoose
151 | *.mm.*
152 | AutoTest.Net/
153 |
154 | # Web workbench (sass)
155 | .sass-cache/
156 |
157 | # Installshield output folder
158 | [Ee]xpress/
159 |
160 | # DocProject is a documentation generator add-in
161 | DocProject/buildhelp/
162 | DocProject/Help/*.HxT
163 | DocProject/Help/*.HxC
164 | DocProject/Help/*.hhc
165 | DocProject/Help/*.hhk
166 | DocProject/Help/*.hhp
167 | DocProject/Help/Html2
168 | DocProject/Help/html
169 |
170 | # Click-Once directory
171 | publish/
172 |
173 | # Publish Web Output
174 | *.[Pp]ublish.xml
175 | *.azurePubxml
176 | # Note: Comment the next line if you want to checkin your web deploy settings,
177 | # but database connection strings (with potential passwords) will be unencrypted
178 | *.pubxml
179 | *.publishproj
180 |
181 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
182 | # checkin your Azure Web App publish settings, but sensitive information contained
183 | # in these scripts will be unencrypted
184 | PublishScripts/
185 |
186 | # NuGet Packages
187 | *.nupkg
188 | # The packages folder can be ignored because of Package Restore
189 | **/[Pp]ackages/*
190 | # except build/, which is used as an MSBuild target.
191 | !**/[Pp]ackages/build/
192 | # Uncomment if necessary however generally it will be regenerated when needed
193 | #!**/[Pp]ackages/repositories.config
194 | # NuGet v3's project.json files produces more ignorable files
195 | *.nuget.props
196 | *.nuget.targets
197 |
198 | # Microsoft Azure Build Output
199 | csx/
200 | *.build.csdef
201 |
202 | # Microsoft Azure Emulator
203 | ecf/
204 | rcf/
205 |
206 | # Windows Store app package directories and files
207 | AppPackages/
208 | BundleArtifacts/
209 | Package.StoreAssociation.xml
210 | _pkginfo.txt
211 | *.appx
212 | *.appxbundle
213 | *.appxupload
214 |
215 | # Visual Studio cache files
216 | # files ending in .cache can be ignored
217 | *.[Cc]ache
218 | # but keep track of directories ending in .cache
219 | !?*.[Cc]ache/
220 |
221 | # Others
222 | ClientBin/
223 | ~$*
224 | *~
225 | *.dbmdl
226 | *.dbproj.schemaview
227 | *.jfm
228 | *.pfx
229 | *.publishsettings
230 | orleans.codegen.cs
231 |
232 | # Including strong name files can present a security risk
233 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
234 | #*.snk
235 |
236 | # Since there are multiple workflows, uncomment next line to ignore bower_components
237 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
238 | #bower_components/
239 |
240 | # RIA/Silverlight projects
241 | Generated_Code/
242 |
243 | # Backup & report files from converting an old project file
244 | # to a newer Visual Studio version. Backup files are not needed,
245 | # because we have git ;-)
246 | _UpgradeReport_Files/
247 | Backup*/
248 | UpgradeLog*.XML
249 | UpgradeLog*.htm
250 | ServiceFabricBackup/
251 | *.rptproj.bak
252 |
253 | # SQL Server files
254 | *.mdf
255 | *.ldf
256 | *.ndf
257 |
258 | # Business Intelligence projects
259 | *.rdl.data
260 | *.bim.layout
261 | *.bim_*.settings
262 | *.rptproj.rsuser
263 | *- Backup*.rdl
264 |
265 | # Microsoft Fakes
266 | FakesAssemblies/
267 |
268 | # GhostDoc plugin setting file
269 | *.GhostDoc.xml
270 |
271 | # Node.js Tools for Visual Studio
272 | .ntvs_analysis.dat
273 | node_modules/
274 |
275 | # Visual Studio 6 build log
276 | *.plg
277 |
278 | # Visual Studio 6 workspace options file
279 | *.opt
280 |
281 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
282 | *.vbw
283 |
284 | # Visual Studio LightSwitch build output
285 | **/*.HTMLClient/GeneratedArtifacts
286 | **/*.DesktopClient/GeneratedArtifacts
287 | **/*.DesktopClient/ModelManifest.xml
288 | **/*.Server/GeneratedArtifacts
289 | **/*.Server/ModelManifest.xml
290 | _Pvt_Extensions
291 |
292 | # Paket dependency manager
293 | .paket/paket.exe
294 | paket-files/
295 |
296 | # FAKE - F# Make
297 | .fake/
298 |
299 | # CodeRush personal settings
300 | .cr/personal
301 |
302 | # Python Tools for Visual Studio (PTVS)
303 | __pycache__/
304 | *.pyc
305 |
306 | # Cake - Uncomment if you are using it
307 | # tools/**
308 | # !tools/packages.config
309 |
310 | # Tabs Studio
311 | *.tss
312 |
313 | # Telerik's JustMock configuration file
314 | *.jmconfig
315 |
316 | # BizTalk build output
317 | *.btp.cs
318 | *.btm.cs
319 | *.odx.cs
320 | *.xsd.cs
321 |
322 | # OpenCover UI analysis results
323 | OpenCover/
324 |
325 | # Azure Stream Analytics local run output
326 | ASALocalRun/
327 |
328 | # MSBuild Binary and Structured Log
329 | *.binlog
330 |
331 | # NVidia Nsight GPU debugger configuration file
332 | *.nvuser
333 |
334 | # MFractors (Xamarin productivity tool) working folder
335 | .mfractor/
336 |
337 | # Local History for Visual Studio
338 | .localhistory/
339 |
340 | # BeatPulse healthcheck temp database
341 | healthchecksdb
342 |
343 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
344 | MigrationBackup/
345 |
346 | ##
347 | ## Visual studio for Mac
348 | ##
349 |
350 |
351 | # globs
352 | Makefile.in
353 | *.userprefs
354 | *.usertasks
355 | config.make
356 | config.status
357 | aclocal.m4
358 | install-sh
359 | autom4te.cache/
360 | *.tar.gz
361 | tarballs/
362 | test-results/
363 |
364 | # Mac bundle stuff
365 | *.dmg
366 | *.app
367 |
368 | # content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
369 | # General
370 | .DS_Store
371 | .AppleDouble
372 | .LSOverride
373 |
374 | # Icon must end with two \r
375 | Icon
376 |
377 |
378 | # Thumbnails
379 | ._*
380 |
381 | # Files that might appear in the root of a volume
382 | .DocumentRevisions-V100
383 | .fseventsd
384 | .Spotlight-V100
385 | .TemporaryItems
386 | .Trashes
387 | .VolumeIcon.icns
388 | .com.apple.timemachine.donotpresent
389 |
390 | # Directories potentially created on remote AFP share
391 | .AppleDB
392 | .AppleDesktop
393 | Network Trash Folder
394 | Temporary Items
395 | .apdisk
396 |
397 | # content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
398 | # Windows thumbnail cache files
399 | Thumbs.db
400 | ehthumbs.db
401 | ehthumbs_vista.db
402 |
403 | # Dump file
404 | *.stackdump
405 |
406 | # Folder config file
407 | [Dd]esktop.ini
408 |
409 | # Recycle Bin used on file shares
410 | $RECYCLE.BIN/
411 |
412 | # Windows Installer files
413 | *.cab
414 | *.msi
415 | *.msix
416 | *.msm
417 | *.msp
418 |
419 | # Windows shortcuts
420 | *.lnk
421 |
422 | # JetBrains Rider
423 | .idea/
424 | *.sln.iml
425 |
426 | ##
427 | ## Visual Studio Code
428 | ##
429 | .vscode/*
430 | !.vscode/settings.json
431 | !.vscode/tasks.json
432 | !.vscode/launch.json
433 | !.vscode/extensions.json
434 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
14 |
15 |
16 |
17 | $([System.String]::Copy('$(GITHUB_REF)').Replace('refs/pull/', '').Replace('/merge', ''))
18 |
19 |
20 |
21 |
22 | $(MSBuildThisFileDirectory)artifacts/
23 | $(FiniteCommandsProjectCategory)/$(MSBuildProjectName)
24 | https://github.com/FiniteReality/Finite.Commands/
25 |
26 |
27 |
28 |
29 | true
30 | $(BaseArtifactsPath)obj/$(BaseArtifactsPathSuffix)/
31 | embedded
32 | false
33 | enable
34 | true
35 | true
36 | true
37 |
38 |
39 |
40 | true
41 |
42 |
43 |
44 |
45 | Monica S.
46 | $(BaseArtifactsPath)bin/$(BaseArtifactsPathSuffix)/
47 | VariadicGenerics
48 | $(BaseArtifactsPath)pkg/$(Configuration)
49 | $(BaseArtifactsPath)pkg/$(Configuration)
50 | VariadicGenerics
51 | 0.1.0
52 | alpha
53 | pr$(PullRequestNumber)
54 |
55 |
56 |
57 |
58 | Copyright © Monica S.
59 | Variadic generic parameter support for .NET based on source generators
60 | strict
61 | true
62 | true
63 | preview
64 | 4.3
65 | en-US
66 | true
67 | MIT
68 | $(RepositoryUrl)
69 | git
70 |
71 | https://api.nuget.org/v3/index.json;
72 |
73 | true
74 |
75 |
76 |
77 |
78 | true
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
14 |
15 |
16 |
17 | $(DefineConstants);$(OS)
18 | $(NoWarn);NU5105
19 | $(Version).$(GITHUB_RUN_ID)
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022+ FiniteReality
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # VariadicGenerics #
2 |
3 | A small example demonstrating one way to use C# source generators to implement
4 | variadic generics.
5 |
6 | ## License ##
7 |
8 | Copyright (C) 2022 FiniteReality under the MIT license. See the LICENSE file in
9 | the root directory of the project for more information.
--------------------------------------------------------------------------------
/VariadicGenerics.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30114.105
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VariadicGenerics.SourceGenerator", "src\VariadicGenerics.SourceGenerator.csproj", "{4718055F-7B2B-4909-8051-1D92BBA8ED34}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{E519B0FF-D919-452A-AD1D-1F86D59F2AD7}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenericMethods", "samples\GenericMethods\GenericMethods.csproj", "{272F4997-8A23-4810-98A8-3EB71884A3F5}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {4718055F-7B2B-4909-8051-1D92BBA8ED34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {4718055F-7B2B-4909-8051-1D92BBA8ED34}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {4718055F-7B2B-4909-8051-1D92BBA8ED34}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 | {4718055F-7B2B-4909-8051-1D92BBA8ED34}.Release|Any CPU.Build.0 = Release|Any CPU
25 | {272F4997-8A23-4810-98A8-3EB71884A3F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 | {272F4997-8A23-4810-98A8-3EB71884A3F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 | {272F4997-8A23-4810-98A8-3EB71884A3F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {272F4997-8A23-4810-98A8-3EB71884A3F5}.Release|Any CPU.Build.0 = Release|Any CPU
29 | EndGlobalSection
30 | GlobalSection(NestedProjects) = preSolution
31 | {272F4997-8A23-4810-98A8-3EB71884A3F5} = {E519B0FF-D919-452A-AD1D-1F86D59F2AD7}
32 | EndGlobalSection
33 | EndGlobal
34 |
--------------------------------------------------------------------------------
/samples/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
14 |
15 |
16 | true
17 | $(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\Directory.Build.props
18 | samples
19 |
20 |
21 |
22 |
23 |
24 | false
25 | false
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/samples/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
14 |
15 |
16 | $(MSBuildAllProjects);$(MSBuildThisFileDirectory)..\Directory.Build.targets
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/samples/GenericMethods/GenericMethods.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/samples/GenericMethods/Program.cs:
--------------------------------------------------------------------------------
1 | // See https://aka.ms/new-console-template for more information
2 |
3 | using VariadicGenerics;
4 | using System;
5 |
6 | Stuff stuff = new();
7 | stuff.WriteMultiple("oh", "cool");
8 |
9 | class Stuff
10 | {
11 | public void WriteMultiple<[Variadic] T>(T value)
12 | where T : class
13 | {
14 | Console.WriteLine(value);
15 | }
16 | }
17 |
18 | class VariadicAttribute : Attribute { }
--------------------------------------------------------------------------------
/src/VariadicGenerator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Microsoft.CodeAnalysis;
5 | using Microsoft.CodeAnalysis.CSharp.Syntax;
6 |
7 | namespace VariadicGenerics.SourceGenerator
8 | {
9 | [Generator]
10 | public sealed class VariadicGenerator : ISourceGenerator
11 | {
12 | public void Execute(GeneratorExecutionContext context)
13 | {
14 | var receiver = (SyntaxReceiver)context.SyntaxContextReceiver!;
15 | var variadicMethods = new List<(IMethodSymbol original, int arity)>();
16 |
17 | foreach (var list in receiver!.GetGenericArgumentLists())
18 | {
19 | var model = context.Compilation.GetSemanticModel(list.SyntaxTree);
20 | var info = model.GetSymbolInfo(list.Parent!);
21 | var symbol = info.CandidateReason == CandidateReason.WrongArity
22 | ? info.CandidateSymbols.FirstOrDefault()
23 | : info.Symbol;
24 |
25 | if (symbol is IMethodSymbol methodSymbol)
26 | {
27 | if (methodSymbol.IsGenericMethod
28 | && methodSymbol.ConstructedFrom is
29 | IMethodSymbol originalDefinition
30 | && originalDefinition.TypeParameters.SingleOrDefault() is
31 | ITypeParameterSymbol genericParameter
32 | && genericParameter.GetAttributes().SingleOrDefault(
33 | x => x?.AttributeClass?.Name == "VariadicAttribute") is
34 | {} attr)
35 | {
36 | variadicMethods.Add((originalDefinition, list.Arguments.Count));
37 | }
38 | }
39 | }
40 |
41 | foreach (var (method, arity) in variadicMethods.Distinct())
42 | {
43 | var types = string.Join(", ",
44 | Enumerable.Range(1, arity)
45 | .Select(x => $"T{x}"));
46 | var constraints = "// No constraints on original method";
47 |
48 | if (method.TypeParameters.Any(HasConstraint))
49 | {
50 | constraints = string.Join("\n ",
51 | Enumerable.Range(1, arity)
52 | .Select(
53 | x => $"where T{x} : {GetConstraints(method.TypeParameters[0])}"));
54 | }
55 |
56 | var parameters = "";
57 | if (method.IsExtensionMethod || !method.IsStatic)
58 | {
59 | parameters = string.Join(", ",
60 | Enumerable.Range(1, arity)
61 | .Select(x => $"T{x} value{x}")
62 | .Prepend(
63 | $"this {method.ReceiverType!.ToDisplayString()} target"));
64 | }
65 | else
66 | {
67 | parameters = string.Join(", ",
68 | Enumerable.Range(1, arity)
69 | .Select(x => $"T{x} value{x}"));
70 | }
71 |
72 | var invocations = "";
73 | if (method.IsExtensionMethod || !method.IsStatic)
74 | {
75 | invocations = string.Join("\n ",
76 | Enumerable.Range(1, arity)
77 | .Select(
78 | x => $"target.{method.Name}(value{x});"));
79 | }
80 | else
81 | {
82 | invocations = string.Join("\n ",
83 | Enumerable.Range(1, arity)
84 | .Select(
85 | x => $"{method.Name}(value{x});"));
86 | }
87 |
88 | context.AddSource($"VariadicMethod.{method.Name}.{arity}.cs",
89 | $@"namespace VariadicGenerics
90 | {{
91 | internal static class Extensions
92 | {{
93 | public static {method.ReturnType.ToDisplayString()} {method.Name}<{types}>({parameters})
94 | {constraints}
95 | {{
96 | {invocations}
97 | }}
98 | }}
99 | }}");
100 | }
101 | }
102 |
103 | private static string GetConstraints(ITypeParameterSymbol symbol)
104 | {
105 | return string.Join(", ", Impl(symbol));
106 |
107 | static IEnumerable Impl(ITypeParameterSymbol symbol)
108 | {
109 | if (symbol.HasConstructorConstraint)
110 | yield return "new()";
111 | if (symbol.HasNotNullConstraint)
112 | yield return "notnull";
113 | if (symbol.HasReferenceTypeConstraint)
114 | yield return "class";
115 | else if (symbol.HasValueTypeConstraint)
116 | yield return "struct";
117 | else if (symbol.HasUnmanagedTypeConstraint)
118 | yield return "unmanaged";
119 |
120 | foreach (var type in symbol.ConstraintTypes)
121 | yield return type.ToDisplayString();
122 | }
123 | }
124 |
125 | private static bool HasConstraint(ITypeParameterSymbol symbol)
126 | {
127 | return symbol.HasConstructorConstraint
128 | || symbol.HasNotNullConstraint
129 | || symbol.HasReferenceTypeConstraint
130 | || symbol.HasUnmanagedTypeConstraint
131 | || symbol.HasValueTypeConstraint
132 | || symbol.ConstraintTypes.Any()
133 | || symbol.ConstraintNullableAnnotations.Any();
134 | }
135 |
136 | public void Initialize(GeneratorInitializationContext context)
137 | {
138 | context.RegisterForSyntaxNotifications(() => new SyntaxReceiver());
139 | }
140 |
141 | private sealed class SyntaxReceiver : ISyntaxContextReceiver
142 | {
143 | private readonly List _typeArgumentLists;
144 |
145 | public SyntaxReceiver()
146 | {
147 | _typeArgumentLists = new();
148 | }
149 |
150 | public IEnumerable GetGenericArgumentLists()
151 | => _typeArgumentLists;
152 |
153 | public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
154 | {
155 | if (context.Node is TypeArgumentListSyntax typeArguments)
156 | {
157 | _typeArgumentLists.Add(typeArguments);
158 | }
159 | }
160 | }
161 | }
162 | }
--------------------------------------------------------------------------------
/src/VariadicGenerics.SourceGenerator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | enable
6 |
7 |
8 |
9 | false
10 | true
11 |
12 | $(NoWarn);RS2000;RS2001;RS2002;RS2003;RS2004;RS2005;RS2006;RS2007;RS2008
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------