fake_reflection 1.0.1 copy "fake_reflection: ^1.0.1" to clipboard
fake_reflection: ^1.0.1 copied to clipboard

A package to get a class structure (like reflection) in runtime without code generation.

It's a package to get a class structure (like reflection) in runtime without code generation.

Features #

  • Get Class name;
  • Get named params: name, type, isNullable, isRequired;
  • Get positional params: type, isNullable
  • Get positional not required params: type, isNullable

Usage #

pubspec.yaml

dependencies:
 ...
 fake_reflection: <last version here>

import

import 'package:fake_reflection/fake_reflection.dart';

using

  ClassData classData = YourClass.new.reflection();

Example

class Test1Class {
  final int param1;
  final String? param2;
  final Map param3;
  final Map<List, double>? param4;
  const Test1Class(
    this.param1, {
    this.param2,
    required this.param3,
    required this.param4,
  });
}

void main() {
  ClassData classData = Test1Class.new.reflection();
  print(classData.className);
  // output: Test1Class

  print(classData.namedParams);
  // output:
  // {
  //    NamedParam(name: param2, type: String, required: false, nullable: true), 
  //    NamedParam(name: param3, type: Map<dynamic, dynamic>, required: true, nullable: false), 
  //    NamedParam(name: param4, type: Map<List<dynamic>, double>, required: true, nullable: true)
  // }
  
  print(classData.positionalParams); 
  // output: 
  // [
  //   PositionalParam(type: int, nullable: false, required: true),
  // ]
  
  print(classData.notRequiredPositionalParams); 
  //output: []
}
10
likes
140
pub points
43%
popularity

Publisher

verified publisherdeivao.dev

A package to get a class structure (like reflection) in runtime without code generation.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on fake_reflection