+ All Categories
Home > Software > "Reguli CLS" presentation @ RONUA Bucharest

"Reguli CLS" presentation @ RONUA Bucharest

Date post: 22-Jan-2018
Category:
Upload: adrian-florea
View: 80 times
Download: 1 times
Share this document with a friend
48
Reguli CLS Adrian Florea http://blogs.ugidotnet.org/adrian/
Transcript
Page 1: "Reguli CLS" presentation @ RONUA Bucharest

Reguli CLS

Adrian Floreahttp://blogs.ugidotnet.org/adrian/

Page 2: "Reguli CLS" presentation @ RONUA Bucharest

La inceput: Project 7 Un proiect de cercetare, rod al colaborarii

intre MS Research si cateva universitatzi din afara SUA, in vederea implementarii de compilatoare pentru CLR pentru diferite limbaje de programare folosite cu precadere in mediul academic si explorarii posibilitatzilor de interoperabilitate intre aceste limbaje. Experientza castigata de echipele participante in acest proiect a putut da un valoros feedback arhitectilor .NET si a dus la cresterea popularitatzii limbajelor academice.

Page 3: "Reguli CLS" presentation @ RONUA Bucharest

Regula 1 “CLS rules apply only to those parts of a

type that are accessible or visible outside of the defining assembly”.

Public

FamilyFamily-Or-Assembly

Private

AssemblyFamily-And-Assembly

Compiler-ControlledCLS

Page 4: "Reguli CLS" presentation @ RONUA Bucharest

Regula 2 “Members of non-CLS compliant types shall

not be marked CLS-compliant”. In Visual C#: error CS3003: Type of ‘...' is not

CLS-compliant In Visual Basic .NET compileaza fara erori In Visual J#: warning VJS1466: The attribute

System.CLSCompliantAttribute is being attached but the compiler will not verify that the assembly is CLS compliant

Page 5: "Reguli CLS" presentation @ RONUA Bucharest

Tipuri neconforme cu CLS System.SByte System.UIntPtr System.TypedReference (Regula 14) System.UInt16 System.UInt32 System.UInt64

Page 6: "Reguli CLS" presentation @ RONUA Bucharest

Tipuri neconforme cu CLS “We include Byte rather than SByte in

the CLS because it is much more common to view bytes as unsigned 0..255 values than –128..127 values”.

Brad Abrams, SLAR p. 78

Page 7: "Reguli CLS" presentation @ RONUA Bucharest

Regula 4 “Assemblies shall follow Annex 7 of Technical

Report 15 of the Unicode Standard 3.0. Identifiers shall be in the canonical format defined by Unicode Normalization Form C. For CLS purposes, two identifiers are the same if their lowercase mappings are the same. However, in order to override an inherited definition the CLI requires the precise encoding of the original declaration be used”.

Page 8: "Reguli CLS" presentation @ RONUA Bucharest

Regula 4 In Visual C#: error CS3008: Identifier

'...' is not CLS-compliant error CS3005: Identifier ‘...' differing

only in case is not CLS-compliant In Visual Basic .NET: error BC30260:

'...' is already declared as '...' in this class

In Visual J# compileaza fara erori

Page 9: "Reguli CLS" presentation @ RONUA Bucharest

Regula 6 “Fields and nested types shall be

distinct by identifier comparison alone, even though the CTS allows distinct signatures to be distinguished. Methods, properties, and events that have the same name (by identifier comparison) shall differ by more than just the return type, except as specified in CLS Rule 39”.

Page 10: "Reguli CLS" presentation @ RONUA Bucharest

Regula 6 In Visual C#: error CS0102: The class

‘...' already contains a definition for '...‘ In Visual Basic .NET: error BC31073:

'...' conflicts with a function by the same name declared in '...'

Page 11: "Reguli CLS" presentation @ RONUA Bucharest

Regula 10 “Accessibility shall not be changed

when overriding inherited methods, except when overriding a method inherited from a different assembly with accessibility Family-or-Assembly. In this case the override shall have accessibility family.”

Page 12: "Reguli CLS" presentation @ RONUA Bucharest

Regula 10Assembly 1 Assembly 2

Public Public

Assembly 1 Assembly 2

Family Family

Assembly 1 Assembly 2

Family-Or-Assembly Family

Page 13: "Reguli CLS" presentation @ RONUA Bucharest

Regula 11 “All types appearing in a signature shall

be CLS-compliant”.

Conforme al CLS

Type

Member

Signature

1

Page 14: "Reguli CLS" presentation @ RONUA Bucharest

