Coder Social home page Coder Social logo

dart-opt's Introduction

dart_opt

This exists to serve as an option set generator for a Dart.

The general idea is that for an application there may need to be an object (or several) that you read in a set of key value pairs for and pass into a class.

Note:

I know there are other ways of generating the constructor body for a class automatically using tools like source_gen, but I choose to do this the "manual" way as I find it a good exercise in a language to explore their reflection/mirrors api and other language level features like annotations/attributes

Use

Write your class as a subclass of OptionSet and annotate the member variables you wish to be auto populated from the Map with their appropriate type

Example (from the tests)

class MocOptionSet extends OptionSet {
  @StringOption(optionName: "myStringField", defaultValue: "defaultValue")
  String myString;

  @NumOption(optionName: "myNumber", defaultValue: 10)
  num myNum;

  @BoolOption(optionName: "myBoolean")
  bool myBool;

  @boolOption
  bool unnamedBool;

  @stringOption
  String unnamedString;

  @numOption
  num unnamedNum;

  MocOptionSet(Map<String, dynamic> theMap) : super(theMap);
}

In this example, the to provide a value for the field myBool the Map would need a key: myBoolean and a bool value.

To pass a value for the field unnamedBool the Map would need a key: unnamedBool with a bool value.

TODO

  • Add more api-level documentation
  • Add more unit tests
  • Support Enum types

dart-opt's People

Contributors

orthros avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.