Esempio n. 1
0
        private static Action <object, object> createSourceSetter(Type oneSideType, Type manySideType)
        {
            var valueSetMethod = manySideType.GetProperties()
                                 .Single(p => MultiReference.IsReal(p) && MultiReference.SourceType(p) == oneSideType)
                                 .SetMethod;

            return(TableInfo.BuildSetAccessor(valueSetMethod));
        }
Esempio n. 2
0
        public void CreateReaders()
        {
            if (this.lines == null)
            {
                throw new InvalidOperationException();
            }

            int i = 0;

            foreach (string[] lin in lines)
            {
                if (types[i] == typeof(object))
                {
                    continue;
                }

                defs.Add(types[i], lin[2]);
                string[] entries = lin[2].Split(',');
                var      array   = this[types[i]] = new FieldReader[entries.Length];
                for (int k = 0; k < entries.Length; k++)
                {
                    string[] parts = entries[k].Split(' ');
                    if (parts[0].StartsWith("ref"))
                    {
                        var referencedType = types[Int32.Parse(parts[0].Remove(0, 3))];
                        if (referencedType == typeof(object))
                        {
                            array[k] = new EmptyReader(sizeof(int));
                        }
                        else
                        {
                            array[k] = new ForeignKeyReader(dbm, referencedType)
                            {
                                Name = parts[1]
                            }
                        };
                    }
                    else if (parts[0].StartsWith("sub="))
                    {
                        //array[k] = new MultiKeyReader(dbm, types[Int32.Parse(parts[0].Remove(0, 4))]);
                        Type referencedType = types[Int32.Parse(parts[0].Remove(0, 4))];
                        if (referencedType == typeof(object))
                        {
                            array[k] = new EmptyReader(2 * sizeof(int));
                        }
                        else
                        {
                            array[k] = (FieldReader)Activator.CreateInstance(typeof(MultiKeyReader <>).MakeGenericType(referencedType), dbm);
                            try
                            {
                                array[k].Name = types[i].GetProperties()
                                                .SingleOrDefault(p => MultiReference.IsReal(p) &&
                                                                 MultiReference.SourceType(p) == array[k].Type).Name;
                            }
                            catch (Exception e) { array[k].Name = "unknown"; }
                        }
                    }
                    else
                    {
                        array[k] = new ColumnReader(dbm, parts[0])
                        {
                            Name = parts[1]
                        };
                    }
                }
                i++;
            }
            this.lines = null;
        }