Skip to content

Instantly share code, notes, and snippets.

View nirinchev's full-sized avatar

Nikola Irinchev nirinchev

  • Realm
  • Copenhagen
View GitHub Profile
async Task First()
{
await Second();
}
async Task Second()
{
DoExpensiveCalculation1();
await Task.Run(() =>
{
void main() {
final accessor = Accessor();
final property = ValueProperty<int>(accessor, 'foo', 5);
print(property.getValue());
}
class Accessor {
final Map<String, Object?> _values = <String, Object?>{};
T getValue<T>(String propertyName) => _values[propertyName] as T;
IQueryable<Powerup> PowerupsAroundLocation(Vector3 location, float radius)
{
// Note that this query returns a cube around the location, not a sphere.
var powerups = realm.All<Powerup>().Filter(
"Position.x > $0 AND Position.x < $1 AND Position.y > $2 AND Position.y < $3 AND Position.z > $4 AND Position.z < $5",
location.x - radius, location.x + radius,
location.y - radius, location.y + radius,
location.z - radius, location.z + radius);
}
class Vector3Model : EmbeddedObject
{
// Casing of the properties here is unusual for C#,
// but consistent with the Unity casing.
private float x { get; set; }
private float y { get; set; }
private float z { get; set; }
public Vector3Model(Vector3 vector)
{
enum TransactionState
{
Pending,
Settled,
Error
}
class Transaction : RealmObject
{
private string _State { get; set; }
// _Name is mapped to 'Name' which is what we use here
var peters = realm.All<Person>().Filter("Name == 'Peter'");
class Person : RealmObject
{
protected override void OnPropertyChanged(string propertyName)
{
base.OnPropertyChanged(propertyName);
if (propertyName == nameof(_Name))
{
RaisePropertyChanged(nameof(Name));
}
class Person : RealmObject
{
[MapTo("Name")]
private string _Name { get; set; }
public string Name
{
get => _Name;
set
{
class Transaction : RealmObject
{
public Guid Id { get; private set; } = Guid.NewGuid();
}
class Person : RealmObject
{
public string Name { get; private set; }
public Person(string name)
{
// ...
}
}