private void databinding(List<RFDeviceAPP.Common.NSPRFIQ01.Response.UtilityHeader> list)
 {
     this.dataGridTableStyle1.MappingName = list.GetType().Name;
     this.dataGrid1.TableStyles.Clear();
     this.dataGrid1.TableStyles.Add(this.dataGridTableStyle1);
     this.dataGrid1.DataSource = list;
 }
Example #2
0
 public void SaveGuitars(List<Guitar> guitars)
 {
     var serializer = new XmlSerializer(guitars.GetType());
     TextWriter tw = new StreamWriter(Path);
     serializer.Serialize(tw, guitars);
     tw.Close();
 }
Example #3
0
 static void Main(string[] args)
 {
     Type guyType = typeof(Guy);
     Console.WriteLine("{0} extends {1}",
     guyType.FullName,
     guyType.BaseType.FullName);
     // output: TypeExamples.Guy extends System.Object
     Type nestedClassType = typeof(NestedClass.DoubleNestedClass);
     Console.WriteLine(nestedClassType.FullName);
     // output: TypeExamples.Program+NestedClass+DoubleNestedClass
     List<Guy> guyList = new List<Guy>();
     Console.WriteLine(guyList.GetType().Name);
     // output: List`1
     Dictionary<string, Guy> guyDictionary = new Dictionary<string, Guy>();
     Console.WriteLine(guyDictionary.GetType().Name);
     // output: Dictionary`2
     Type t = typeof(Program);
     Console.WriteLine(t.FullName);
     // output: TypeExamples.Program
     Type intType = typeof(int);
     Type int32Type = typeof(Int32);
     Console.WriteLine("{0} - {1}", intType.FullName, int32Type.FullName);
     // System.Int32 - System.Int32
     Console.WriteLine("{0} {1}", float.MinValue, float.MaxValue);
     // output:-3.402823E+38 3.402823E+38
     Console.WriteLine("{0} {1}", int.MinValue, int.MaxValue);
     // output:-2147483648 2147483647
     Console.WriteLine("{0} {1}", DateTime.MinValue, DateTime.MaxValue);
     // output: 1/1/0001 12:00:00 AM 12/31/9999 11:59:59 PM
     Console.WriteLine(12345.GetType().FullName);
     // output: System.Int32
     Console.ReadKey();
 }
Example #4
0
    public static void Main (string[] args) {
        var coll = new List<int>() { 5, 25, 50, 125 };
        var arr = coll.ToArray();

        Console.WriteLine("{0} {1}", coll.GetType(), arr.GetType());
        Console.WriteLine("{0} {1}", coll[0].GetType(), arr[0].GetType());
    }
Example #5
0
 public static void DisplayAllWord(List<string> ls)
 {
     Type t = ls.GetType();
     Console.WriteLine("list of {0} contein", t.Name);
     foreach (string s in ls)
         Console.WriteLine(s);
 }
Example #6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (ItemsFile.Exists)
            {
                List<ItemInfo> lst = new List<ItemInfo>();

                XmlSerializer xml = new XmlSerializer(lst.GetType());

                using (Stream s = ItemsFile.OpenRead())
                {
                    lst = xml.Deserialize(s) as List<ItemInfo>;
                }

                foreach (ItemInfo item in lst)
                {
                    CalendarItem cal = new CalendarItem(calendar1, item.StartTime, item.EndTime, item.Text);

                    if (!(item.R == 0 && item.G == 0 && item.B == 0))
                    {
                        cal.ApplyColor(Color.FromArgb(item.A, item.R, item.G, item.B));
                    }

                    _items.Add(cal);
                }

                PlaceItems();
            }
        }
        public List<CombinerModel> ReadData(string fileName)
        {
            List<CombinerModel> list = new List<CombinerModel>();
            object obj = CacheHelper.ReadData(ConstMember.CONFIG_CACHE_ID);

            if (obj == null)
            {
                string strFilePath = GetAbsolutPath(fileName);

                try
                {
                    obj = XMLHelper.LoadFromXml(strFilePath, list.GetType());
                    CacheDependency dep = new CacheDependency(strFilePath);
                    CacheHelper.WriteData(ConstMember.CONFIG_CACHE_ID, dep, obj);
                }
                catch
                {
                }
            }

            if (obj != null && obj is List<CombinerModel>)
            {
                list = obj as List<CombinerModel>;
            }

            return list;
        }
