Ejemplo n.º 1
0
        private static DataAcessor makeDataAcessor(IGetDataItems data, string name)
        {
            //create a new one
            var prop = data.GetType().GetProperties().Where(P => P.Name == name).FirstOrDefault();

            if (prop != null)
            {
                var acc = prop.GetAccessors(true);
                if (acc.Length == 2)
                {
                    var setter = acc.FirstOrDefault(A => A.Name.StartsWith("set", StringComparison.OrdinalIgnoreCase));
                    var getter = acc.FirstOrDefault(A => A.Name.StartsWith("get", StringComparison.OrdinalIgnoreCase));
                    if (getter != null && setter != null)
                    {
                        //TODO: optimise this code (remove Invoke)
                        return(new DataAcessor(name,
                                               () => getter.Invoke(data, null),
                                               S => setter.Invoke(data, new object[] { S })
                                               ));
                    }
                }
            }

            throw new ArgumentException(string.Format("Could find no property or field called {0} in {1}", name, data.GetType().Name));
        }
Ejemplo n.º 2
0
        public static byte[] writeToBytes(this IGetDataItems item)
        {
            using (MemoryStream ms = new MemoryStream())
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    foreach (string name in item.DataNames)
                    {
                        bw.Write(name);
                        //bw.Write(item.GetDataItem(name));
                    }

                    return(ms.ToArray());
                }
        }
Ejemplo n.º 3
0
        public TestDataGenerator(T item, TestDataLevel level)
        {
            Type          type      = typeof(T);
            IGetDataItems dataItems = item as IGetDataItems;

            if (dataItems != null)
            {
                //values = new Cascader(item.
            }
            else
            {
                T[] testData = GetTestData <T>(level);

                values = new Cascader(new List <IEnumerable> {
                    testData
                });
            }
        }
Ejemplo n.º 4
0
        private static Dictionary <string, DataAcessor> GetDataAcessors(this IGetDataItems data)
        {
            //do acessos already exist
            Dictionary <string, DataAcessor> acessors;

            if (DataAcessorLut.TryGetValue(data, out acessors))
            {
                return(acessors);
            }
            else
            {
                //make all acessors for this type and cache
                acessors = makeDataAcessors(data);
                DataAcessorLut.Add(data, acessors);

                //return the result
                return(acessors);
            }
        }
Ejemplo n.º 5
0
        private static Dictionary <string, DataAcessor> makeDataAcessors(IGetDataItems data)
        {
            Dictionary <string, DataAcessor> acessors = new Dictionary <string, DataAcessor>();

            foreach (var name in data.DataNames)
            {
                var acc = makeDataAcessor(data, name);
                if (acc != null)
                {
                    acessors.Add(name, acc);
                }
                else
                {
                    WDAppLog.LogNeverSupposedToBeHere();
                }
            }

            return(acessors);
        }
Ejemplo n.º 6
0
 public static int HashDataItems(this IGetDataItems data)
 {
     return(Misc.HashItems(data.GetDataItems()));
 }
Ejemplo n.º 7
0
 public static void SetDataItem(this IGetDataItems data, string name, object value)
 {
     data.GetDataAcessor(name).Set(value);
 }
Ejemplo n.º 8
0
 public static void SetDataItem(this IGetDataItems data, int n, object value)
 {
     data.GetDataAcessor(data.DataNames[n]).Set(value);
 }
Ejemplo n.º 9
0
 public static object[] GetDataItems(this IGetDataItems data)
 {
     return((from string D in data.DataNames select GetDataItem(data, D)).ToArray());
 }
Ejemplo n.º 10
0
 public static object GetDataItem(this IGetDataItems data, string name)
 {
     return(data.GetDataAcessor(name).Get());
 }
Ejemplo n.º 11
0
 private static DataAcessor GetDataAcessor(this IGetDataItems data, string name)
 {
     return(data.GetDataAcessors()[name]);
 }