The IecAnalyzer is a roslyn based Code Analyzer with the goal to help the development with the Phoenix Contact C# Add-In.
For general information on the PLCnext C# developement have a look at our samples on github.
The IecAnalyzer is installed via the PLCnext Toolchain. The PLCnext Toolchain also installs the Visual Studio Project Template "PLCnext C# Firmware Library". If you create a new Project with this Template the IecAnalyzer is active in the new project by default.
You may disable the IecAnalyzer by changing UseIecAnalyzer to false in the .csproj file:
<PropertyGroup>
<UseIecAnalyzer>false</UseIecAnalyzer>
</PropertyGroup>
You can adjust the severity of each rule with a .editorconfig
. Additional information about automatic or manual creation at .Net Code-Analysis Configuration
- An example that disables the rule Iec001 in all .cs files (on and beneath the level of the EditorConfig file) would be:
[*.cs] # next block applies to all .cs files
# sets Iec001 severity to none (possible severities: default|none|silent|suggestion|warning|error)
dotnet_diagnostic.Iec001.severity = none
You can also suppress a rule only for a single code region using the context menu to create a SuppressMessage attribute or pragma.
Diagnostic ID | Summary | Default Severity |
---|---|---|
Iec001 | Old Attributes are not allowed | Warning |
Iec002 | Name of the pou type too long | Error |
Iec003 | Method missing that FunctionBlock/Function/Program needs | Error |
Iec004 | Parameters of user types or Any have to use ref | Warning |
Iec005 | Return Type has to be IEC compatible | Error |
Iec006 | Parameter type has to be IEC compaible | Error |
Iec007 | Field type has to be IEC compatible | Error |
Iec008 | Return type is ambiguous in IEC and should be explicitly defined with a DataType attribute | Suggestion |
Iec009 | Parameter type is ambiguous in IEC and should be explicitly defined with a DataType attribute | Suggestion |
Iec010 | Field type is ambiguous in IEC and should be explicitly defined with a DataType attribute | Suggestion |
Iec011 | Return type needs correct DataType attribute | Error |
Iec012 | Parameter type needs correct DataType attribute | Error |
Iec013 | Field type needs correct DataType attribute | Error |
Iec014 | Fields of type Any must not be Outputs | Error |
Iec015 | Do not use GdsRetain | Suggestion |
Iec018 | Structure fields should be InOut pointers | Suggestion |
Iec019 | Functions and FunctionContainers are not allowed to have attributed fields | Error |
Iec020 | Methods attributed Execution or Initialization are not allowed to have parameters | Error |
Iec021 | Methods can only have one Output parameter at the first position | Error |
Iec022 | Return types must not be Any or IecString or user structure | Error |
Iec023 | Program port types must not be of type Any | Error |
Iec024 | Silently reports any struct declaration to provide templates for User Array, Structure and String | Silent |
Iec025 | IEC Array pattern has to be correct | Error |
Iec026 | IEC String Pattern has to be correct | Error |
Iec027 | IEC Structure and all its fields have to be public | Error |
Iec028 | String length and size have to be correct | Error |
Iec029 | Init/ctor has to be called in Initialization for FunctionBlock fields that provide Init/ctor | Error |
Iec030 | IEC Structs have to provide an Init Method calling field's Init/ctor method when any fields have it | Error |
Iec031 | Array element type is ambiguous and should be explicitly defined with a DataType attribute | Suggestion |
Iec032 | Array element type needs correct DataType attribute | Error |
Iec033 | Array element type has to be IEC compatible | Error |
Iec034 | Structure field type is ambiguous and should be explicitly defined with a DataType attribute | Suggestion |
Iec035 | Structure field type has to be Iec compatible | Error |
Iec036 | Structure field needs correct DataType attribute | Error |
Iec037 | Program must not have Input Output or InOut attributes | Error |
Iec038 | Init Methods of user types must not have an Initialization attribute | Warning |
Iec039 | User type Init methods must not have parameters | Error |
Iec040 | Structure parameters should use ref | Suggestion |
Iec041 | Init/ctor must only be called once in Init or __Init | Error |
Iec042 | unsafe blocks are only allowed when pointers are used inside | Warning |
Iec043 | Output parameter name unequal to class name | Error |
Iec044 | Output parameter name unequal to method name | Error |
Iec045 | Output parameter must be ref or out | Error |
Iec046 | Function Container Functions have to be static | Error |
Iec047 | Arrays must not have fields apart from the Anchor field | Error |
Iec048 | Only use Initialization and Execution where correct | Error |
Iec049 | User attribute should only be used in Function Blocks | Error |
Iec050 | Input or Output fields and parameters shall not be pointers | Error |
Iec051 | Structures must not have Any or Pointer fields | Error |
Iec052 | Retaining on Input can be better achieved with Variable Flag | Warning |
Iec053 | Retaining should only be used in FB or Program | Error |
Iec054 | Only use Function attribute in Function Container or on classes | Error |
Iec055 | Strings must not have fields apart from the s field | Error |
Iec056 | Do not use intern attributes | Error |
Iec057 | Namespace names must not be keywords | Error |
Iec058 | Do not mix Retain and GdsRetain | Error |
Iec059 | Only use Retaining where possible | Error |
Iec060 | Only use Hidden on user defined data types and POUs | Error |
Iec061 | Only use NotOverridable on POUs | Error |
Iec062 | Only use OPC, Ehmi, ProfiCloud and Redundant where possible | Error |
Iec064 | Exported fields have to be public | Error |
Iec065 | Do not use the suffix attribute when using attributes | Error |
Iec066 | Methods returning values must not have Output parameters | Error |
Iec067 | Do not use partial | Warning |
Iec068 | Initialize all Array elements | Error |
Iec069 | Only Initialize in Init method | Error |
Iec070 | Only use Invisible where possible | Error |
Iec071 | Elements need unique names | Error |
Iec072 | Use Init instead of old ctor | Warning |
Iec073 | rctor is deprecated | Warning |
Iec074 | Multidimensional Arrays are not supported yet | Error |
Iec075 | Only use Eno where possible | Error |
Iec076 | Do not use POU attributes on abstract classes | Error |
Iec077 | Exported Identifiers must not be keywords | Error |
Iec078 | Parameters of type Any must not be InOuts | Error |
Iec079 | Only use Port attributes in Program | Error |
Iec080 | DataType Attribute can only be used on classes if they are Functions | Error |
Iec081 | DataType Attribute can only be used on methods if they are User methods or Function methods in FunctionContainer | Error |
Iec082 | DataType Attribute for Output parameters positioned on class or method instead | Error |
Iec084 | Generic methods are not supported | Error |
Iec085 | Max 8 type parameters are supported | Error |
Iec086 | Do not nest type arguments | Error |
Iec087 | Generic delegates can not be parameters | Error |
Iec088 | Fields must not use class type parameters | Error |
Iec089 | Also implement non-generic IComparer when implementing generic IComparer | Error |
- compatability of C# dotnet types to IEC
- ambiguous C# dotnet types that can be converted to multiple IEC types. Therefore a DataType attribute for clarification might be necessary.
- IEC type defined in DataType attributes have to suit the C# dotnet type
- special rules for the type Any (and User Types and IecStrings)
- Deprecated Attributes
- Attribute suffix
[Input]
,[Output]
,[InOut]
,[Local]
,[InputPort]
and[OutputPort]
[User]
[GdsRetain]
and[Retain]
[Function]
[Output]
[Initialization]
and[Execution]
[Skip]
and[ReadOnly]
[Retain]
and[GdsRetain]
[Hidden]
[NotOverridable]
[OPC]
,[Ehmi]
,[ProfiCloud]
and[Redundant]
[Invisible]
[Eno]
[DataType]
positioning