private IReadOnlyNamedCollection <DataEntityPropertyToken> CreateTokens(Type type) { var collection = new NamedCollection <DataEntityPropertyToken>(m => m.Property.Name); if (type == null || type == typeof(object) || Zongsoft.Common.TypeExtension.IsDictionary(type)) { foreach (var property in _entity.Properties) { collection.Add(new DataEntityPropertyToken(property, null)); } } else { foreach (var property in _entity.Properties) { var member = this.FindMember(type, property.Name); if (member != null) { collection.Add(new DataEntityPropertyToken(property, member)); } } } return(collection); }
private static void LoadResults(NamedCollection <Result> results, string modelName, Method method, StoredProcedure procedure) { Match matchResults = regexResults.Match(procedure.Definition); int length = matchResults.Groups["Name"].Captures.Count; if (length == 0 && method.MethodType == MethodType.ExecuteReader) { string typePostfix = regexGetList.IsMatch(method.Name) ? "Collection" : "Item"; string modelNameWithSchema = GetModelForMethod(procedure.Schema, modelName); // TODO: Conflict Names. results.Add( new Result { Name = modelName + typePostfix, CommonType = modelNameWithSchema + typePostfix, Description = string.Empty, IsOutputParameter = false }); } else { for (int i = 0; i < length; i++) { results.Add( new Result { Name = MappingHelper.GetPascalCase(matchResults.Groups["Name"].Captures[i].Value), CommonType = matchResults.Groups["Type"].Captures[i].Value, Description = string.Empty, IsOutputParameter = false }); } } foreach (var parameter in method.Parameters) { if (parameter.Direction != ParameterDirection.Input) { results.Add( new Result { Name = parameter.Name, CommonType = parameter.Name == "ReturnResult" ? "ReturnResult" : MappingHelper.GetCommonTypeString(parameter.Type), Description = parameter.Description, IsOutputParameter = true }); } } }
private void TypeToArguments(NamedCollection <IArgumentInstance> arguments, NamedCollection <IArgumentDeclaration> declarations, ILocalIdentifierScope identifiers, ArgumentSide side, Type type, FieldToInstance fields) { if (type == null) { return; } foreach (var field in type.GetRuntimeFields()) { var argumentDecl = new ArgumentDeclaration { IsUnrolled = field.GetCustomAttributes(typeof(ArgumentUnrolled)).Any(), IsAssignable = field.GetCustomAttributes(typeof(ArgumentAssignable)).Any(), Name = field.Name, Type = NetTypeToRebuildType(field.FieldType) //Value = field.V }; var argument = new ArgumentInstance { Argument = argumentDecl, Side = side }; declarations.Add(argumentDecl); identifiers.Add(argument); arguments.Add(argument); fields.Add(field, argument); } }
public void TestNamedCollection() { INamedList <int> l1 = new NamedList <int>("l1", 11); INamedCollection <int> nc1 = new NamedCollection <int>("NamedCollection 1 ", l1); nc1.OnNameChanged += Nc1_OnNameChanged; l1.OnNameChanged += Nc1_OnNameChanged; Console.WriteLine(nc1); Console.WriteLine(l1); l1.Name = "Named List #1"; for (int i = 0; i < 11; i++) { nc1.Add(i); } nc1.Name = "NamedCollection 1"; nc1.Name = "Collection 1, which is named."; Console.WriteLine(nc1); Console.WriteLine(l1); }
private static void LoadParameters(NamedCollection <Code.Parameter> parameters, Procedure procedure) { string parameterName; var procedureParameters = procedure.Parameters; foreach (var parameter in procedureParameters) { parameterName = provider.GetParameterName(parameter.Name); parameters.Add( new Code.Parameter() { Name = parameterName.ToPascalCase(), CamelCaseName = parameterName.ToCamelCase(), SqlName = parameter.Name, DbType = parameter.DbType, Type = MappingHelper.GetCommonTypeString(parameter.DbType.ToCommonType()), EnumType = DiscoverEnumType(parameter.DbType.ToCommonType(), parameterName), Direction = parameter.Direction, Size = parameter.Size, Description = parameter.Description }); } }
public void AddTest() { var count = _list.Count; _customers.Add(new Customer() { Name = "New Customer", }); Assert.Equal(count + 1, _list.Count); _employees.Add(new Employee() { Name = "New Employee", }); Assert.Equal(count + 2, _list.Count); }
private static void LoadEnumMembers(NamedCollection <EnumMember> members, Enumeration enumeration) { foreach (var enumerationMember in enumeration.Members) { members.Add( new EnumMember { Name = enumerationMember.Name, Value = enumerationMember.Value, Description = enumerationMember.Description }); } }
/// <summary> /// Creates <see cref="TrustNode"/> representations for all entries in a <see cref="TrustDB"/>. /// </summary> public static NamedCollection<TrustNode> ToNodes([NotNull] this TrustDB trustDB) { #region Sanity checks if (trustDB == null) throw new ArgumentNullException("trustDB"); #endregion var nodes = new NamedCollection<TrustNode>(); foreach (var key in trustDB.Keys) { foreach (var domain in key.Domains) nodes.Add(new TrustNode(key.Fingerprint, domain)); } return nodes; }
private NamedCollection <Enumeration> GetAllEnumerations() { NamedCollection <Enumeration> emumerations = new NamedCollection <Enumeration>(); foreach (var reference in this.references) { if (File.Exists(reference)) { GetEnumerationFromAssembly(reference).ForEach( enumeratioin => emumerations.Add(enumeratioin) ); } } return(emumerations); }
/// <summary> /// Creates a new log with the given name. /// </summary> /// <param name="name">Name to give to the log, i.e. "Axiom.log"</param> /// <param name="defaultLog"> /// If true, this is the default log output will be /// sent to if the generic logging methods on this class are /// used. The first log created is always the default log unless /// this parameter is set. /// </param> /// <param name="debuggerOutput"> /// If true, output to this log will also be routed to <see cref="System.Diagnostics.Debug"/> /// Not only will this show the messages into the debugger, but also allows you to hook into /// it using a custom TraceListener to receive message notification wherever you want. /// </param> /// <returns>A newly created Log object, opened and ready to go.</returns> public Log CreateLog(string name, bool isDefaultLog, bool debuggerOutput) { Log newLog = new Log(name, debuggerOutput); // set as the default log if need be if (defaultLog == null || isDefaultLog) { defaultLog = newLog; } if (name == null) { name = string.Empty; } logList.Add(name, newLog); return(newLog); }
private static void LoadProperties(NamedCollection <Property> properties, IColumns databaseObject) { Table table; bool isView = databaseObject is View; if (isView) { table = null; } else { table = databaseObject as Table; } var columns = databaseObject.Columns; string name; CommonType commonType; foreach (var column in columns) { name = column.Name.ToPascalCase(); commonType = column.DbType.ToCommonType(); properties.Add( new Property { Name = name, CamelCaseName = column.Name.ToCamelCase(), ColumnName = column.Name, DbType = column.DbType, Type = MappingHelper.GetCommonTypeString(commonType), EnumType = DiscoverEnumType(commonType, name), Nulls = (commonType == CommonType.String || commonType == CommonType.Object) ? false : column.Nullable, Size = column.Size, Description = column.Description, HasDefault = isView ? false : !string.IsNullOrEmpty(column.Default.Trim()), IsPrimaryKey = isView ? false : table.PrimaryKey.Columns.Contains(column.Name), IsExtended = false }); } }
/// <summary> /// Creates <see cref="TrustNode"/> representations for all entries in a <see cref="TrustDB"/>. /// </summary> public static NamedCollection <TrustNode> ToNodes(this TrustDB trustDB) { #region Sanity checks if (trustDB == null) { throw new ArgumentNullException(nameof(trustDB)); } #endregion var nodes = new NamedCollection <TrustNode>(); foreach (var key in trustDB.Keys) { foreach (var domain in key.Domains) { nodes.Add(new TrustNode(key.Fingerprint, domain)); } } return(nodes); }
private static void LoadProperties(NamedCollection <Property> properties, View view) { foreach (Column column in view.Columns) { properties.Add( new Property { Name = GetName(view, column.Name), Column = column.Name, ColumnName = MappingHelper.GetPascalCase(column.Name), Description = column.Description, Nulls = column.Nullable, ReferenceType = GetReferenceType(view, column.Name), Size = column.Size, SqlDbType = column.SqlDbType, Type = MappingHelper.GetCommonType(column.SqlDbType), Attributes = string.Empty }); } }
private static void LoadParameters(NamedCollection <Code.Parameter> parameters, StoredProcedure procedure) { string parameterName; foreach (var parameter in procedure.Parameters) { parameterName = MappingHelper.GetPascalCase(MappingHelper.GetParameterName(parameter.Name)); parameters.Add( new Code.Parameter() { Name = parameterName, SqlName = parameter.Name, SqlDbType = parameter.SqlDbType, Description = parameter.Description, Direction = parameter.Direction, Size = parameter.Size, Type = MappingHelper.GetCommonType(parameter.SqlDbType) }); } }
private static void LoadProperties(NamedCollection <Property> properties, Table table) { foreach (Column column in table.Columns) { properties.Add( new Property { Name = GetName(table, column.Name), Column = column.Name, ColumnName = MappingHelper.GetPascalCase(column.Name), Description = column.Description, Nulls = column.Nullable, ReferenceType = GetReferenceType(table, column.Name), Size = column.Size, SqlDbType = column.SqlDbType, Type = MappingHelper.GetCommonType(column.SqlDbType), CanGetItemBy = CanGetItemBy(table, column.Name), CanGetCollectionBy = CanGetCollectionBy(table, column.Name), IsPrimaryKey = table.PrimaryKey.Columns.Contains(column.Name), HasDefault = !string.IsNullOrEmpty(column.Default.Trim()), Attributes = string.Empty }); } }
static NamedCollection <IArgumentDeclaration> ParseArgumentsDecl( IEnumerator <TokenData> tokens, IContext context, ArgumentSide side, ref bool done) { var result = new NamedCollection <IArgumentDeclaration>(); var token = tokens.Current; var withBracket = token.Type == Token.BracketOpen; if (withBracket) { if (!tokens.MoveNext()) { done = true; } if (done) { return(result); // TODO: report error dangling open bracket } token = tokens.Current; } var withComma = false; while (true) { var isAssignable = false; if (token.Type == Token.OperatorLiteral && ((IIdentifierLiteral)token.Data).Content == "*") { isAssignable = true; if (!tokens.MoveNext()) { done = true; } if (done) { return(result); // TODO: report missing value & dangling open bracket } token = tokens.Current; } if (token.Type != Token.IdentifierLiteral) { break; } var argName = ((IIdentifierLiteral)token.Data).Content; // TODO: check for duplicate argument names var argument = new ArgumentDeclaration { Name = argName, IsAssignable = isAssignable }; result.Add(argument); context.Identifiers.Add(new ArgumentInstance { Argument = argument, Side = side }); if (!tokens.MoveNext()) { done = true; } if (done) { return(result); // TODO: report error dangling open bracket } token = tokens.Current; #region Argument Type if (token.Type == Token.OperatorLiteral && ((IIdentifierLiteral)token.Data).Content == ":") { if (!tokens.MoveNext()) { done = true; } if (done) { return(result); // TODO: report missing type & dangling open bracket } token = tokens.Current; // TODO: expand ParseTypeExpression if (token.Type == Token.IdentifierLiteral) { var typeName = ((IIdentifierLiteral)token.Data).Content; if (context.Identifiers[typeName] is IModuleInstance typeEntry && typeEntry.IsType()) { argument.Type = typeEntry; } else { // TODO: report missing type } if (!tokens.MoveNext()) { done = true; } if (done) { return(result); // TODO: report dangling open bracket } token = tokens.Current; } } #endregion #region Default Value if (token.Type == Token.OperatorLiteral && ((IIdentifierLiteral)token.Data).Content == "=") { if (!tokens.MoveNext()) { done = true; } if (done) { return(result); // TODO: report missing value & dangling open bracket } argument.Value = ExpressionParser.Parse(tokens, context, ref done); if (done) { return(result); // TODO: report missing dangling open bracket } token = tokens.Current; } #endregion #region Comma Separator if (token.Type == Token.CommaSeparator) { if (!withComma && result.Count > 1) { // TODO: report inconsistent use of commas // handling: ignore } withComma = true; if (!tokens.MoveNext()) { done = true; } if (done) { return(result); } } else if (withComma) { // TODO: report inconsistent use of commas // handling: ignore } #endregion }
/// <summary> /// Adds a specific file to the <paramref name="files"/> list. /// </summary> /// <param name="files">The collection to add the file to.</param> /// <param name="type">The type-subdirectory the file belongs to.</param> /// <param name="name">The file name to be added to the list.</param> /// <param name="flagAsMod">Set to <c>true</c> when handling mod files to detect added and changed files.</param> private static void AddFileToList(NamedCollection<FileEntry> files, string type, string name, bool flagAsMod) { if (flagAsMod) { // Detect whether this is a new file or a replacement for an existing one if (files.Contains(name)) { var previousEntry = files[name]; // Only mark as modified if the pre-existing file isn't already a mod file itself if (previousEntry.EntryType == FileEntryType.Normal) { files.Remove(previousEntry); files.Add(new FileEntry(type, name, FileEntryType.Modified)); } } else files.Add(new FileEntry(type, name, FileEntryType.Added)); } else { // Prevent duplicate entries if (!files.Contains(name)) files.Add(new FileEntry(type, name)); } }
//--------------------// #region Add asset /// <summary> /// Adds an <see cref="Asset"/> to the cache. /// </summary> /// <param name="asset">The <see cref="Asset"/> to add.</param> internal void AddAsset(Asset asset) { _assetCache.Add(asset); }
/// <inheritdoc/> public NamedCollection <SelectionsTreeNode> GetTree(Selections selections) { #region Sanity checks if (selections == null) { throw new ArgumentNullException(nameof(selections)); } #endregion var visited = new HashSet <FeedUri>(); var result = new NamedCollection <SelectionsTreeNode>(); ImplementationSelection?TryGetImplementation(IInterfaceUri target) { try { return(selections[target.InterfaceUri]); } catch (KeyNotFoundException) { return(null); } } string?GetPath(ImplementationBase implementation) => implementation.LocalPath ?? (implementation.ID.StartsWith(ExternalImplementation.PackagePrefix) ? "(" + implementation.ID + ")" : _implementationStore.GetPath(implementation.ManifestDigest)); void AddNodes(IInterfaceUri target, SelectionsTreeNode?parent) { // Prevent infinite recursion if (visited.Contains(target.InterfaceUri)) { return; } visited.Add(target.InterfaceUri); var implementation = TryGetImplementation(target); var node = new SelectionsTreeNode( target.InterfaceUri, implementation?.Version, (implementation == null) ? null : GetPath(implementation), parent); result.Add(node); if (implementation == null) { return; } // Recurse into regular dependencies foreach (var dependency in implementation.Dependencies) { AddNodes(dependency, parent: node); } foreach (var command in implementation.Commands) { // Recurse into command dependencies foreach (var dependency in command.Dependencies) { AddNodes(dependency, parent: node); } // Recurse into runner dependency if (command.Runner != null) { AddNodes(command.Runner, parent: node); } } } AddNodes(selections, parent: null); return(result); }