What are the naming rules for CIL Classes and Methods

2537 views c#
3

And how do they differ from C#?

Is there any standard way of writing a name for a method in CIL that can not conflict with any C# method, as the CIL name is illegal in C#?

Could such a name cause issues with other .net languages such as F# or Visual Basic?

An example of a naming rule in C# is: Method2 is a legal name for a method in C#, but 2Method is an illegal method name since names cannot start with a digit, but may contain digits. What naming rules are there for CIL?

answered question

The CLR accepts almost anything. Formally the set of characters specified in Unicode TR15, annex 7, using normalization rule C. It has to, given that it must support the naming rules of any language that runs on it. Notably ab/used pretty heavily by obfuscators, they'll use non-printable characters to make it hard. So it is not the rock that you need to look under, go by what the language specifies.

2 Answers

11

To write code that can interop with any .NET Language you follow the guidelines of the Common Language Specification, and ensure that your publicly-visible types are "CLS Compliant":

To fully interact with other objects written in any language, objects must expose to callers only those features that are common to all languages. This common set of features is defined by the Common Language Specification (CLS), which is a set of rules that apply to generated assemblies. The Common Language Specification is defined in Partition I, Clauses 7 through 11 of the ECMA-335 Standard: Common Language Infrastructure.

Language Independence and Language-Independent Components

posted this
11

I suspect you actually mean CLS compliance. This is detailed here along with the naming rules. The most important thing seems to be to make sure that two identifiers differ in more than just case.

posted this

Have an answer?

JD

Please login first before posting an answer.