• Basics
  • Abyss
  • Web APIs
  • C# & Razor
  • .net API
  • JS & TS API

    Show / Hide Table of Contents

    Interface ICreateInstance

    Marks objects - usually DynamicCode - which can create instances of other C# files.
    A special feature is that it must store a reference to the path it's in (provided by the compiler that created this instance). This is important, so that CreateInstance knows what path to start in.

    Namespace: ToSic.Sxc.Code
    Assembly: ToSic.Sxc.dll
    Syntax
    [PublicApi_Stable_ForUseInYourCode]
    public interface ICreateInstance

    Properties

    | Improve this Doc View Source

    CreateInstancePath

    Location of the current code. This is important when trying to create instances for other code in relative folders - as this is usually not known.

    Declaration
    string CreateInstancePath { get; set; }
    Property Value
    Type Description
    System.String

    The real path to the currently executed code - important for dynamically compiled code like WebApis

    Methods

    | Improve this Doc View Source

    CreateInstance(String, String, String, String, Boolean)

    Create an instance of code lying in a file near this

    Declaration
    dynamic CreateInstance(string virtualPath, string noParamOrder = "Params must be named (https://r.2sxc.org/named-params)", string name = null, string relativePath = null, bool throwOnError = true)
    Parameters
    Type Name Description
    System.String virtualPath

    path to the other code file to compile

    System.String noParamOrder

    see Convention: Named Parameters

    System.String name

    Override the class name to compile - usually not required as it should match the file name

    System.String relativePath

    optional relative path, will usually use the CreateInstancePath

    System.Boolean throwOnError

    throw errors if compiling fails, recommended

    Returns
    Type Description
    System.Object

    An object of the class in the file

    Remarks

    Note that the C# code which we are creating an instance of inherits from DynamicCode then it will automatically be initialized to support App, AsDynamic etc.

    • Improve this Doc
    • View Source
    Back to top Generated by DocFX