コード例 #1
0
        internal virtual void InitializeFromORTSSpecific(string wagFilePath, object initWhat)
        {
            object[] fattrs;
            if (initWhat == null)
            {
                initWhat = this;
            }
            System.Reflection.MemberInfo info = initWhat.GetType();
            fattrs = Attribute.GetCustomAttributes(info, typeof(ORTSPhysicsFileAttribute), true);

            bool setdef = true;

            foreach (object fattr in fattrs)
            {
                ORTSPhysicsFileAttribute opfa = fattr as ORTSPhysicsFileAttribute;
                STFReader stf     = opfa.OpenSTF(wagFilePath);
                bool      hasFile = stf != null;

                object[] attrs;
                STFReader.TokenProcessor        tp;
                List <STFReader.TokenProcessor> result = new List <STFReader.TokenProcessor>();

                ORTSPhysicsAttribute attr;
                FieldInfo[]          fields = initWhat.GetType().GetFields();
                foreach (FieldInfo fi in fields)
                {
                    attrs = fi.GetCustomAttributes(typeof(ORTSPhysicsAttribute), false);
                    if (attrs.Length > 0)
                    {
                        attr = attrs[0] as ORTSPhysicsAttribute;

                        if (setdef)
                        {
                            fi.SetValue2(initWhat, attr.DefaultValue);
                        }

                        if (hasFile && opfa.FileID == attr.FileID)
                        {
                            AttributeProcessor ap = new AttributeProcessor(initWhat, fi, stf, attr.DefaultValue);
                            tp = new STFReader.TokenProcessor(attr.Token, ap.P);

                            result.Add(tp);
                        }
                    }
                }

                setdef = false;

                if (hasFile)
                {
                    stf.MustMatch(opfa.Token);
                    stf.MustMatch("(");
                    stf.ParseBlock(result.ToArray());
                    stf.Dispose();
                }
            }
        }