예제 #1
0
        public PropertyCarrier GetPropertyForString( SaveFile savefile, string line )
        {
            var commandchain = ExtractCommands( line );
            var current = new PropertyCarrier() { Parent = savefile };

            foreach( var command in commandchain )
            {
                SetCurrentParentFromProperty( current );

                var t = current.Parent.GetType();
                var match = ExtractIndex.Match( command );
                var propertyname = command;
                if( match.Success )
                {
                    propertyname = match.Groups["property"].Captures[0].Value;
                    var indexstring = match.Groups["index"].Captures[0].Value;
                    int index = Int32.Parse( indexstring );
                    current.Index = index;
                }
                else
                    current.Index = null;

                current.Property = t.GetProperty( propertyname, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance );
                if( current.Property == null )
                {
                    current.Error = "Not valid property";
                    return current;
                }
            }
            return current;
        }
예제 #2
0
 public void SetCurrentParentFromProperty( PropertyCarrier carrier )
 {
     if( carrier.Property != null )
     {
         carrier.Parent = carrier.Property.GetValue( carrier.Parent, null );
         if( carrier.Parent is IList && carrier.Index.HasValue )
             carrier.Parent = ( (IList) carrier.Parent )[carrier.Index.Value];
     }
 }