Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tomlm/flexobject
FlexObject is a hybrid object which combines the best of typed and dynamic in .NET
https://github.com/tomlm/flexobject
Last synced: 5 days ago
JSON representation
FlexObject is a hybrid object which combines the best of typed and dynamic in .NET
- Host: GitHub
- URL: https://github.com/tomlm/flexobject
- Owner: tomlm
- License: mit
- Created: 2018-05-22T18:18:34.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-08T16:20:09.000Z (5 months ago)
- Last Synced: 2025-01-15T15:19:22.569Z (11 days ago)
- Language: C#
- Size: 26.4 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FlexObject
FlexObject is a hybrid object which combines the best of typed and dynamic in .NET## It's pure dynamic
You can simply use it as a dynamic object```C#
dynamic obj = new FlexObject();
obj.x = 3;
obj.y = "yo";
```## It's pure typed
You can use it as a typed object```C#
public class Car : FlexObject
{
public string Name { get;set;}
}Car car = new Car();
car.Name = "test";
car.Age = 15;
if (car.Name == "test" && car["Age"] == 15)
{
}
```## It can be both!
You can use it as a typed object AND a dynamic object at the same time!```C#
Car car = new Car();
if (car.Name == null)
{
// use typed property
car.Name = "Volvo";// assign a property via dictionary syntax
car["x"] = 3;// use a property using dynamic keyword
dynamic car2 = car;
if (car.x == 3 && car.Name == "Volvo")
{
}
}
```You can also enumerate typed and untyped properties the same way.
```C#
foreach(var property in car.GetProperties())
{
Debug.Print(car[property]);
}
```It also supports INotifyPropertyChanged notifications.
``` C#
public class Car : FlexObject
{
private string _name;
public string Name { get=>_name; set { _name = value; NotifyChanged();}}
}
Car car = new Car();
car.PropertyChanged += (sender, args) => Debug.Print("Property {0} changed", args.PropertyName);
car.Name = "Volvo";
// => Property Name Changed
car["x"] = 3;
// => Property x Changed
```