Click or drag to resize
weroSoft AG, Software
CodeExamination Class
The documentation is integral part of the weroSoft product documentation. This part is intended to be used by developers only.
Provides the code examination for types according the defined rules.
Inheritance Hierarchy
SystemObject
  WeroSoft.Diagnostics.CodeExaminationCodeExamination

Namespace:  WeroSoft.Diagnostics.CodeExamination
Assembly:  WeroSoft.Core.Library (in WeroSoft.Core.Library.dll) Version: 3.0
Syntax
C#
public sealed class CodeExamination : ICodeExamination
Remarks

The code examination is a library part which is intended to be used by developers during testing their code, but also on runtime for components which are mission critical and correctly must be implemented from the point of view of the framework and its products like Triton and Heron.

Code examination is not a replacement for the compiler. It has been introduced for checks of code which can not be made by the compiler, or where the compiler can be set to ignore rules. Code checks have been introduced to allow writing checking rules for any purpose, and to be examined to any code independent whether its code of the framework, code of projects or customers.


Principle of work
The principle of usage of code examination is easy. Follow the steps below for performing one or multiple code examination on types of your choice.

  • Instantiation of Code Examination - Create an instance of code examination can be done either directly locally in the code (e.g., in a unit test, or in any component during initiation. In runtime environments you may use the code examination application service which is provided in the framework as centralized instance for code examination.
  • Registration of examinees - After creating the code examination register the types which shall be examined. Note that registration can be called as many types for different or same times a needed. The Code Examination automatically ignore calls which happens for types and rules for this types which are already registered. See next paragraph for more information about registration.
  • Execute examination - After all requested types have been registered, the code examination can be executed.
  • Consume result. - Finally, the result can be obtained in different formats. For tracing reasons the code examination supports different text formats, and for programmatic reasons the code examination supports the presentation of the result by using the CheckResult type of the library.
  • Repeat work - If more code examination is used afterwards, you can create a new instance of code examination or working on the same instance again and simple register one or more types after any executed code examination at any time. Every execution allows to check the new parts separately. If you register a type which already examined its registration is reset, and you can again examine it.


Registration of types.
The registration of a type for the code examination can be performed in three different ways.

  • Single type - The single type registration is done using one of the registration methods which has a type as parameter. This methods register exactly the given type and the rules of this type. Note that this can be the directly the given type (direct registration) or using the CodeExaminationAttribute on the given type also another targeted type (indirect registration). This kind of registration need a call to the registration method per type which shall be examined.
  • Bulk registration - The bulk registration is done using one of the registration methods which have an assembly as parameter. This methods registers all types found in the given assembly according the found rules and the additional filter criteria. For more information about the filter criteria see the parameter description of the given methods.
  • Ignoring registration - Sometimes it is important to ignore a defined type on code examination. In this case the method Register(Type, Boolean) allows to register the given type to be ignored on code examination when set the second parameter to true.

Examples

The following sample shows how a simple complete work cycle like it can be used in a unit test.

// Arrange the code examination and register the test type for testing.
ICodeExamination examination = new CodeExamination();
examination.Register(typeof(StandardConstructorPositiveExaminee));

// Act the examination.
CheckResult result = examination.Execute();

// Assert the result.
Assert.AreEqual(CheckIssueLevel.Success, result.IssueLevel, "The issue level is not as expected.");

The following sample shows how a bulk test can be written. This sample loads the whole weroSoft Core Library and examine their rules. The result is created using all three possible representations. Where the CheckResult can directly be used for programmatic checks, the two text representations or used for tracing information in files (see below the code).

Bulk test
// Arrange the code examination and register the assembly which 
// contains the types to be examined. Note that a random
// type is used for getting the needed assembly information.
CodeExamination examination = new CodeExamination();
examination.Register(typeof(CheckResult).Assembly);

// Act the examination and the all possible result representations.
CheckResult result = examination.Execute();
string singleLineResult = examination.GetOverallExaminationResult(CodeExaminationResultTextFormat.LinePerIssue, true);
string multiLineResult = examination.GetOverallExaminationResult(CodeExaminationResultTextFormat.FormatIssue);

// Assert the content.
Assert.AreEqual(CheckIssueLevel.Success, result.IssueLevel, "The code examination of the weroSoft Core library is not as expected");
// Add more asserts here ...
Content of the single line text result (shortened):
Success CEX_0001 WeroSoft.Diagnostics.CodeExamination.CodeExaminationRule The type 'CodeExaminationRule' was skipped by code examination due to registered exclude.Ensure that excluding this type is justified.
Success CEX_0001 WeroSoft.Diagnostics.CodeExamination.CodeExaminationRule The type 'CodeExaminationRule' was skipped by code examination due to registered exclude.Ensure that excluding this type is justified.
Success CEX_0000 WeroSoft.CertificateException The type 'CertificateException' was successfully examined by the rule 'Standard constructor rule'. No more action required. 
Success CEX_0000 WeroSoft.ImplementationException The type 'ImplementationException' was successfully examined by the rule 'Standard constructor rule'. No more action required. 
Success CEX_0000 WeroSoft.DataSearchException The type 'DataSearchException' was successfully examined by the rule 'Standard constructor rule'. No more action required. 
Success CEX_0000 WeroSoft.RecursionException The type 'RecursionException' was successfully examined by the rule 'Standard constructor rule'. No more action required. 
Success CEX_0000 WeroSoft.TypeManagerException The type 'TypeManagerException' was successfully examined by the rule 'Standard constructor rule'. No more action required. 
Success CEX_0000 WeroSoft.ConfigurationException The type 'ConfigurationException' was successfully examined by the rule 'Standard constructor rule'. No more action required. 
Success CEX_0000 WeroSoft.SecurityException The type 'SecurityException' was successfully examined by the rule 'Standard constructor rule'. No more action required. 
Success CEX_0000 WeroSoft.TypeFactoringException The type 'TypeFactoringException' was successfully examined by the rule 'Standard constructor rule'. No more action required.     /// 
...
Content of the multi line text result (shortened too):
Code Examination Report
22.12.2021 22:44:47

Count of report items:     46
   Successful        :     46
   Error             :      0
   Warning           :      0
   Information       :      0
   Not checked       :      0   

Type: WeroSoft.AssertArgumentException
   Result:            CEX_0000 Success
   Message:           The type 'AssertArgumentException' was successfully examined by the rule 'Standard constructor rule'.
   Suggested action : No more action required.
   CustomData:        

Type: WeroSoft.BaseException
   Result:            CEX_0000 Success
   Message:           The type 'BaseException' was successfully examined by the rule 'Standard constructor rule'.
   Suggested action : No more action required.
   CustomData:        

Type: WeroSoft.CertificateException
   Result:            CEX_0000 Success
   Message:           The type 'CertificateException' was successfully examined by the rule 'Standard constructor rule'.
   Suggested action : No more action required.
   CustomData:        

Type: WeroSoft.Client.ClientLogicException
   Result:            CEX_0000 Success
   Message:           The type 'ClientLogicException' was successfully examined by the rule 'Standard constructor rule'.
   Suggested action : No more action required.
   CustomData:        

...

The CodeExamination type exposes the following members.

Constructors
  NameDescription
Public methodCodeExamination
Initializes a new instance of the code examination.
Top
Properties
  NameDescription
Public propertyContext
Gets the code examination context of this code examination instance.
Top
Methods
  NameDescription
Public methodStatic memberCheckTypeMatchTarget
Checks whether the given type match the given target.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodExecute
Executes the code examination for the registered types.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetLastExaminationResult
Gets the results of the last execution of code examination.
Public methodGetLastExaminationResult(Boolean)
Gets the results of the last execution of code examination.
Public methodGetLastExaminationResult(CodeExaminationResultTextFormat)
Gets the results of the last execution of code examination.
Public methodGetLastExaminationResult(CodeExaminationResultTextFormat, Boolean)
Gets the results of the last execution of code examination.
Public methodGetOverallExaminationResult
Gets the result of all executions since the code examination was initialized.
Public methodGetOverallExaminationResult(Boolean)
Gets the result of all executions since the code examination was initialized.
Public methodGetOverallExaminationResult(CodeExaminationResultTextFormat)
Gets the result of all executions since the code examination was initialized.
Public methodGetOverallExaminationResult(CodeExaminationResultTextFormat, Boolean)
Gets the result of all executions since the code examination was initialized.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodRegister(Assembly)
Registers the exported types provided by the defined assembly for code examination.
Public methodRegister(Type)
Registers a single type for code examination.
Public methodRegister(Assembly, CodeExaminationTarget)
Registers the exported types provided by the defined assembly for code examination.
Public methodRegister(Type, Boolean)
Registers a single type for code examination or exclude it from code examination.
Public methodRegister(Type, ICodeExaminiationRule)
Registers a single type for code examination together with an explicit defined rule.
Public methodRegisterAssignables
Public methodRegisterDecorated
Public methodReset
Resets the code examination.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Extension Methods
  NameDescription
Public Extension MethodClone(CloneWorkingMode, IEnumerableType)Overloaded.
Clones an object by serialization.
(Defined by RuntimeExtensions.)
Public Extension MethodCloneT(CloneWorkingMode, IEnumerableType)Overloaded.
Clones an object by serialization.
(Defined by RuntimeExtensions.)
Public Extension MethodConvert (Defined by DataConverterExtensions.)
Public Extension MethodCreateTraceDataEntry(StringBuilder, SourceLevels, TraceableKind, String)Overloaded.
Creates a data entry into a string builder according to the giving parameters.
(Defined by TraceExtensions.)
Public Extension MethodCreateTraceDataEntry(SourceLevels, TraceableKind, String, String, Int32)Overloaded.
Creates a trace entry for a data element.
(Defined by TraceExtensions.)
Public Extension MethodCreateTraceDataEntry(StringBuilder, SourceLevels, TraceableKind, String, String, Int32)Overloaded.
Creates a trace entry into a string builder.
(Defined by TraceExtensions.)
Public Extension MethodDynamicCast
Dynamically casts a reference to another type.
(Defined by TypeManagerHelper.)
Public Extension MethodExtractSystemParametersFromTrigger
Extracts the system parameters from a collection of trigger parameter and transform them to a dictionary using string keys and string values.
(Defined by TriggerExtensions.)
Public Extension MethodGetFieldValue(String)Overloaded.
Gets the data object held by a defined field of a particular type.
(Defined by UnitTest.)
Public Extension MethodGetFieldValueT(String)Overloaded.
Gets the data object held by a defined field of a particular type.
(Defined by UnitTest.)
Public Extension MethodGetPropertyValue(String)Overloaded.
Gets the data object held by a defined property of a particular type.
(Defined by UnitTest.)
Public Extension MethodGetPropertyValueT(String)Overloaded.
Gets the data object held by a defined property of a particular type.
(Defined by UnitTest.)
Public Extension MethodInject(Type, Object)Overloaded.
Injects all fields or properties which are marked with the defined attribute type name.
(Defined by DataInjection.)
Public Extension MethodInject(Type, Object, Boolean)Overloaded.
Injects all fields or properties which are marked with the defined attribute type name.
(Defined by DataInjection.)
Public Extension MethodInjectField
Injects a value to a property within a data object.
(Defined by DataInjection.)
Public Extension MethodInjectProperty(String, Object)Overloaded.
Injects a value to a property within a data object.
(Defined by DataInjection.)
Public Extension MethodInjectProperty(String, Type, Object)Overloaded.
Injects a value to a property within a data object.
(Defined by DataInjection.)
Public Extension MethodInvoke(String, Object)Overloaded.
Invokes a method on an object by reflection.
(Defined by UnitTest.)
Public Extension MethodInvokeTResult(String, Object)Overloaded.
Invokes a method on an object by reflection.
(Defined by UnitTest.)
Public Extension MethodSetFieldValue
Sets the data object on a defined field of a particular type.
(Defined by UnitTest.)
Public Extension MethodSetPropertyValue
Sets the data object on a defined property of a particular type.
(Defined by UnitTest.)
Public Extension MethodSetReadOnlyFieldValue
Sets the data object on a defined field of a particular type.
(Defined by UnitTest.)
Public Extension MethodTryInjectProperty
Tries to Inject a value to a property within a data object.
(Defined by DataInjection.)
Top
See Also