コード例 #1
0
        public static List <T> ProvideFromFile(string defFileName)
        {
            DefinationReader dr = new DefinationReader(defFileName);

            dr.Read();
            List <T> list = new List <T>();
            Type     t    = typeof(T);

            if (t == null)
            {
                throw new TypeLoadException(String.Format("Cannot find Type {0}", t.ToString()));
            }

            foreach (var section in dr.Sections)
            {
                T tInstance = t.Assembly.CreateInstance(t.ToString()) as T;
                if (tInstance == null)
                {
                    throw new TypeLoadException(String.Format("Create Type {0} failed", t.ToString()));
                }

                // Set the property value to the instance of T
                //
                foreach (PropertyInfo property in t.GetProperties())
                {
                    // Get DefinationKey attribute
                    //
                    DefinationKeyAttribute dkattr = property.GetCustomAttributes(typeof(DefinationKeyAttribute)).FirstOrDefault() as DefinationKeyAttribute;
                    if (dkattr != null)
                    {
                        // get value in
                        //
                        if (section.ContainsKey(dkattr.Name))
                        {
                            string value = section[dkattr.Name];
                            property.SetValue(tInstance, value);
                        }
                    }
                }

                ModelBase mb = tInstance as ModelBase;
                mb.PrepareProperties();

                list.Add(tInstance);
            }

            return(list);
        }
コード例 #2
0
        public void TestUnityBuiltInValues()
        {
            string defFileName = "Data\\Unity3D_values.def";
            DefinationReader dr = new DefinationReader(defFileName);
            dr.Read();
            Console.WriteLine(dr.Sections.Count);

            var dataList = DefinationDataProvider<UnityBuiltinValue>.ProvideFromFile(defFileName);
            Console.WriteLine(dataList.Count);

            foreach (var val in dataList)
            {
                Console.WriteLine("-----------------Values--------------------");
                Console.WriteLine("Name={0}", val.Name);
                Console.WriteLine("Type={0}", val.Type);
                Console.WriteLine("Description={0}", val.VauleDescription);
            }

        }
コード例 #3
0
        public void ParseTest()
        {
            DefinationReader dr = new DefinationReader("Data\\test.def");
            dr.Read();
            StringBuilder sb = new StringBuilder();
            foreach (var section in dr.Sections)
            {
                Console.WriteLine("-----------------Sections--------------------");
                sb.AppendLine("-----------------Sections--------------------");
                foreach (var pair in section)
                {
                    Console.WriteLine("({0})=({1})", pair.Key, pair.Value);
                    sb.AppendLine(string.Format("({0})=({1})", pair.Key, pair.Value));
                }
            }

            string result = sb.ToString();
            Assert.IsTrue(result.Contains(@"(Name)=(abs)"));
            Assert.IsTrue(result.Contains(@"(Synopsis)="));
            Assert.IsTrue(result.Contains(@"(returns absolute value of scalars and vectors.)"));
            Assert.IsTrue(result.Contains(@"(Escape#Chars)=(\#=>#, \$=>$, \{=>{, \}=}, \==>=, \%=>%)"));
        }