Django dynamic model fields

As of today, there are four available approaches, two of them requiring a certain storage backend: Django-eav (the original package is no longer mantained but has some thriving forks) This solution is based on Entity Attribute Value data model, essentially, it uses several tables to store dynamic attributes of objects. Great parts about this solution … Read more

How to create own dynamic type or dynamic object in C#?

dynamic MyDynamic = new System.Dynamic.ExpandoObject(); MyDynamic.A = “A”; MyDynamic.B = “B”; MyDynamic.C = “C”; MyDynamic.Number = 12; MyDynamic.MyMethod = new Func<int>(() => { return 55; }); Console.WriteLine(MyDynamic.MyMethod()); Read more about ExpandoObject class and for more samples: Represents an object whose members can be dynamically added and removed at run time.

How to detect if a property exists on an ExpandoObject?

According to MSDN the declaration shows it is implementing IDictionary: public sealed class ExpandoObject : IDynamicMetaObjectProvider, IDictionary<string, Object>, ICollection<KeyValuePair<string, Object>>, IEnumerable<KeyValuePair<string, Object>>, IEnumerable, INotifyPropertyChanged You can use this to see if a member is defined: var expandoObject = …; if(((IDictionary<String, object>)expandoObject).ContainsKey(“SomeMember”)) { // expandoObject.SomeMember exists. }

What’s the difference between dynamic (C# 4) and var?

var is static typed – the compiler and runtime know the type – they just save you some typing… the following are 100% identical: var s = “abc”; Console.WriteLine(s.Length); and string s = “abc”; Console.WriteLine(s.Length); All that happened was that the compiler figured out that s must be a string (from the initializer). In both … Read more

How to implement a rule engine?

This snippet compiles the Rules into fast executable code (using Expression trees) and does not need any complicated switch statements: (Edit : full working example with generic method) public Func<User, bool> CompileRule(Rule r) { var paramUser = Expression.Parameter(typeof(User)); Expression expr = BuildExpr(r, paramUser); // build a lambda function User->bool and compile it return Expression.Lambda<Func<User, bool>>(expr, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)