Example #8
0
        static FtpUserStore()
        {
            _users = new List<FtpUser>();

            XmlSerializer serializer = new XmlSerializer(_users.GetType(), new XmlRootAttribute("Users"));

            if (File.Exists("users.xml"))
            {
                _users = serializer.Deserialize(new StreamReader("users.xml")) as List<FtpUser>;
            }
            else
            {
                _users.Add(new FtpUser
                {
                    UserName = "rick",
                    Password = "test",
                    HomeDir = "C:\\Utils"
                });

                using (StreamWriter w = new StreamWriter("users.xml"))
                {
                    serializer.Serialize(w, _users);
                }
            }
        }
        public Course[] GetCourses()
        {
            List<Course> holder = new List<Course>();

            Console.Write(holder.GetType());

            using (SqlConnection conn = new SqlConnection())
            {
                // Create the connectionString
                // Trusted_Connection is used to denote the connection uses Windows Authentication
                conn.ConnectionString = "Data Source=tfs;Initial Catalog=study3;Integrated Security=True";
                conn.Open();
                // Create the command
                SqlCommand command = new SqlCommand("SELECT * FROM db_owner.course", conn);
                //// Add the parameters.
                //command.Parameters.Add(new SqlParameter("0", 1));

                // Use a SqlDataReader to read the results from the SqlCommand
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    foreach (IDataRecord record in reader)
                    {
                        string[] dataRow = ReadSingleRow((IDataRecord)reader);

                        //Course courseHolder = new Course(dataRow);

                        //holder.Add(courseHolder);
                    }
                }
            }

            Course[] returnCourseArray = holder.ToArray();

            return returnCourseArray;
        }
Example #10
0
        private static void CreateSampleQueries()
        {
            var queries = new List<Query>
                              {
                                  new Query
                                      {
                                          OrderBy = "Id",
                                          OutputFileName = "Result0.xml",
                                          WhereClauses = new List<WhereClause>
                                              {
                                                  new WhereClause
                                                      {
                                                          PropertyName = "City",
                                                          Type = "Equals",
                                                          Value = "Sofia"
                                                      },
                                                    new WhereClause
                                                        {
                                                            PropertyName = "Year",
                                                            Type = "GreaterThan",
                                                            Value = "1999"
                                                        }
                                              }
                                      }
                              };

            var serializer = new XmlSerializer(queries.GetType(), new XmlRootAttribute("Queries"));

            using (var fs = new FileStream("Queries.xml", FileMode.Create))
            {
                serializer.Serialize(fs, queries);
            }
        }
Example #11
0
    static void Main(string[] args)
    {
      // Use var for an array.
      // Note the use of the new implicitly typed array syntax.
      // The compiler looks at the initialization list and infers that the
      // array type you want is int[].
      var numbers = new[] { 1, 2, 3 };
      Console.WriteLine("Array initializer: ");
      foreach (int n in numbers)
      {
        Console.WriteLine(n.ToString());
      }
      // This writes "System.Int32[]".
      Console.WriteLine(numbers.GetType().ToString());
      Console.WriteLine();

      // Use var for a generic list type.
      // Note the use of the new collection initializer syntax, too.
      var names = new List<string> { "Chuck", "Bob", "Steve", "Mike" };
      Console.WriteLine("List of names: ");
      foreach (string s in names)
      {
        Console.WriteLine(s);
      }
      // This writes "System.Collections.Generic.List`1[System.String]".
      // Note that the compiler calls any List<T> a List`1.
      // To look up List<T> in the documentation, specify "List<T>".
      Console.WriteLine(names.GetType().ToString());
      Console.WriteLine();

      // Wait for user to acknowledge results.
      Console.WriteLine("Press Enter to terminate...");
      Console.Read();
    }
Example #12
0
        /// <summary>
        /// 通过文件名获取配置
        /// </summary>
        /// <param name="fileName">配置文件名不带后缀的</param>
        /// <returns></returns>
        public static List<VarItem> Load(string fileName) {

            //如果缓存里面有这个配置就直接返还
            if (dataCache.ContainsKey(fileName)&& dataCache[fileName] != null)
                return dataCache[fileName];

            //如果缓存里没这个配置就第一次读取
            string path = GetDefaultConfigPath(fileName);

            //校验是路径是否有效
            if (File.Exists(path) == false)
                throw new FileNotFoundException("文件没找到", path);

            //读取
            List<VarItem> items = new List<VarItem>();
            XmlSerializer xmlSerializer = new XmlSerializer(items.GetType());
            FileStream fs = new FileStream(path, FileMode.Open);
            using (fs) {
                try {
                    items = xmlSerializer.Deserialize(fs) as List<VarItem>;
                }
                catch (InvalidOperationException ex) {
                    throw ;
                }
            }

            //如果配置没有内容可能会读到空的items,不过这是允许的。
            dataCache.Add(fileName, items);

            return items;
        }