Regula 12 “The visibility and accessibility of types

and members shall be such that types in the signature of any member shall be visible and accessible whenever the member itself is visible and accessible. For example, a public method that is visible outside its assembly shall not have an argument whose type is visible only within the assembly”.

Page 15: "Reguli CLS" presentation @ RONUA Bucharest

Regula 18 “CLS-compliant interfaces shall not require

the definition of non-CLS compliant methods in order to implement them”.

In Visual C# obtinem: error CS3002: Return type of ‘...' is not CLS-

compliant error CS3001: Argument type ‘...' is not CLS-

compliant In Visual Basic .NET nu obtinem eroare

Page 16: "Reguli CLS" presentation @ RONUA Bucharest

Regula 19 “CLS-compliant interfaces shall not

define static methods, nor shall they define fields”.

In Visual C# obtinem: error CS0106: The modifier 'static' is not

valid for this item error CS0525: Interfaces cannot contain

fields

Page 17: "Reguli CLS" presentation @ RONUA Bucharest

Regula 19 In Visual Basic .NET obtinem: error BC30270: 'Shared' is not valid on

an interface method declaration. error BC30602: Interface members

must be methods, properties, events, or type definitions.

Page 18: "Reguli CLS" presentation @ RONUA Bucharest

Regula 20 “CLS-compliant classes, value types, and

interfaces shall not require the implementation of non-CLS-compliant interfaces”.

In Visual C#: error CS3003: Type of ‘...' is not CLS-compliant

Implementarea unei interfete marcator (goale) neconforme cu CLS nu da insa eroare

Page 19: "Reguli CLS" presentation @ RONUA Bucharest

Regula 21 “An object constructor shall call some

class constructor of its base class before any access occurs to inherited instance data. This does not apply to value types, which need not have constructors”.

Page 20: "Reguli CLS" presentation @ RONUA Bucharest

Regula 21

Page 21: "Reguli CLS" presentation @ RONUA Bucharest

Regula 23 “System.Object is CLS-compliant. Any

other CLS-compliant class shall inherit from a CLS compliant class”.

In Visual C#: error CS3009: ‘...': base type ‘...' is not CLS-compliant

Page 22: "Reguli CLS" presentation @ RONUA Bucharest

Regula 24 “The methods that implement the getter

and setter methods of a property shall be marked SpecialName in the metadata”.

Page 23: "Reguli CLS" presentation @ RONUA Bucharest

Regula 25 “The accessibility of a property and of

its accessors shall be identical”. In Visual Basic .NET si Visual C#,

regula e impusa de sintaxa In Visual J#: error VJS1805: Both

accessor methods of a property or event must have the same modifiers

Page 24: "Reguli CLS" presentation @ RONUA Bucharest

Regula 26 “A property and its accessors shall all

be static, all be virtual, or all be instance”.

In Visual Basic .NET si Visual C#, regula e impusa de sintaxa

In Visual J#, aceeasi eroare ca la regula 25 (VJS1805)

Page 25: "Reguli CLS" presentation @ RONUA Bucharest

Regula 27 “The type of a property shall be the return

type of the getter and the type of the last argument of the setter. The types of the parameters of the property shall be the types of the parameters to the getter and the types of all but the final parameter of the setter. All of these types shall be CLScompliant, and shall not be managed pointers (i.e. shall not be passed by reference)”.

Page 26: "Reguli CLS" presentation @ RONUA Bucharest

Regula 27 Incercand sa incalcam aceasta regula in

Visual Basic .NET, se obtin erorile: BC31064: 'Set' parameter must have the

same type as the containing property. BC30651: Property parameters cannot be

declared 'ByRef‘. BC31065: 'Set' parameter cannot be declared

'ByRef‘. BC31063: 'Set' method cannot have more

than one parameter.

Page 27: "Reguli CLS" presentation @ RONUA Bucharest

Regula 28 “Properties shall adhere to a specific

naming pattern. The SpecialName attribute referred to in CLS rule 24 shall be ignored in appropriate name comparisons and shall adhere to identifier rules”.

Visual J# nu dispune de o sintaxa pentru accesarea proprietatilor

Page 28: "Reguli CLS" presentation @ RONUA Bucharest

Regula 28

Page 29: "Reguli CLS" presentation @ RONUA Bucharest

Regula 28

Page 30: "Reguli CLS" presentation @ RONUA Bucharest

Regula 29 "The methods that implement an event shall

be marked SpecialName in the metadata"

Page 31: "Reguli CLS" presentation @ RONUA Bucharest

