private Dictionary <int, CommaDelimitedStringCollection> GetDatabase() { var contents = GetFileContents(DATABASE_PATH); var commaStr = new CommaDelimitedStringCollection(); commaStr.AddRange(contents.Split(',')); var db = new Dictionary <int, CommaDelimitedStringCollection>(); var id = 0; var collection = new CommaDelimitedStringCollection(); for (var i = 0; i < commaStr.Count; i++) { var str = commaStr[i]; if (str.Contains(":")) { collection.Add(str.Split(':')[1]); if (i > 0) { db.Add(id, collection); } collection = new CommaDelimitedStringCollection(); id = int.Parse(str.Split(':')[0]); } else { collection.Add(str); } } return(db); }
public void Manipulations() { CommaDelimitedStringCollection c = new CommaDelimitedStringCollection(); c.Add("1"); Assert.Equal("1", c.ToString()); c.Add("2"); c.Add("3"); Assert.Equal("1,2,3", c.ToString()); c.Remove("2"); Assert.Equal("1,3", c.ToString()); c.Insert(1, "2"); Assert.Equal("1,2,3", c.ToString()); c.Clear(); Assert.Null(c.ToString()); string[] foo = new string[3]; foo[0] = "1"; foo[1] = "2"; foo[2] = "3"; c.AddRange(foo); Assert.Equal("1,2,3", c.ToString()); }
static void Main(string[] args) { CommaDelimitedStringCollection commaStr = new CommaDelimitedStringCollection(); string[] itemList = { "Test1", "Test2", "Test3" }; commaStr.AddRange(itemList); Console.WriteLine(commaStr.ToString()); //Outputs Test1,Test2,Test3 Console.ReadLine(); }
internal RecentConnectionConfigElement(RecentQueueManagerConnection rc) : this() { QueueManagerName = rc.QueueManagerName; FilterPrefix = rc.ObjectNamePrefix; if (rc.QueueList != null && rc.QueueList.Count > 0) { QueueList = new CommaDelimitedStringCollection(); QueueList.AddRange(rc.QueueList.ToArray()); } }
public void RO_AddRange() { CommaDelimitedStringCollection c = new CommaDelimitedStringCollection(); string[] foo = new string[2]; foo[0] = "hi"; foo[1] = "bye"; c.SetReadOnly(); Assert.Throws <ConfigurationErrorsException>(() => c.AddRange(foo)); }
public void RO_AddRange() { CommaDelimitedStringCollection c = new CommaDelimitedStringCollection(); string[] foo = new string[2]; foo[0] = "hi"; foo[1] = "bye"; c.SetReadOnly(); c.AddRange(foo); }
private OracleCommand GetMappedInsertCommand(object entity, KeyValuePair <Mapper, Type> map) { if (ConnectionMode == Enums.Mode.UnitOfWork && !insertCommands.Where(a => a.Equals(entity)).Any()) { insertCommands.Add(entity); return(null); } OracleCommand cmd = new OracleCommand(); string commandText = string.Empty; CommaDelimitedStringCollection col = new CommaDelimitedStringCollection(); CommaDelimitedStringCollection param = new CommaDelimitedStringCollection(); col.AddRange(map.Key.Columns.Select(a => a.ColumnName).ToArray()); foreach (var column in map.Key.Columns) { var prop = entity.GetType().GetProperty(column.ColumnName); var value = prop.GetValue(entity, null); if (String.IsNullOrWhiteSpace(column.DefaultValue)) { if (string.IsNullOrWhiteSpace(column.SequenceName)) { param.Add(String.Format(":{0}", column.ColumnName)); if (column.Nullable && value == null) { cmd.Parameters.Add(new OracleParameter(column.ColumnName, DBNull.Value)); } else { cmd.Parameters.Add(new OracleParameter(column.ColumnName, value)); } } else { param.Add(String.Format("{0}.{1}.NextVal", _schemmaName, column.SequenceName)); } } else { param.Add(column.DefaultValue); } } commandText = String.Format("INSERT INTO {0}.{1} ({2}) VALUES ({3})", _schemmaName, entity.GetType().Name, col.ToString(), param.ToString()); cmd.CommandText = commandText.ToString(); return(cmd); }
internal RecentRemoteConnectionConfigElement(RecentRemoteQueueManagerConnection rc) : this() { QueueManagerName = rc.QueueManagerName; FilterPrefix = rc.ObjectNamePrefix; if (rc.QueueList != null && rc.QueueList.Count > 0) { QueueList = new CommaDelimitedStringCollection(); QueueList.AddRange(rc.QueueList.ToArray()); } Host = rc.HostName; Port = rc.Port; Channel = rc.Channel; UserId = rc.UserId; }
private List <int> GetPartNumbers(string filePath) { var contents = GetFileContents(filePath); var commaStr = new CommaDelimitedStringCollection(); var result = new List <int>(); commaStr.AddRange(contents.Split(',')); for (var i = 7; i < commaStr.Count; i += 15) { result.Add(int.Parse(commaStr[i].Replace("\"", string.Empty))); } return(result); }
static void Main(string[] args) { // Display title and info. Console.WriteLine("ASP.NET Configuration Info"); Console.WriteLine("Type: CommaDelimitedStringCollection"); Console.WriteLine(); // Set the path of the config file. string configPath = "/aspnet"; // Get the Web application configuration object. Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath); // Get the section related object. AuthorizationSection configSection = (AuthorizationSection)config.GetSection("system.web/authorization"); // Get the authorization rule collection. AuthorizationRuleCollection authorizationRuleCollection = configSection.Rules; // <Snippet2> // Create a CommaDelimitedStringCollection object. CommaDelimitedStringCollection myStrCollection = new CommaDelimitedStringCollection(); // </Snippet2> for (int i = 0; i < authorizationRuleCollection.Count; i++) { if (authorizationRuleCollection.Get(i).Action.ToString().ToLower() == "allow") { // <Snippet3> // Add values to the CommaDelimitedStringCollection object. myStrCollection.AddRange( authorizationRuleCollection.Get(i).Users.ToString().Split( ",".ToCharArray())); // </Snippet3> } } Console.WriteLine("Allowed Users: {0}", myStrCollection.ToString()); // <Snippet4> // Count the elements in the collection. Console.WriteLine("Allowed User Count: {0}", myStrCollection.Count); // </Snippet4> // <Snippet5> // Call the Contains method. Console.WriteLine("Contains 'userName1': {0}", myStrCollection.Contains("userName1")); // </Snippet5> // <Snippet6> // Determine the index of an element // in the collection. Console.WriteLine("IndexOf 'userName0': {0}", myStrCollection.IndexOf("userName0")); // </Snippet6> // <Snippet7> // Call IsModified. Console.WriteLine("IsModified: {0}", myStrCollection.IsModified); // </Snippet7> // <Snippet8> // Call IsReadyOnly. Console.WriteLine("IsReadOnly: {0}", myStrCollection.IsReadOnly); // </Snippet8> Console.WriteLine(); Console.WriteLine("Add a user name to the collection."); // <Snippet9> // Insert a new element in the collection. myStrCollection.Insert(myStrCollection.Count, "userNameX"); // </Snippet9> Console.WriteLine("Collection Value: {0}", myStrCollection.ToString()); Console.WriteLine(); Console.WriteLine("Remove a user name from the collection."); // <Snippet10> // Remove an element of the collection. myStrCollection.Remove("userNameX"); // </Snippet10> Console.WriteLine("Collection Value: {0}", myStrCollection.ToString()); // Display and wait Console.ReadLine(); }