Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiewest committed Feb 10, 2024
1 parent 18d4d77 commit 2d04eee
Show file tree
Hide file tree
Showing 92 changed files with 2,927 additions and 627 deletions.
3 changes: 2 additions & 1 deletion examples/dart_example/bin/dart_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class OperationLogger {
String message,
) {
print(
'$scope: ${T.runtimeType.toString()} [ ${operation.operationId}...$message ');
'$scope: ${T.runtimeType.toString()} [ ${operation.operationId}...$message ',
);
}
}
17 changes: 17 additions & 0 deletions packages/extensions/example/example_dependency_injection.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'dart:collection';

import 'package:extensions/dependency_injection.dart';

void main() {
var collection = ServiceCollection();
collection.addSingleton<String>((services) => '1');
collection.addSingleton<String>((services) => '2');
collection.addSingleton<int>((services) => 3);
collection.addSingleton<int>((services) => 4);
collection.addSingleton<int>((services) => 5);
var sp = collection.buildServiceProvider();

var result = sp.getService<int>();

print(result);
}
6 changes: 3 additions & 3 deletions packages/extensions/example/example_hosting.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:extensions/hosting.dart';

void main() {
var builder = Host.createApplicationBuilder()
..logging.addDebug()
..logging.setMinimumLevel(LogLevel.trace);
var builder = Host.createApplicationBuilder();
// ..logging.addDebug()
// ..logging.setMinimumLevel(LogLevel.trace);

var host = builder.build()..start();

Expand Down
12 changes: 2 additions & 10 deletions packages/extensions/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ export 'src/common/cancellation_token_registration.dart';
export 'src/common/cancellation_token_source.dart';
export 'src/common/cancellation_token.dart';
export 'src/common/disposable.dart';
export 'src/common/string.dart';
export 'src/common/enum.dart';

typedef TimerCallback = void Function(Object? state);

bool isNullOrWhitespace(String? value) {
if (value == null) return true;
return value.trim().isEmpty;
}

bool isNullOrEmpty(String? value) {
if (value == null) return true;
return value.isEmpty;
}
1 change: 1 addition & 0 deletions packages/extensions/lib/diagnostics.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
library extensions.diagnostics;
3 changes: 1 addition & 2 deletions packages/extensions/lib/hosting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'src/hosting/host_application_builder_settings.dart';
import 'src/hosting/host_builder.dart';
import 'src/hosting/hosting_host_builder_extensions.dart';

export 'common.dart';
export 'configuration.dart';
export 'dependency_injection.dart';
export 'logging.dart';
Expand Down Expand Up @@ -42,7 +41,7 @@ export 'src/hosting/service_collection_hosted_service_extensions.dart';
/// Initializes a new instance of the [HostBuilder] class with
/// pre-configured defaults.
HostBuilder createDefaultBuilder([List<String>? args]) {
var builder = HostBuilder();
var builder = DefaultHostBuilder();
return builder.configureDefaults(args);
}

Expand Down
34 changes: 34 additions & 0 deletions packages/extensions/lib/src/common/enum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Mixin to create Enum for bitflags uses.
mixin EnumFlags on Enum {
// value receive a bitwise shift operation. It means "shift the
// bits of 1 to the left by index places".
//
//So, "1,10,100,1000..." == 1,2,4,8,16....
int get value => 1 << index;
// Creates a operator "|" for enum.
int operator |(other) => value | other.value;

int operator &(other) => value & other.value;

int operator ^(other) => value ^ other.value;
}

// Extension "int" to verify that value contains the enum flag.
extension EnumFlagsExtension on int {
bool hasFlag(EnumFlags flag) => this & flag.value == flag.value;
}

void main() {
final x = Car.ford | Car.honda;
print(x);
print(x.hasFlag(Car.honda));
final y = Car.ford & Car.subaru;
print(y);
print(y.hasFlag(Car.ford));
}

enum Car with EnumFlags {
ford,
honda,
subaru,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../../../common.dart';
import '../string.dart' as string;
import 'invalid_operation_exception.dart';

/// /// The exception that is thrown when accessing an object that was disposed.
Expand All @@ -16,7 +16,7 @@ class ObjectDisposedException extends InvalidOperationException {
@override
String? get message {
final name = objectName;
if (isNullOrEmpty(name)) {
if (string.isNullOrEmpty(name)) {
return super.message;
}

Expand Down
15 changes: 15 additions & 0 deletions packages/extensions/lib/src/common/string.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
bool isNullOrEmpty(String? value) {
if (value == null || value.isEmpty) return true;
if (value.isEmpty) return true;
return false;
}

bool isNullOrWhitespace(String? value) {
if (value == null) return true;
return value.trim().isEmpty;
}

bool equals(String value1, String value2, {bool ignoreCase = true}) =>
ignoreCase
? value1.toLowerCase() == value2.toLowerCase()
: value1 == value2;
Loading

0 comments on commit 2d04eee

Please sign in to comment.