Regula 29

Page 32: "Reguli CLS" presentation @ RONUA Bucharest

Regula 30 "The accessibility of an event and of its

accessors shall be identical" In Visual Basic .NET nu exista event

accessors In Visual C# regula e impusa de sintaxa In Visual J#: error VJS1805: Both

accessor methods of a property or event must have the same modifiers

Page 33: "Reguli CLS" presentation @ RONUA Bucharest

Regula 30

Page 34: "Reguli CLS" presentation @ RONUA Bucharest

Regula 31 “The add and remove methods for an event

shall both either be present or absent” In Visual C#: error CS0065: event property

must have both add and remove accessors In Visual Basic .NET amandoua metodele

add si remove sunt absente In Visual J#: error VJS1806: The event '...'

must have both add and remove accessors

Page 35: "Reguli CLS" presentation @ RONUA Bucharest

Regula 32 “The add and remove methods for an event

shall each take one parameter whose type defines the type of the event and that shall be derived from System.Delegate”.

In Visual J#: error VJS1810: Event accessor must be of type 'void add_name(type)' or 'void remove_name(type)' where 'type' derives from System.Delegate

Page 36: "Reguli CLS" presentation @ RONUA Bucharest

Regula 33 “Events shall adhere to a specific

naming pattern. The SpecialName attribute referred to in CLS rule 31 shall be ignored in appropriate name comparisons and shall adhere to identifier rules”.

Page 37: "Reguli CLS" presentation @ RONUA Bucharest

Regula 33

Page 38: "Reguli CLS" presentation @ RONUA Bucharest

Regula 36 “Global static fields and methods are

not CLS-compliant”.

Page 39: "Reguli CLS" presentation @ RONUA Bucharest

Regula 37 “Only properties and methods may be

overloaded”. Deci nu si campurile sau evenimentele In Visual C#: error CS0102: The class

‘...' already contains a definition for ‘...‘ In Visual Basic .NET: error BC30260:

'...' is already declared as '...' in this class

Page 40: "Reguli CLS" presentation @ RONUA Bucharest

Regula 38 “Properties, instance methods, and

virtual methods may be overloaded based only on the number and types of their parameters, except the conversion operators named op_Implicit and op_Explicit which may also be overloaded based on their return type”.

Page 41: "Reguli CLS" presentation @ RONUA Bucharest

Regula 38 Overloading CTS Overloading CLS Overloading by demangling (la nivel

compilator, vezi Eiffel#)

Page 42: "Reguli CLS" presentation @ RONUA Bucharest

Regula 39 “If either op_Implicit or op_Explicit is

provided, an alternate means of providing the coercion shall be provided”.

ToXxx FromXxx

Page 43: "Reguli CLS" presentation @ RONUA Bucharest

Regula 40 “Objects that are thrown shall be of type

System.Exception or inherit from it. Nonetheless, CLS compliant methods are not required to block the propagation of other types of exceptions”.

Page 44: "Reguli CLS" presentation @ RONUA Bucharest

Regula 40 Programatorii Visual J# au la dispozitie

doua ierarhii de exceptii: exceptii Java (care deriva din java.lang.Throwable) si exceptii .NET (care deriva din System.Exception). Cele doua ierarhii sunt mapate partial de catre metoda java.lang.Throwable.__mapCorException iar java.lang.Throwable deriva din System.Exception

Page 45: "Reguli CLS" presentation @ RONUA Bucharest

Regula 40

Page 46: "Reguli CLS" presentation @ RONUA Bucharest

Regula 40 In Visual C#: error CS0155: The type caught

or thrown must be derived from System.Exception

In Visual Basic .NET: error BC30665: 'Throw' operand must derive from 'System.Exception‘

In Visual J#: error VJS1362: Cannot throw ‘...' that does not inherit from java.lang.Throwable or System.Exception

Page 47: "Reguli CLS" presentation @ RONUA Bucharest

Regula 40 In Lagoona .NET, exceptiile deriva din

System.Object si nu din System.Exception

In Nemerle si S# nu exista restrictii

Page 48: "Reguli CLS" presentation @ RONUA Bucharest

Regula 41 “Attributes shall be of type System.Attribute,

or inherit from it”. In Visual C#: error CS0616: ‘...': is not an

attribute class In Visual Basic .NET: error BC31504: ‘...'

cannot be used as an attribute because it does not inherit from 'System.Attribute‘

In Visual J#: error VJS1397: Attribute ‘...' doesn't inherit from 'System.Attribute'


Recommended