Example #13
0
        public void LogNameDisplaysReadablyGenerics()
        {
            var subject = new List<int>();
            var logger = new Log4NetLogger(subject.GetType());
            logger.Name.Should().Be("List<Int32>");

        }
Example #14
0
        /// <summary>
        /// MA: moving average
        /// An often used helper method which take in a list of values (of consecutive
        /// days) and calculates the moving average
        /// </summary>
        /// <param name="values">a list of certain length of values of different dates</param>
        /// <returns>MA</returns>
        public static double[] MACalculator(List<double> values)
        {
            double[] resultArray = new double[6];
            double sum = 0.0;
            int days = 0;

            if (values.Count >= 250)
            {
                for (int i = 0; i <= 249; i++)
                {
                    sum += values[i];
                    if (values.GetType().Name != "DBNull")
                        days++;

                    if (i == 4) resultArray[0] = sum / days;
                    else if (i == 9) resultArray[1] = sum / days;
                    else if (i == 19) resultArray[2] = sum / days;
                    else if (i == 59) resultArray[3] = sum / days;
                    else if (i == 119) resultArray[4] = sum / days;
                    else if (i == 249) resultArray[5] = sum / days;
                }
            }
            else
            {
                Console.WriteLine("data not available, needs to wait for 250 days");
            }

            return resultArray;
        }
Example #15
0
 public void SaveAmplifiers(List<Amplifier> amplifiers)
 {
     var serializer = new XmlSerializer(amplifiers.GetType());
     TextWriter tw = new StreamWriter(@"d:\guitarweb\amplifiers.xml");
     serializer.Serialize(tw, amplifiers);
     tw.Close();
 }
        /// <summary>
        /// Loads the highscores from isolated storage
        /// </summary>
        static public void Load()
        {
            scores = new List<HighscoreItem>();
            IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();

            // Create empty list if the highscores file does not exist.
            // This is needed when the application is started for the first time.
            if (!store.FileExists(highscoresFilename))
            {
                for (int i = 1; i <= 20; i++)
                {
                    scores.Add(new HighscoreItem(i, "Sudokumaster",
                        new TimeSpan(0, 59, 59), 100));
                }
                Save();
                return;
            }

            // Open the file and use XmlSerializer to deserialize the xml file into
            // a list of HighscoreItems.
			using (IsolatedStorageFileStream stream = store.OpenFile(highscoresFilename, FileMode.Open))
			{
				using (StreamReader reader = new StreamReader(stream))
				{
					XmlSerializer serializer = new XmlSerializer(scores.GetType());
					scores = (List<HighscoreItem>)serializer.Deserialize(reader);
				}
			}
        }
