コード例 #1
0
        public static T CreateType<T>(string line, string[] headersEn, string[] headersRu, Type type)
        {
            string[] lines = GetSplitString(line);
            T obj = (T)Activator.CreateInstance(type);
            PropertyInfo[] props = obj.GetType().GetProperties();

            foreach (var prop in props)
            {
                for (int i = 0; i < lines.Length; i++)
                {
                    if (prop.Name == headersEn[i])
                    {
                        string sprop = lines[i].Trim();

                        if (prop.PropertyType.IsEnum)
                        {
                            Enum eprop = TypeObject.GetTypeObject(sprop);
                            prop.SetValue(obj, Convert.ChangeType(eprop, prop.PropertyType));
コード例 #2
0
        public static List<T> GetObjects<T>(string filename, Dictionary<string, string> headRuEn) where T : IGetTypeObject
        {
            List<T> listT = new List<T>();

            var lines = File.ReadAllLines(filename, Encoding.Default).ToList();
            var headersRus = lines.First();
            string[] headersRu = GetSplitString(headersRus);
            lines.RemoveAt(0);
            string[] headersEn = ReadFile.GetEnHeaders(headersRus, headRuEn);

            foreach (var line in lines)
            {
                Type type = TypeObject.GetTypeObject(line, headersEn);
                if (type != null)
                {
                    T obj = ReadFile.CreateType<T>(line, headersEn, headersRu, type);
                    obj.GetTypeObject = TypeObject.GetTypeObject;
                    listT.Add(obj);
                }
            }
            return listT;
        }