Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace ObjectPrinting.Context;

public interface IPropertyPrinterConfigContext<TOwner, T>
{
IPropertyPrinterConfigContext<TOwner, T> SetSerializer(Func<T, string> serializer);
IPropertyPrinterConfigContext<TOwner, T> ExcludeProperty();
PrintingConfig<TOwner> End();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace ObjectPrinting.Context;

public interface IStringPropertyPrinterConfigContext<TOwner> : IPropertyPrinterConfigContext<TOwner, string>
{
IStringPropertyPrinterConfigContext<TOwner> TrimToLength(int maxLength);
}
33 changes: 33 additions & 0 deletions ObjectPrinting/Context/PropertyContext/PropertyContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using ObjectPrinting.Context;

namespace ObjectPrinting;

public class PropertyContext<TOwner, T> : IPropertyPrinterConfigContext<TOwner, T>
{
private readonly PrintingConfig<TOwner> parent;
private readonly string propertyName;

internal PropertyContext(PrintingConfig<TOwner> parent, string propertyName)
{
this.parent = parent;
this.propertyName = propertyName;
}

public IPropertyPrinterConfigContext<TOwner, T> SetSerializer(Func<T, string> serializer)
{
parent.SetPropertySerializer(propertyName, serializer);
return this;
}

public IPropertyPrinterConfigContext<TOwner, T> ExcludeProperty()
{
parent.ExcludeProperty(propertyName);
return this;
}

public PrintingConfig<TOwner> End()
{
return parent;
}
}
49 changes: 49 additions & 0 deletions ObjectPrinting/Context/PropertyContext/StringPropertyContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using ObjectPrinting.Context;

namespace ObjectPrinting;

public class StringPropertyContext<TOwner> : IStringPropertyPrinterConfigContext<TOwner>
{
private readonly PrintingConfig<TOwner> parent;
private readonly string propertyName;

internal StringPropertyContext(PrintingConfig<TOwner> parent, string propertyName)
{
this.parent = parent;
this.propertyName = propertyName;
}

public IStringPropertyPrinterConfigContext<TOwner> Set(Func<string, string> serializer)
{
parent.SetPropertySerializer(propertyName, serializer);
return this;
}

public IStringPropertyPrinterConfigContext<TOwner> Exclude()
{
parent.ExcludeProperty(propertyName);
return this;
}

public IStringPropertyPrinterConfigContext<TOwner> TrimToLength(int maxLength)
{
parent.TrimStringProperty(propertyName, maxLength);
return this;
}

public PrintingConfig<TOwner> End()
{
return parent;
}

IPropertyPrinterConfigContext<TOwner, string> IPropertyPrinterConfigContext<TOwner, string>.SetSerializer(Func<string, string> serializer)
{
return Set(serializer);
}

IPropertyPrinterConfigContext<TOwner, string> IPropertyPrinterConfigContext<TOwner, string>.ExcludeProperty()
{
return Exclude();
}
}
37 changes: 37 additions & 0 deletions ObjectPrinting/Context/TypeContext/BaseContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using ObjectPrinting.Context;

namespace ObjectPrinting;

public class BaseContext<TOwner, T> : IPrintingConfigContext<TOwner, T>
{
private readonly PrintingConfig<TOwner> parent;

internal BaseContext(PrintingConfig<TOwner> parent)
{
this.parent = parent;
}

public IPrintingConfigContext<TOwner, T> SetSerializer(Func<T, string> serializer)
{
parent.SetTypeSerializer(serializer);
return this;
}

public IPrintingConfigContext<TOwner, T> UsingCulture(IFormatProvider culture)
{
parent.SetNumericCulture<T>(culture);
return this;
}

public IPrintingConfigContext<TOwner, T> ExcludeType()
{
parent.ExcludeType<T>();
return this;
}

public PrintingConfig<TOwner> End()
{
return parent;
}
}
11 changes: 11 additions & 0 deletions ObjectPrinting/Context/TypeContext/IPrintingConfigContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace ObjectPrinting.Context;

public interface IPrintingConfigContext<TOwner, T>
{
IPrintingConfigContext<TOwner, T> SetSerializer(Func<T, string> serializer);
IPrintingConfigContext<TOwner, T> UsingCulture(IFormatProvider culture);
IPrintingConfigContext<TOwner, T> ExcludeType();
PrintingConfig<TOwner> End();
}
Loading