Table of Contents

Method AsStructType

Namespace
SparkTest.NET.Extensions
Assembly
SparkTest.NET.dll

AsStructType<T>(T)

Creates a struct type from a given T

[Pure]
public static StructType AsStructType<T>(this T _) where T : class

Parameters

_ T

instance of T

Returns

StructType

struct type

Type Parameters

T

some T

Examples

Converting a anonymous object to a struct type


var customPerson = new
{
    FirstName = "James",
    LastName = "Stanley",
    Hobby = "Cycling"
};
customPerson
    .AsStructType()
    .Should()
    .Be(
        new StructType(
            new[]
            {
                new StructField("FirstName", new StringType()),
                new StructField("LastName", new StringType()),
                new StructField("Hobby", new StringType())
            }
        )
    );

Exceptions

NotSupportedException

if the type is not supported in spark

AsStructType(Type)

Creates a struct type from a given Type

[Pure]
public static StructType AsStructType(this Type type)

Parameters

type Type

type to convert

Returns

StructType

struct type

Examples

Converting a simple POCO to a struct type


class Person
{
    public string? Name { get; set; }
    public int Age { get; set; }
}

[Fact(DisplayName = "POCOs can be converted to Spark Struct types, Example 2")]
public static void Case8() =>
    typeof(Person)
        .AsStructType()
        .Should()
        .Be(
            new StructType(
                new[]
                {
                    new StructField("Name", new StringType()),
                    new StructField("Age", new IntegerType())
                }
            )
        );

Exceptions

NotSupportedException

if the type is not supported in spark