internal static object GetNew(Type type) { Func <object> del; if (Ctors.TryGetValue(type, out del)) { return(del()); } if (type.HasDefaultConstructor()) { Expression @new = Expression.New(type); if (type.IsValueType) //lambda won't box by default, which is required for value types. { @new = Expression.Convert(@new, typeof(object)); } del = (Func <object>)Expression.Lambda(typeof(Func <object>), @new).Compile(); } else { del = () => null; } Ctors[type] = del; return(del()); }
internal static ContentMatchExpression CreateContentMatchExpression(ContentToken token) { string header = token.Content.Substring(0, token.Content.IndexOf(':') + 1); if (string.IsNullOrWhiteSpace(header)) { return(new TextMatchExpression(token)); } else { Func <ContentToken, ContentMatchExpression> ctor; if (Ctors.TryGetValue(header, out ctor)) { return(ctor(token)); } else { return(new TextMatchExpression(token)); } } }