Table of Contents

InOperatorResult Class

Definition

Namespace
Cuemon.Data
Assemblies
Cuemon.Data.dll
Source
src/Cuemon.Data/InOperatorResult.cs

Provides the result of an InOperator<T> operation.

public class InOperatorResult
Inheritance
InOperatorResult

Examples

The following example demonstrates how to create an InOperatorResult by using a custom InOperator<T> subclass and then access its arguments, parameters, and string representation. The IntInOperator maps integer values to parameterized SQL-safe placeholders prefixed with @p. Calling ToSafeResult with three values produces an InOperatorResult whose arguments CSV and parameter metadata are written to the console, showing how to generate safe SQL IN clauses programmatically.

using System;
using System.Data;
using System.Linq;
using Cuemon.Data;

namespace MyApp.Examples;

public class InOperatorResultExample
{
    public static void Main()
    {
        var safeOperator = new IntInOperator();
        InOperatorResult result = safeOperator.ToSafeResult(10, 20, 30);

        Console.WriteLine("Arguments CSV: {0}", result);
        Console.WriteLine("Parameter count: {0}", result.Parameters.Count());
        Console.WriteLine("First parameter value: {0}", result.Parameters.First().Value);

        // Output:
        // Arguments CSV: @p0, @p1, @p2
        // Parameter count: 3
        // First parameter value: 10
    }

    private sealed class IntInOperator : InOperator<int>
    {
        public IntInOperator() : base(() => "@p") { }

        protected override IDbDataParameter ParametersSelector(int expression, int index)
        {
            return new SimpleParameter(string.Concat(ParameterPrefix, index), expression);
        }

        private sealed class SimpleParameter : IDbDataParameter
        {
            public SimpleParameter(string name, object value)
            {
                ParameterName = name;
                Value = value;
            }

            public DbType DbType { get; set; } = DbType.Int32;
            public ParameterDirection Direction { get; set; } = ParameterDirection.Input;
            public bool IsNullable => false;
            public string ParameterName { get; set; }
            public int Size { get; set; }
            public string SourceColumn { get; set; } = string.Empty;
            public bool SourceColumnNullMapping { get; set; }
            public DataRowVersion SourceVersion { get; set; } = DataRowVersion.Current;
            public object Value { get; set; }
            public byte Precision { get; set; }
            public byte Scale { get; set; }
        }
    }
}

Properties

Name Description
Arguments

Gets the arguments for the IN operator.

Parameters

Gets the parameters for the IN operator.

Methods

Name Description
ToParametersArray()

Converts the parameters for the IN operator to an IDbDataParameter array.

ToString()

Returns a string that represents this instance.