示例#1
0
        public void AddProp(string name, int col)
        {
            if (parsers.ContainsKey(name))
            {
                throw new PropertyException("Allready constains a property with that name");
            }
            if (!Array.Exists(pi, p => p.Name == name))
            {
                throw new PropertyException($"No such property found in {type.Name}");
            }

            CsvBasicInfo    bInfo    = new CsvBasicInfo(type, name, col, separator);
            PropertyInfo    pInfo    = type.GetProperty(name);
            Type            propType = pInfo.PropertyType;                      // prop Type
            PropertyWrapper pw;
            IReflection     reflect;

            if (ReflectorsCache.cache.TryGetValue(propType, out reflect))
            {
                // if reflect of type propType exists, get it from cache
                pw = new PropertyWrapper((PropertyReflect)reflect, bInfo);
                parsers.Add(name, pw);
            }
            else
            {
                //if not build a new onde, add to cache and create PropertyWrapper
                //and add it to parsers Dictionary
                PropertyReflect pr = new PropertyReflect(propType);
                ReflectorsCache.cache.Add(propType, pr);
                pw = new PropertyWrapper(pr, bInfo);
                parsers.Add(name, pw);
            }
        }
示例#2
0
        public void AddField(string name, int col)
        {
            if (parsers.ContainsKey(name))
            {
                throw new FieldException("allready constains a field with that name");
            }
            if (!Array.Exists(fi, f => f.Name == name))
            {
                throw new FieldException($"No such field found in {type.Name}");
            }

            CsvBasicInfo bInfo     = new CsvBasicInfo(type, name, col, separator);
            FieldInfo    fInfo     = type.GetField(name);
            Type         fieldType = fInfo.FieldType;                           // prop Type
            FieldWrapper fw;
            IReflection  reflect;

            if (ReflectorsCache.cache.TryGetValue(fieldType, out reflect))
            {
                fw = new FieldWrapper((FieldReflect)reflect, bInfo);
                parsers.Add(name, fw);
            }
            else
            {
                FieldReflect fr = new FieldReflect(fieldType);
                ReflectorsCache.cache.Add(fieldType, fr);
                fw = new FieldWrapper(fr, bInfo);
                parsers.Add(name, fw);
            }
        }
示例#3
0
        /**
         * this method will set all properties and fields values in src object with the values of data
         * */
        public void SetFieldAndPropertiesValues(object src, string data)
        {
            foreach (KeyValuePair <string, IParserWrapper> pw in parsers)
            {
                IParserWrapper parser    = pw.Value;
                string         name      = pw.Key;
                CsvBasicInfo   bInfo     = parser.GetBasicInfo();
                string[]       arrayData = data.Split(bInfo.Separator);

                parser.SetValue(arrayData, src);
            }
        }
示例#4
0
 public FieldWrapper(FieldReflect fReflect, CsvBasicInfo csvInfo)
 {
     this.fReflect = fReflect;
     this.csvInfo  = csvInfo;
 }
示例#5
0
 public PropertyWrapper(PropertyReflect pReflect, CsvBasicInfo csvInfo)
 {
     this.pReflect = pReflect;
     this.csvInfo  = csvInfo;
 }