Example #17
0
 /// <summary>
 /// Чтение статистики для страницы из файла
 /// </summary>
 /// <param name="url">URL страницы, для которой эта статистика</param>
 /// <param name="directory">Папка сохранения логов</param>
 /// <returns>Список статистики для страницы в случае удачи, или null в случае неудачи</returns>
 public static List<Stat> LoadListFromFile(string url, string directory)
 {
     List<Stat> myList = new List<Stat>();
     try
     {
         if (Directory.Exists(directory))
         {
             if (File.Exists(directory + @"\" + url.GetHashCode().ToString() + @".log"))
             {
                 XmlSerializer XmlSer = new XmlSerializer(myList.GetType());
                 FileStream Set = new FileStream(directory + @"\" + url.GetHashCode().ToString() + @".log", FileMode.Open);
                 myList = (List<Stat>)XmlSer.Deserialize(Set);
                 Set.Close();
                 return myList;
             }
             else return null;
         }
         else return null;
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message, "Exception loading statistics", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return null;
     }
 }
        public List<TranferLayer> DeserializeXmlFile()
        {
            List<TranferLayer> dataLayers = new List<TranferLayer>();
            try
            {
                XmlSerializer ser = new XmlSerializer(dataLayers.GetType());
                if (!File.Exists(lm.PathToXMLFile))
                    return dataLayers;
                using (XmlReader reader = XmlReader.Create(lm.PathToXMLFile))
                {
                    try
                    {
                        dataLayers = (List<TranferLayer>)ser.Deserialize(reader);
                    }
                    catch (Exception ex) { }
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return dataLayers;
        }
 public void TypeConverterListBool_CanConvert(object value, bool isConvertable)
 {
     var converter = new TypeConverter<IEnumerable<bool>>();
     var list = new List<bool> {false, true};
     var canConvert = converter.CanConvert(list.GetType());
     Assert.True(canConvert);
 }
Example #20
0
        static UserStore()
        {
            _users = new List<User>();

            XmlSerializer serializer = new XmlSerializer(_users.GetType(), new XmlRootAttribute("Users"));

            if (File.Exists("users.xml"))
            {
                _users = serializer.Deserialize(new StreamReader("users.xml")) as List<User>;
            }
            else
            {
                _users.Add(new User {
                    Username = "rick",
                    Password = "test",
                    HomeDir = "C:\\Utils",
                    //TwoFactorSecret = "1234567890", // Base32 Encoded: gezdgnbvgy3tqojq
                });

                using (StreamWriter w = new StreamWriter("users.xml"))
                {
                    serializer.Serialize(w, _users);
                }
            }
        }
 public void SaveTimesheeets(List<Timesheet> timesheets)
 {
     var serializer = new XmlSerializer(timesheets.GetType());
     using (TextWriter streamWriter = new StreamWriter(Settings.Default.XMLFileName))
     {
         serializer.Serialize(streamWriter, timesheets);
     }
 }
Example #22
0
 public void print(List<string> input)
 {
     Console.WriteLine("Collection: " + input.GetType());
     foreach (var item in input)
     {
         Console.Write("{0}", item);
     }
 }
 public void Save(List<Entree> rank)
 {
     using (FileStream str = File.Create("sav.xml"))
     {
         XmlSerializer bf = new XmlSerializer(rank.GetType());
         bf.Serialize(str, rank);
     }
 }
Example #24
0
 public void Serialize(List<MessageModel> messages, string fileName)
 {
     var serializer = new XmlSerializer(messages.GetType());
     using (var fileStream = new FileStream(fileName, FileMode.Create))
     {
         serializer.Serialize(fileStream, messages);
     }
 }
Example #25
0
        private static Dictionary<string, string> ReadTranslationData()
        {
            List<UserData> userStringList = new List<UserData>();

            XmlSerializer serializer = new XmlSerializer(userStringList.GetType());
            userStringList = (List<UserData>)serializer.Deserialize(XmlReader.Create(SettingsPath));
            return userStringList.ToDictionary(n => n.Tag, n => n.Text.Replace("__BREAK__", Environment.NewLine));
        }
 public void Can_convert_string_list_to_string()
 {
     var items = new List<string> {"foo", "bar", "day"};
     var converter = TypeDescriptor.GetConverter(items.GetType());
     var result = converter.ConvertTo(items, typeof (string)) as string;
     result.ShouldNotBeNull();
     result.ShouldEqual("foo,bar,day");
 }
Example #27
0
 public static List<LinkConfig> GetConfiguration(string name)
 {
     List<LinkConfig> con = new List<LinkConfig>();
     XmlDocument xmlDoc = new XmlDocument();
     xmlDoc.Load(name);
     XmlSerializer ser = new XmlSerializer(con.GetType());
     return (List<LinkConfig>)ser.Deserialize(new StringReader(xmlDoc.InnerXml));
 }
        public void Can_convert_int_list_to_string()
        {
            var items = new List<int> {10, 20, 30, 40, 50};
            var converter = TypeDescriptor.GetConverter(items.GetType());
            var result = converter.ConvertTo(items, typeof (string)) as string;

            result.ShouldNotBeNull();
            result.ShouldEqual("10,20,30,40,50");
        }
 private static List<SystemNotificationPreference> Deserialize(String tbd)
 {
     List<SystemNotificationPreference> l = new List<SystemNotificationPreference>();
     XmlSerializer serializer = new XmlSerializer(l.GetType());
     using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(tbd)))
     {
         return (List<SystemNotificationPreference>)serializer.Deserialize(stream);
     }
 }
 public void AllSongsAcquired(List<GoogleMusicSong> songs)
 {
     var ms = new MemoryStream ();
     var utf8 = System.Text.Encoding.UTF8;
     using (var ifs = IsolatedStorageFile.GetUserStoreForApplication ())
         using (var fs = ifs.CreateFile ("all_songs.lst"))
             new DataContractJsonSerializer (songs.GetType ()).WriteObject (fs, songs.ToArray ());
     this.RunOnUiThread (() => Toast.MakeText (this, "downloaded song list", ToastLength.Short));
 }