Skip to content

A library that allows you to parse any object type to a specific default object type this can be extended to contain your own custom types

License

Notifications You must be signed in to change notification settings

samdvlpr/ParseTo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is ParseTo

Parse To was a project first conceptualized as a way to commonly handle nulls but soon moved into a generic Parser to take an object variable and turn it into a generically passed type, a built in default for the type or a passed default for the type.

It does this by using an IParse<> interface that creates a handler for the type you wish to cast to or resturns an Exception if the type has not IParse<> impelmentation

Current Functionality

Custom parsable types

To build custom parsable type inherit a handler class or actual parsable object class from the IParse<[ObjectClassName]>(Must have a blank constructor) and implement the interface. Its as simple as that you class can now be parsed

For Example:

public TestObject : IParse<TestObject>
{
    public string Name { get; set; }
    
    public TestObject Parse(object i)
    {
        if(i is string)
            return new TestObject() { Name = i };
        return (TestObject)i;
    }

    public TestObject GetDefault()
    {
        return new TestObject();
    }
}    

build the class and inhrit from IParse<>(Must have a blank constructor)

public void TestMethod(string obj = "blank")
{
    var testObject = obj.ParseTo<TestObject>();

Now you can parse to your test object

Pre-built parsable types

int

Default return: 0

int?

Default return: null

string

Default return: ""

double

Default return: 0

long

Default return: 0

float

Default return: 0

decimal

Default return: 0

Guid

Default return: 00000000-0000-0000-0000-000000000000

bool

Default return: false

bool?

Default return: null

DateTime

Default return: 1/1/0001 12:00:00 AM (Equals Date.MinValue)

DateTime?

Default return: null

Contribute

Come conribute would love to hear you ideas Contribute

Issues

Got an issue here are my guidelines for reporting it.

License

This work is licensed under a MIT License

Code of Conduct

This repository contains the Open Source Code of Conduct

About

A library that allows you to parse any object type to a specific default object type this can be extended to contain your own custom types

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages