} // ctor /// <summary>Add a meta info value.</summary> /// <param name="key">Meta key.</param> /// <param name="getDataType">Data type of the value.</param> /// <param name="value">Unconverted value of the meta key.</param> protected void Add(string key, Func <Type> getDataType, object value) { if (String.IsNullOrEmpty(key)) { throw new ArgumentNullException("key"); } if (value == null) { metaInfo.Remove(key); } else { // change the type if (WellknownMetaTypes.TryGetValue(key, out var dataType)) { value = Procs.ChangeType(value, dataType); } else if (getDataType != null) { value = Procs.ChangeType(value, getDataType()); } // add the key if (value == null) { metaInfo.Remove(key); } else { metaInfo[key] = value; } } } // proc Add
} // func TryGetProperty internal Expression GetMetaConstantExpression(string key, bool generateException) { if (TryGetProperty(key, out var value)) { return(Expression.Constant(value, typeof(object))); } else if (WellknownMetaTypes.TryGetValue(key, out var type)) { return(Expression.Convert(Expression.Default(type), typeof(object))); } else if (generateException) { return(Expression.Throw( Expression.New(Procs.ArgumentOutOfRangeConstructorInfo2, new Expression[] { Expression.Constant(key), Expression.Constant("Could not resolve key.") } ), typeof(object) )); } else { return(Expression.Constant(null, typeof(object))); } } // func GetMetaConstantExpression