C# Code Actions

Autogenerated by MFractor v3.6.7

Create Immutable Constructor

Professional Only

Configuration Id: com.mfractor.code_actions.csharp.create_immutable_constuctor

This code action creates a constructor that assigns all of a classes readonly fields from constructor arguments

The Create Immutable Constructor code action is useful when building readonly class implementations.

When triggered, the code action collects all readonly fields in a class and builds a constructor that has a parameter that assigns to each readonly field.

Before

public class MyImmutableClass
{
    public readonly string MyString;
    public readonly int MyInt;
}

After

public class MyImmutableClass
{
    public readonly string MyString;
    public readonly int MyInt;

    public MyImmutableClass(string myString, myInt)
    {
        MyString = myString;
        MyInt = myInt;
    }
}

Uses:

Exclude Symbol From Linker

Professional Only

Configuration Id: com.mfractor.code_actions.linker.exclude_symbol_from_linking

The Exclude From Linking code action creates linker config files and ensures a symbol isn't remove by the linker.

When creating Android and iOS applications, the Xamarin toolchain uses the Linker to remove unused symbols from the final application build. The Exclude Symbol From Linker code action generates a linker.xml entry for the symbol that is selected.

Uses:

Generate Interface Implementation

Professional Only

Configuration Id: com.mfractor.code_actions.csharp.generate_interface_implementation

Creating a new interface implementation

Creates a new implementation of the selected interface.

Uses:

Go To Implementation

Professional Only

Configuration Id: com.mfractor.code_actions.csharp.go_to_interface_implementation

You can use MFractors Go-To Implementation shortcut to find classes that implement that interface and then jump to that class!

Shortcut: Option + D

Navigates to the implementation of an interface, abstract class or any members of that interface/abstract class. If there are multiple implementations of this interface/class/member, shows a list of everywhere it is declared.

Implement Base Class Constructors

Professional Only

Configuration Id: com.mfractor.code_actions.csharp.implement_base_class_constructors

When a C# class inherits from a base type that does only has parameterised constructors, this code action will generate each of the base classes parametered constructors.

For example, say a developer wanted to inherit MyCustomView from Android.Views.View to create a custom view in Xamarin.Android; the View class does not have any paramterless contructors.


public class MyCustomView : Android.Views.View // Generates a compiler error as View has no parameterless constructors. 
{
}

Using the Implement Base Class Constructors code action against the MyCustomView class would generate the following code.


public class MyClass : View
{
    public MyClass(System.IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer) : base(javaReference, transfer)
    {
    }

    public MyClass(Android.Content.Context context) : base(context)
    {
    }

    public MyClass(Android.Content.Context context, Android.Util.IAttributeSet attrs) : base(context, attrs)
    {
    }

    public MyClass(Android.Content.Context context, Android.Util.IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr)
    {
    }

    public MyClass(Android.Content.Context context, Android.Util.IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes)
    {
    }
}

Uses:

Implement Interface Member In Children

Professional Only

Configuration Id: com.mfractor.code_actions.csharp.implement_interface_member_in_children

This code action detects when classes implemening an interface do not have an implementation for the member under the cursor and generates a stub for it in all classes where it's missing.'

Uses:

Replace String With Resource Lookup

Professional Only

Configuration Id: com.mfractor.code_actions.resx.replace_csharp_string_with_resource_lookup

You can use the localisation wizard to find and move all C# strings into a RESX file, replacing the original string with a resource lookup!

This code refactoring will open the localisation wizard, allowing you to walk through all strings in a C# code file and replace inline strings with resource lookups.

Uses:

Simplify Qualified Type

Professional Only

Configuration Id: com.mfractor.code_actions.csharp.simplify_qualified

Use the Simplify Qualified Type refactoring to introduce usings for a qualified type reference.

When a type reference is qualified with either a full or partial namespace, this refactoring inserts a using statement for the types namespace and removes the namespace component of the type.