/// <summary> /// /// </summary> /// <param name="entityType"></param> /// <param name="connection"></param> /// <param name="tableName"></param> /// <param name="dbFields"></param> /// <param name="fields"></param> /// <param name="commandText"></param> /// <returns></returns> private static UpdateExecutionContext CreateInternal(Type entityType, IDbConnection connection, string tableName, IEnumerable <DbField> dbFields, IEnumerable <Field> fields, string commandText) { var dbSetting = connection.GetDbSetting(); var inputFields = new List <DbField>(); // Filter the actual properties for input fields inputFields = dbFields? .Where(dbField => dbField.IsIdentity == false) .Where(dbField => fields.FirstOrDefault(field => string.Equals(field.Name.AsUnquoted(true, dbSetting), dbField.Name.AsUnquoted(true, dbSetting), StringComparison.OrdinalIgnoreCase)) != null) .AsList(); // Return the value return(new UpdateExecutionContext { CommandText = commandText, InputFields = inputFields, ParametersSetterFunc = FunctionCache.GetDataEntityDbParameterSetterCompiledFunction(entityType, string.Concat(entityType.FullName, StringConstant.Period, tableName, ".Update"), inputFields?.AsList(), null, dbSetting) }); }
public SourceView(string text) : base("SourceView") { TextBox = new Scintilla { Lexer = ScintillaNET.Lexer.Container, VirtualSpaceOptions = VirtualSpace.UserAccessible }; foreach (var id in TextStyle.All) StyleConfig(id); TextBox.StyleNeeded += (s, args) => SignalStyleNeeded(args.Position); TextBox.TextChanged += (s, args) => OnTextChanged(); TextBox.ContextMenu = new ContextMenu(); TextBox.ContextMenu.Popup += (s, args) => OnContextMenuPopup(); CompilerCache = new ValueCache<CompilerBrowser>(CreateCompilerBrowser); ResultCachesViews = new FunctionCache<Value, ResultCachesView> (item => new ResultCachesView(item, this)); ChildViews = new FunctionCache<object, ChildView>(CreateView); Client = TextBox; TextBox.Text = text; TraceLog = new BrowseTraceCollector(this); LogView = new TraceLogView(this); }
Proxy CreateProxy(FunctionCache <Version, ModDescription> modVersions) { var value = modVersions.OrderByDescending(mod => mod.Key).First().Value; var moreVersions = modVersions.Select(v => v.Key).Where(v => v != value.Version); return(new Proxy(value, moreVersions, RefreshTitle)); }
internal T4Context(StringBuilder text, ITextTemplatingEngineHost host) { _text = text; _host = host; _fileItems = new FunctionCache<string, Box<string>>(fileName => new Box<string>("")); _dte = new ValueCache<DTE>(ObtainDTE); }
public CalculatorEngine() { TrigonometryMode = TrigonometryMode.DEG; ConstantDB = new ConstantDB(); _linebuffer = new StringBuilder(); _functioncache = new Dictionary <string, FunctionInformation>(); _preprocessor = new Preprocessor(_functioncache, ConstantDB); var options = new Dictionary <string, object>(); options["DivisionOptions"] = PythonDivisionOptions.New; _history = new ZeroStream(); _output = new EventRedirectedStreamWriter(_history); _output.StreamWasWritten += _output_StreamWasWritten; _engine = Python.CreateEngine(options); _engine.Runtime.IO.SetOutput(_history, _output); _engine.Runtime.IO.SetErrorOutput(_history, _output); _scope = _engine.CreateScope(); _functionTypes = new Type[] { typeof(Trigonometry), typeof(Engineering), typeof(GeneralFunctions), typeof(Variations), typeof(TypeFunctions), typeof(Statistics) }; FunctionCache.Fill(ref _functioncache, ref _scope, _functionTypes); }
/// <summary> /// Gets the value of this curry cache according to the parameter association /// </summary> /// <param name="association"></param> /// <returns></returns> public ExplainedValue GetValue(Dictionary <Actual, IValue> association) { ExplainedValue retVal = null; FunctionCache current = Curry; foreach (IValue val in OrderedParameters(association)) { FunctionCache next; if (current.TryGetValue(val, out next)) { current = next; } else { current = null; break; } } if (current != null) { retVal = current.Value; } return(retVal); }
public static Qualifier Put <T1, R>(Qualifier named, Func <T1, R> f1) { FunctionCache.AddOrUpdate(named, f1, (q, f) => { Log.LogWarning("{0}: Key '{1}' already present. Using new function reference.", typeof(DynamicDelegation), named.ToLabel()); return(f1); }); return(named); }
public TypeLibrary(IEnumerable<Type> types) { _types = types.ToArray(); ByNamePart = new FunctionCache<string, Type>(GetTypeByNamePart); ByNamePartMulti = new FunctionCache<string, Type[]>(GetTypesByNamePart); _byName = _types.GroupBy(t => t.Name, t => t).ToDictionary(t => t.Key, t => t); PrettyName = new FunctionCache<Type, string>(type => ObtainTypeName(type, true)); CompleteName = new FunctionCache<Type, string>(type => ObtainTypeName(type, false)); }
public TypeLibrary(IEnumerable <Type> types) { Types = types.ToArray(); ByNamePart = new(GetTypeByNamePart); ByNamePartMulti = new(GetTypesByNamePart); ByName = Types.GroupBy(t => t.Name, t => t).ToDictionary(t => t.Key, t => t); PrettyName = new(type => ObtainTypeName(type, true)); CompleteName = new(type => ObtainTypeName(type, false)); }
public static Symbol Execute(FunctionSymbol symbol, Stack <Symbol> arguments) { if (cached_functions == null) { LoadFunctionCache(); } if (!cached_functions.ContainsKey(symbol.Name)) { throw new InvalidFunctionException(symbol.Name); } FunctionCache function = cached_functions[symbol.Name]; if (arguments.Count != function.ArgumentCount && function.ArgumentCount >= 0) { throw new ArgumentException(symbol.Name); } if (function.RawSymbols) { if (function.ArgumentCount == -1) { return((Symbol)function.Method.Invoke(null, new object [] { arguments.ToArray() })); } else { return((Symbol)function.Method.Invoke(null, arguments.ToArray())); } } ArrayList resolved_arguments = new ArrayList(); while (arguments.Count > 0) { Symbol argument = arguments.Pop(); if (!(argument is ValueSymbol)) { throw new ArgumentException("argument must be ValueSymbol"); } resolved_arguments.Add((argument as ValueSymbol).Value); } double retval; if (function.ArgumentCount == -1) { retval = (double)function.Method.Invoke(null, new object [] { resolved_arguments.ToArray(typeof(double)) }); } else { retval = (double)function.Method.Invoke(null, resolved_arguments.ToArray()); } return(new NumberSymbol(retval)); }
internal CodeContainer (string moduleName, Root root, Syntax syntax, string description) { ModuleName = moduleName; Root = root; MainCache = new ValueCache<Container> (() => root.MainContainer(syntax, description)); CSharpStringCache = new ValueCache<string>(GetCSharpStringForCache); _functions = new FunctionCache<int, FunctionContainer>(Root.FunctionContainer); }
public FunctionList() { _dictionary = new FunctionCache <FunctionSyntax, FunctionCache<CompoundView, FunctionCache<TypeBase, int>>> ( syntax => new FunctionCache<CompoundView, FunctionCache<TypeBase, int>> ( structure => new FunctionCache<TypeBase, int> (-1, args => CreateFunctionInstance(args, syntax, structure)))); }
/// <summary> /// /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="connection"></param> /// <param name="dbFields"></param> /// <param name="tableName"></param> /// <param name="fields"></param> /// <param name="commandText"></param> /// <returns></returns> private static InsertExecutionContext <TEntity> CreateInternal <TEntity>(IDbConnection connection, IEnumerable <DbField> dbFields, string tableName, IEnumerable <Field> fields, string commandText) where TEntity : class { var typeOfEntity = typeof(TEntity); var dbSetting = connection.GetDbSetting(); var identity = (Field)null; var inputFields = (IEnumerable <DbField>)null; var identityDbField = dbFields?.FirstOrDefault(f => f.IsIdentity); // Set the identity field if (typeOfEntity.IsClassType()) { identity = IdentityCache.Get <TEntity>()?.AsField() ?? FieldCache .Get <TEntity>()? .FirstOrDefault(field => string.Equals(field.Name.AsUnquoted(true, dbSetting), identityDbField?.Name.AsUnquoted(true, dbSetting), StringComparison.OrdinalIgnoreCase)) ?? identityDbField?.AsField(); } // Filter the actual properties for input fields inputFields = dbFields? .Where(dbField => dbField.IsIdentity == false) .Where(dbField => fields.FirstOrDefault(field => string.Equals(field.Name.AsUnquoted(true, dbSetting), dbField.Name.AsUnquoted(true, dbSetting), StringComparison.OrdinalIgnoreCase)) != null) .AsList(); // Variables for the entity action var identityPropertySetter = (Action <TEntity, object>)null; // Get the identity setter if (typeOfEntity.IsClassType() == true && identity != null) { identityPropertySetter = FunctionCache.GetDataEntityPropertySetterCompiledFunction <TEntity>(identity); } // Return the value return(new InsertExecutionContext <TEntity> { CommandText = commandText, InputFields = inputFields, ParametersSetterFunc = FunctionCache.GetDataEntityDbParameterSetterCompiledFunction <TEntity>( string.Concat(typeof(TEntity).FullName, StringConstant.Period, tableName, ".Insert"), inputFields?.AsList(), null, dbSetting), IdentityPropertySetterFunc = identityPropertySetter }); }
/// <summary> /// Converts the <see cref="DbDataReader"/> into an enumerable of <see cref="ExpandoObject"/> object. /// </summary> /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param> /// <param name="basedOnFields">Check whether to create a delegate based on the data reader fields.</param> /// <returns>An array of <see cref="ExpandoObject"/> objects.</returns> internal static IEnumerable <dynamic> ToEnumerable(DbDataReader reader, bool basedOnFields = false) { if (reader != null && reader.HasRows) { var func = FunctionCache.GetDataReaderToExpandoObjectFunction(reader, basedOnFields); while (reader.Read()) { yield return(func(reader)); } } }
/// <summary> /// Returns the first element of a sequence, or a default value if no element is found. /// </summary> /// <param name="type">The <see cref="Type"/> to return.</param> /// <param name="value"> /// The <see cref="IEnumerable"/> to return the item from. /// </param> /// <returns> /// The <see cref="object"/> representing the item. /// </returns> public static object FirstOrDefault(Type type, IEnumerable value) { var key = GetMethodCacheKey(type); if (FunctionCache.TryGetValue(key, out Func <object, object> f) == false) { f = StaticMethodSingleParameter <object>(FirstOrDefaultMethod.MakeGenericMethod(type)); FunctionCache[key] = f; } return(f(Cast(type, value))); }
/// <summary> /// Converts the <see cref="DbDataReader"/> into an enumerable of data entity object. /// </summary> /// <typeparam name="TEntity">The data entity type to convert.</typeparam> /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param> /// <param name="basedOnFields">Check whether to create a delegate based on the data reader fields.</param> /// <returns>An array of data entity objects.</returns> internal static IEnumerable <TEntity> ToEnumerable <TEntity>(DbDataReader reader, bool basedOnFields = false) where TEntity : class { if (reader != null && reader.IsClosed == false && reader.HasRows) { var func = FunctionCache.GetDataReaderToDataEntityFunction <TEntity>(reader, basedOnFields); while (reader.Read()) { yield return(func(reader)); } } }
/// <summary> /// Returns an empty <see cref="IEnumerable{T}"/> that has the specified type argument. /// </summary> /// <param name="type"> /// The <see cref="Type"/> to assign to the type parameter of the returned /// generic <see cref="IEnumerable{T}"/>. /// </param> /// <returns> /// The <see cref="object"/> representing the empty enumerable. /// </returns> public static object Empty(Type type) { var key = GetMethodCacheKey(type); if (FunctionCache.TryGetValue(key, out Func <object, object> f) == false) { f = StaticMethod <object>(EmptyMethod.MakeGenericMethod(type)); FunctionCache[key] = f; } return(f(type)); }
public static object GetValue(PropertyInfo property, object instance) { var key = GetMethodCacheKey(property); if (FunctionCache.TryGetValue(key, out Func <object, object> a) == false) { a = MakeGetMethod(property.GetGetMethod(), property.PropertyType); FunctionCache[key] = a; } return(a(instance)); }
/// <summary> /// Casts the elements of the given <see cref="IEnumerable"/> to the specified type. /// </summary> /// <param name="type">The <see cref="Type"/> to cast to.</param> /// <param name="value"> /// The <see cref="IEnumerable"/> to cast the items of. /// </param> /// <returns> /// The <see cref="object"/> representing the cast enumerable. /// </returns> public static object Cast(Type type, IEnumerable value) { var key = GetMethodCacheKey(type); Func <object, object> f; if (!FunctionCache.TryGetValue(key, out f)) { f = StaticMethodSingleParameter <object>(CastMethod.MakeGenericMethod(type)); FunctionCache[key] = f; } return(f(value)); }
/// <summary> /// Gets the value of the property on the given instance. /// </summary> /// <param name="property">The property to set.</param> /// <param name="instance">The current instance to return the property from.</param> /// <returns>The <see cref="object"/> value.</returns> public static object GetValue(PropertyInfo property, object instance) { var key = GetMethodCacheKey(property); Func <object, object> a; if (!FunctionCache.TryGetValue(key, out a)) { a = BuildGetAccessor(property.GetGetMethod()); FunctionCache[key] = a; } return(a(instance)); }
private FunctionSymbol?TryGetFunctionSymbol(string name) { // symbol comparison relies on object equality; use of this cache ensures that different symbols with the same name are not returned. // we also cache negative lookups (null) so that we don't slow down when looking up references to a missing symbol if (FunctionCache.TryGetValue(name, out var symbol)) { return(symbol); } // wildcard match (e.g. list*) var wildcardOverloads = FunctionWildcardOverloads.Where(fo => fo.WildcardRegex.IsMatch(name)); // create a new symbol for each unique name that matches the wildcard return(wildcardOverloads.Any() ? new FunctionSymbol(name, wildcardOverloads) : null); }
/// <summary> /// Converts the <see cref="DbDataReader"/> into an enumerable of dynamic objects. /// </summary> /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param> /// <param name="dbFields">The list of the <see cref="DbField"/> objects to be used.</param> /// <param name="dbSetting">The instance of <see cref="IDbSetting"/> object to be used.</param> /// <returns>An array of dynamic objects.</returns> public static IEnumerable <dynamic> ToEnumerable(DbDataReader reader, IEnumerable <DbField> dbFields = null, IDbSetting dbSetting = null) { if (reader?.IsClosed == false && reader.HasRows) { var func = FunctionCache.GetDataReaderToExpandoObjectCompileFunction(reader, dbFields, dbSetting); while (reader.Read()) { yield return(func(reader)); } } }
/// <summary> /// Converts the <see cref="DbDataReader"/> into an enumerable of data entity objects. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param> /// <param name="dbFields">The list of the <see cref="DbField"/> objects to be used.</param> /// <param name="dbSetting">The instance of <see cref="IDbSetting"/> object to be used.</param> /// <returns>A list of the target result type.</returns> public static IEnumerable <TResult> ToEnumerable <TResult>(DbDataReader reader, IEnumerable <DbField> dbFields = null, IDbSetting dbSetting = null) { if (reader?.IsClosed == false && reader.HasRows) { var func = FunctionCache.GetDataReaderToTypeCompiledFunction <TResult>(reader, dbFields, dbSetting); while (reader.Read()) { yield return(func(reader)); } } }
/// <summary> /// Converts the <see cref="DbDataReader"/> into an enumerable of <see cref="ExpandoObject"/> object. /// </summary> /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param> /// <param name="tableName">The name of the target table.</param> /// <param name="connection">The used <see cref="IDbConnection"/> object.</param> /// <returns>An array of <see cref="ExpandoObject"/> objects.</returns> internal static IEnumerable <dynamic> ToEnumerable(DbDataReader reader, string tableName, IDbConnection connection) { if (reader != null && reader.HasRows) { var func = FunctionCache.GetDataReaderToExpandoObjectConverterFunction(reader, tableName, connection); while (reader.Read()) { yield return(func(reader)); } } }
/// <summary> /// /// </summary> /// <param name="entityType"></param> /// <param name="connection"></param> /// <param name="dbFields"></param> /// <param name="tableName"></param> /// <param name="fields"></param> /// <param name="commandText"></param> /// <returns></returns> private static MergeExecutionContext CreateInternal(Type entityType, IDbConnection connection, IEnumerable <DbField> dbFields, string tableName, IEnumerable <Field> fields, string commandText) { var dbSetting = connection.GetDbSetting(); var identity = (Field)null; var inputFields = new List <DbField>(); var identityDbField = dbFields?.FirstOrDefault(f => f.IsIdentity); // Set the identity field identity = IdentityCache.Get(entityType)?.AsField() ?? FieldCache .Get(entityType)? .FirstOrDefault(field => string.Equals(field.Name.AsUnquoted(true, dbSetting), identityDbField?.Name.AsUnquoted(true, dbSetting), StringComparison.OrdinalIgnoreCase)) ?? identityDbField?.AsField(); // Filter the actual properties for input fields inputFields = dbFields? .Where(dbField => fields.FirstOrDefault(field => string.Equals(field.Name.AsUnquoted(true, dbSetting), dbField.Name.AsUnquoted(true, dbSetting), StringComparison.OrdinalIgnoreCase)) != null) .AsList(); // Variables for the entity action var identityPropertySetter = (Action <object, object>)null; // Get the identity setter if (identity != null) { identityPropertySetter = FunctionCache.GetDataEntityPropertySetterCompiledFunction(entityType, identity); } // Return the value return(new MergeExecutionContext { CommandText = commandText, InputFields = inputFields, ParametersSetterFunc = FunctionCache.GetDataEntityDbParameterSetterCompiledFunction(entityType, string.Concat(entityType.FullName, StringConstant.Period, tableName, ".Merge"), inputFields?.AsList(), null, dbSetting), IdentityPropertySetterFunc = identityPropertySetter }); }
/// <summary> /// Set the parameters (and/or values) of the <see cref="DbCommand"/> object based on the passed data entity object. /// </summary> /// <typeparam name="TEntity">The type of the data entity object.</typeparam> /// <param name="command">The <see cref="DbCommand"/> object where to set the parameters.</param> /// <param name="tableName">The name of the target table.</param> /// <param name="entities">The list of the data entity objects.</param> /// <param name="inputFields">The list of the input <see cref="DbField"/> objects to be used.</param> /// <param name="outputFields">The list of the output <see cref="DbField"/> objects to be used.</param> public static void SetParameters <TEntity>(DbCommand command, string tableName, IEnumerable <TEntity> entities, IEnumerable <DbField> inputFields, IEnumerable <DbField> outputFields) where TEntity : class { // Get the actual function var func = FunctionCache.GetDataEntitiesDbCommandParameterSetterFunction <TEntity>(tableName, inputFields, outputFields, entities.Count()); // Execute the function func(command, entities.AsList()); }
/// <summary> /// Converts the <see cref="DbDataReader"/> into an enumerable of data entity object. /// </summary> /// <typeparam name="TEntity">The data entity type to convert.</typeparam> /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param> /// <param name="connection">The used <see cref="IDbConnection"/> object.</param> /// <param name="transaction">The transaction object that is currently in used.</param> /// <returns>An array of data entity objects.</returns> public static IEnumerable <TEntity> ToEnumerable <TEntity>(DbDataReader reader, IDbConnection connection = null, IDbTransaction transaction = null) where TEntity : class { if (reader != null && reader.IsClosed == false && reader.HasRows) { var func = FunctionCache.GetDataReaderToDataEntityFunction <TEntity>(reader, connection, transaction); while (reader.Read()) { yield return(func(reader)); } } }
/// <summary> /// Sets the value according to the parameter association /// </summary> /// <param name="association"></param> /// <param name="value"></param> public void SetValue(Dictionary <Actual, IValue> association, IValue value, ExplanationPart explanation) { FunctionCache current = Curry; foreach (IValue val in OrderedParameters(association)) { FunctionCache next; if (!current.TryGetValue(val, out next)) { next = new FunctionCache(); current.Add(val, next); } current = next; } current.Value = new ExplainedValue(value, explanation); }
/// <summary> /// Converts the <see cref="DbDataReader"/> into an enumerable of <see cref="ExpandoObject"/> object in an asynchronous way. /// </summary> /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param> /// <param name="tableName">The name of the target table.</param> /// <param name="connection">The used <see cref="IDbConnection"/> object.</param> /// <returns>An array of <see cref="ExpandoObject"/> objects.</returns> internal static async Task <IEnumerable <dynamic> > ToEnumerableAsync(DbDataReader reader, string tableName, IDbConnection connection) { var list = new List <dynamic>(); if (reader != null && reader.HasRows) { var func = FunctionCache.GetDataReaderToExpandoObjectConverterFunction(reader, tableName, connection); while (await reader.ReadAsync()) { list.Add(func(reader)); } } return(list); }
public FunctionAnalysis2ndPass(FunctionCache functionCache, MethodInfo method) { FunctionCache = functionCache; Data = null; _IsPure = method.Metadata.HasAttribute("JSIL.Meta.JSIsPure"); var parms = method.Metadata.GetAttributeParameters("JSIL.Meta.JSMutatedArguments"); if (parms != null) { ModifiedVariables = new HashSet <string>(GetAttributeArguments <string>(parms)); } else if (!_IsPure) { ModifiedVariables = new HashSet <string>(from p in method.Parameters select p.Name); } else { ModifiedVariables = new HashSet <string>(); } parms = method.Metadata.GetAttributeParameters("JSIL.Meta.JSEscapingArguments"); if (parms != null) { EscapingVariables = new HashSet <string>(GetAttributeArguments <string>(parms)); } else if (!_IsPure) { EscapingVariables = new HashSet <string>(from p in method.Parameters select p.Name); } else { EscapingVariables = new HashSet <string>(); } VariableAliases = new Dictionary <string, HashSet <string> >(); ResultVariable = null; ResultIsNew = method.Metadata.HasAttribute("JSIL.Meta.JSResultIsNew"); MutatedFields = null; Trace(method.Member.FullName); }
/// <summary> /// Converts the <see cref="DbDataReader"/> into an enumerable of data entity objects in asynchronous way. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param> /// <param name="dbFields">The list of the <see cref="DbField"/> objects to be used.</param> /// <param name="dbSetting">The instance of <see cref="IDbSetting"/> object to be used.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> object to be used during the asynchronous operation.</param> /// <returns>A list of the target result type.</returns> public static async IAsyncEnumerable <TResult> ToEnumerableAsync <TResult>(DbDataReader reader, IEnumerable <DbField> dbFields = null, IDbSetting dbSetting = null, [EnumeratorCancellation] CancellationToken cancellationToken = default) { if (reader?.IsClosed != false || !reader.HasRows) { yield break; } var func = FunctionCache.GetDataReaderToTypeCompiledFunction <TResult>(reader, dbFields, dbSetting); while (await reader.ReadAsync(cancellationToken)) { yield return(func(reader)); } }
/// <summary> /// Converts the <see cref="DbDataReader"/> into an enumerable of data entity objects in asynchronous way. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param> /// <param name="dbFields">The list of the <see cref="DbField"/> objects to be used.</param> /// <param name="dbSetting">The instance of <see cref="IDbSetting"/> object to be used.</param> /// <param name="cancellationToken">The <see cref="CancellationToken"/> object to be used during the asynchronous operation.</param> /// <returns>A list of the target result type.</returns> public static async Task <IEnumerable <TResult> > ToEnumerableAsync <TResult>(DbDataReader reader, IEnumerable <DbField> dbFields = null, IDbSetting dbSetting = null, CancellationToken cancellationToken = default) { var list = new List <TResult>(); if (reader != null && reader.IsClosed == false && reader.HasRows) { var func = FunctionCache.GetDataReaderToTypeCompiledFunction <TResult>(reader, dbFields, dbSetting); while (await reader.ReadAsync(cancellationToken)) { list.Add(func(reader)); } } return(list); }
/// <summary> /// Converts the <see cref="DbDataReader"/> into an enumerable of data entity object in an asynchronous way. /// </summary> /// <typeparam name="TEntity">The data entity type to convert.</typeparam> /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param> /// <param name="connection">The used <see cref="IDbConnection"/> object.</param> /// <param name="basedOnFields">Check whether to create a delegate based on the data reader fields.</param> /// <returns>An array of data entity objects.</returns> internal static async Task <IEnumerable <TEntity> > ToEnumerableAsync <TEntity>(DbDataReader reader, IDbConnection connection, bool basedOnFields) where TEntity : class { var list = new List <TEntity>(); if (reader != null && reader.IsClosed == false && reader.HasRows) { var func = FunctionCache.GetDataReaderToDataEntityFunction <TEntity>(reader, connection, basedOnFields); while (await reader.ReadAsync()) { list.Add(func(reader)); } } return(list); }
/// <summary> /// Converts the <see cref="DbDataReader"/> into an enumerable of data entity objects. /// </summary> /// <typeparam name="TEntity">The data entity type to convert.</typeparam> /// <param name="reader">The <see cref="DbDataReader"/> to be converted.</param> /// <param name="connection">The used <see cref="IDbConnection"/> object.</param> /// <param name="connectionString">The raw connection string.</param> /// <param name="transaction">The transaction object that is currently in used.</param> /// <param name="enableValidation">Enables the validation after retrieving the database fields.</param> /// <returns>An array of data entity objects.</returns> internal static IEnumerable <TEntity> ToEnumerableInternal <TEntity>(DbDataReader reader, IDbConnection connection = null, string connectionString = null, IDbTransaction transaction = null, bool enableValidation = true) where TEntity : class { if (reader != null && reader.IsClosed == false && reader.HasRows) { var func = FunctionCache.GetDataReaderToDataEntityCompiledFunction <TEntity>(reader, connection, connectionString, transaction, enableValidation); while (reader.Read()) { yield return(func(reader)); } } }
/// <summary> /// /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="connection"></param> /// <param name="tableName"></param> /// <param name="where"></param> /// <param name="dbFields"></param> /// <param name="fields"></param> /// <param name="hints"></param> /// <param name="transaction"></param> /// <param name="statementBuilder"></param> /// <returns></returns> private static UpdateExecutionContext <TEntity> CreateInternal <TEntity>(IDbConnection connection, string tableName, QueryGroup where, IEnumerable <DbField> dbFields, IEnumerable <Field> fields, string hints = null, IDbTransaction transaction = null, IStatementBuilder statementBuilder = null) where TEntity : class { var dbSetting = connection.GetDbSetting(); var inputFields = new List <DbField>(); // Filter the actual properties for input fields inputFields = dbFields? .Where(dbField => dbField.IsIdentity == false) .Where(dbField => fields.FirstOrDefault(field => string.Equals(field.Name.AsUnquoted(true, dbSetting), dbField.Name.AsUnquoted(true, dbSetting), StringComparison.OrdinalIgnoreCase)) != null) .AsList(); // Identify the requests var updateRequest = new UpdateRequest(tableName, connection, transaction, where, fields, hints, statementBuilder); // Return the value return(new UpdateExecutionContext <TEntity> { CommandText = CommandTextCache.GetUpdateText(updateRequest), InputFields = inputFields, ParametersSetterFunc = FunctionCache.GetDataEntityDbParameterSetterCompiledFunction <TEntity>( string.Concat(typeof(TEntity).FullName, StringConstant.Period, tableName, ".Update"), inputFields?.AsList(), null, dbSetting) }); }
Syntax ( Syntax left, ITokenClass tokenClass, IToken token, Syntax right) : base(NextObjectId++) { Left = left; TokenClass = tokenClass; Token = token; Right = right; Option = new SyntaxOption(this); LocatePositionCache = new FunctionCache<int, Syntax>(LocatePositionForCache); if(Left != null) Left.Parent = this; if(Right != null) Right.Parent = this; }
internal CompoundView(Compound compound, int viewPosition) : base(_nextObjectId++) { Compound = compound; ViewPosition = viewPosition; CompoundContextCache = new ValueCache<CompoundContext> (() => new CompoundContext(this)); _typeCache = new ValueCache<CompoundType>(() => new CompoundType(this)); _accessFeaturesCache = new FunctionCache<int, AccessFeature> (position => new AccessFeature(this, position)); _fieldAccessTypeCache = new FunctionCache<int, FieldAccessType> (position => new FieldAccessType(this, position)); _functionBodyTypeCache = new FunctionCache<FunctionSyntax, FunctionBodyType> (syntax => new FunctionBodyType(this, syntax)); StopByObjectIds(); }
SQLSysViews() { _compountTypesCache = new ValueCache<all_objectsClass[]>(GetCompountTypes); _objectsCache = new ValueCache<Dictionary<string, all_objectsClass>>(CreateObjects); Columns = new FunctionCache<all_objectsClass, all_columnsClass[]>(CreateColumns); }
internal Externalizer() { _map = new FunctionCache<Internalizer.IItem, Item>(Create); _ids = new FunctionCache<Item, int>(Id); }
public Reducer(LocalReference[] references, CodeBase body) { _references = references; _map = new FunctionCache<LocalReference, LocalReference>(GetReplacementsForCache); NewBody = GetNewBody(body); }
public Information(IDataProvider provider) { _sqlSysViews = Profiler.Measure(() => new SQLSysViews(provider)); _compountTypeCache = new FunctionCache<string, CompountType>(GetCompountType); }
public LocalStackReference(FunctionCache<string, StackData> locals, string holder) { _locals = locals; _holder = holder; }