Provides reflective access to class constructor metadata and instantiation.
This interface enables runtime inspection and invocation of class constructors, including access to:
- Constructor parameters
- Factory constructor detection
- Instance creation
- Declaring class information
{@template constructor_interface_features}
Key Features
- Named and unnamed constructor support
- Parameter inspection
- Type-safe instance creation
- Factory constructor handling
Implementation Notes
Concrete implementations typically wrap platform-specific reflection objects while providing this uniform interface.
Example Usage
// Get constructor metadata
final namedConstructor = userClass.getConstructor('fromJson');
// Inspect parameters
if (namedConstructor.getParameterCount() > 0) {
final firstParam = namedConstructor.getParameterAt(0);
print('First parameter: ${firstParam.getName()}');
}
// Create instances
final user = namedConstructor.newInstance({'json': userData});
{@endtemplate}
- Inheritance
-
- Object
- PermissionManager
- Source
- Executable
- Constructor
- Implemented types
Constructors
- Constructor.declared(ConstructorDeclaration declaration, ProtectionDomain domain)
-
Creates a Constructor instance from reflection metadata.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
canAcceptArguments(
Map< String, dynamic> arguments) → bool -
Checks if named arguments can be accepted.
inherited
-
canAcceptNamedArguments(
Map< String, dynamic> arguments) → bool -
Checks if named arguments can be accepted.
inherited
-
canAcceptPositionalArguments(
List args) → bool -
Checks if positional arguments can be accepted.
inherited
-
checkAccess(
String operation, DomainPermission permission) → void -
Verifies access permissions before performing sensitive operations.
inherited
-
getAllDirectAnnotations(
) → Iterable< Annotation> -
Gets all annotations applied to this element.
inherited
-
getAuthor(
) → Author? -
Retrieves the Author annotation applied to this element, if present.
inherited
-
getDeclaration(
) → ConstructorDeclaration -
Gets the type declaration metadata for this class.
override
-
getDeclaringClass<
D> () → Class< D> -
Gets the class that declares this method.
inherited
-
getDirectAnnotation<
A> () → A? -
Gets a single annotation by type, if present.
inherited
-
getDirectAnnotations<
A> () → Iterable< A> -
Gets all annotations of a specific type.
inherited
-
getModifiers(
) → List< String> -
Returns the list of modifiers associated with this source element.
inherited
-
getName(
) → String -
Gets the declared name of the source.
inherited
-
getNamedParameters(
) → Iterable< Parameter> -
Gets all named parameters declared by this executable.
inherited
-
getParameter(
String name) → Parameter? -
Gets a parameter by name.
inherited
-
getParameterAt(
int index) → Parameter? -
Gets a parameter by index.
inherited
-
getParameterCount(
) → int -
Gets the total number of parameters.
inherited
-
getParameters(
) → Iterable< Parameter> -
Gets all parameters of this executable element.
inherited
-
getParameterTypes(
) → Iterable< Class> -
Gets the types of all parameters.
inherited
-
getPositionalParameters(
) → Iterable< Parameter> -
Gets all positional parameters declared by this executable.
inherited
-
getProtectionDomain(
) → ProtectionDomain -
Gets the protection domain governing access to this element.
inherited
-
getReturnClass(
) → Class< Object> -
Gets the return type of the method.
inherited
-
getReturnType(
) → Type -
Gets the return type of the method.
inherited
-
getSignature(
) → String -
Gets the executable signature as a string.
inherited
-
getVersion(
) → Version -
Retrieves the version metadata associated with this declaration, if any.
inherited
-
hasDirectAnnotation<
A> () → bool -
Checks if this element has a specific annotation.
inherited
-
isConst(
) → bool -
Checks if this executable is declared as const.
inherited
-
isFactory(
) → bool - Checks if this is a factory constructor.
-
isPublic(
) → bool -
Checks if this element is public.
inherited
-
newInstance<
Instance> ([Map< String, dynamic> ? arguments, List args = const []]) → Instance - Creates a new instance using named arguments.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited