Search Results for

    Show / Hide Table of Contents

    Interface ICodeBuilder

    Namespace: LemonEdge.API.Core.Scripting
    Assembly: LemonEdge.API.dll
    Syntax
    public interface ICodeBuilder

    Properties

    GetStandardExecutableReferences

    Returns all PortableExecutableReference assemblies that have been loaded by the system for use when generating dynamic code

    Declaration
    IEnumerable<PortableExecutableReference> GetStandardExecutableReferences { get; }
    Property Value
    Type Description
    IEnumerable<PortableExecutableReference>

    Methods

    AddOrUpdateMemoryType(Assembly, byte[])

    Adds a single dynamic memory type assembly to always be included.

    Declaration
    void AddOrUpdateMemoryType(Assembly assem, byte[] data)
    Parameters
    Type Name Description
    Assembly assem

    The assembly to ensure we are including a PortableExecutableReference

    byte[] data

    Compile(string, string, bool, params Assembly[])

    Compiles the given syntax tree into an assembly in the specified dllStream with the specified fileName

    Declaration
    CustomAssembly Compile(string fileName, string code, bool throwErrors, params Assembly[] references)
    Parameters
    Type Name Description
    string fileName

    The name to give the generated assembly.

    string code

    The code to parse and return a syntax tree for.

    bool throwErrors

    Whether to throw errors or return null.

    Assembly[] references

    The reference dlls to compile against.

    Returns
    Type Description
    CustomAssembly

    THe result of the compilation of the dll, including any compile errors, warnings, etc

    LoadStandardExecutableReferences(IEnumerable<Assembly>, IEnumerable<byte[]>)

    When generating dynamic dlls, and compiling code, it will often make reference to libraries within LemonEdge itself such as this Utils assembly, and the API.

    As such this is used to load PortableExecutableReference classes for each assembly in the app domain that can be referenced by dynamic code being generated

    You shouldn't need to use this, LemonEdge does itself to ensure all relevant AddIn and assemblies can be referenced in custom code

    Declaration
    Task<PortableExecutableReference[]> LoadStandardExecutableReferences(IEnumerable<Assembly> assemblies, IEnumerable<byte[]> customAssemblies = null)
    Parameters
    Type Name Description
    IEnumerable<Assembly> assemblies

    The list of assemblies we want to generate PortableExecutableReference for

    IEnumerable<byte[]> customAssemblies

    Any list of custom assemblies in their byte array form that we also want to be referenceable

    Returns
    Type Description
    Task<PortableExecutableReference[]>

    A task for completing the method - only used if the SetAssemblyReferenceGenerator(Func<TResult>) has been used to provide a custom mechanism of creating the classes

    ParseSyntaxTree(string, CSharpParseOptions)

    Returns a syntax tree for the given custom c# code

    Declaration
    SyntaxTree ParseSyntaxTree(string code, CSharpParseOptions options = null)
    Parameters
    Type Name Description
    string code

    The code to parse and return a syntax tree for.

    CSharpParseOptions options

    Options support script format (top-level code with no class declarations).

    Returns
    Type Description
    SyntaxTree

    A syntax tree for the given custom c# code

    SetAssemblyReferenceGenerator(Func<Assembly, Task<PortableExecutableReference>>)

    Normally we can generate a PortableExecutableReference from a file assembly easily.

    However in certain enviroments, such as Blazor, we dont have the assemblies location so we need to download it from an http stream.

    This method allows us to override the default generation of a PortableExecutableReference with a custom one

    Declaration
    void SetAssemblyReferenceGenerator(Func<Assembly, Task<PortableExecutableReference>> getRef)
    Parameters
    Type Name Description
    Func<Assembly, Task<PortableExecutableReference>> getRef

    A function that given an assembly will return a task that can generate a PortableExecutableReference for it

    Validate(string, string, params Assembly[])

    Compiles the given syntax tree in validation mode, returning any errors.

    Declaration
    ImmutableArray<Diagnostic> Validate(string name, string code, params Assembly[] references)
    Parameters
    Type Name Description
    string name

    The temporary name for the generated assembly.

    string code

    The code to parse and return a syntax tree for.

    Assembly[] references

    The reference dlls to compile against.

    Returns
    Type Description
    ImmutableArray<Diagnostic>

    The result of the validation, including any compile errors, warnings, etc

    Extension Methods

    LinqExtensions.AsArray<T>(T)
    LinqExtensions.ToArrayOfOne<T>(T)
    LinqExtensions.ToListOfOne<T>(T)
    MiscExtensions.SetIfNotEqual<T, TP>(T, Expression<Func<T, TP>>, TP)
    WeakReferenceExtensions.WeakReference(object)
    SQLExtensions.ToSQLValue(object, bool)
    ReflectionExtensions.ClearEventInvocations(object, string)
    StringExtensions.ToCSVFormatString(object, Type)
    In this article
    Back to top © LemonEdge Technologies. All rights reserved.