Пример #1
0
 /// <summary>
 /// Constructs a value path with all parameters
 /// </summary>
 /// <param name="type"></param>
 /// <param name="property"></param>
 /// <param name="identifier"></param>
 /// <param name="inner"></param>
 public ValuePath(Type type, PropertyInfo property, string identifier, ValuePath inner)
 {
     this.m_type       = type;
     this.m_property   = property;
     this.m_identifier = identifier;
     this.m_inner      = inner;
 }
Пример #2
0
        /// <summary>
        /// Parses a value path from string in ISO-10303-11 (EXPRESS) format.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static ValuePath Parse(Assembly assembly, string value)
        {
            if (value == null)
            {
                return(null);
            }

            string[] tokens = value.Split(new char[] { '\\' }); //???// don't remove empty entries -- if it ends in backslash, then indicates type identifier

            ValuePath rootpath  = null;
            ValuePath outerpath = null;

            foreach (string token in tokens)
            {
                ValuePath valuepath = new ValuePath();

                string[] parts = token.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length >= 1)
                {
                    foreach (Type t in assembly.GetTypes())
                    {
                        if (parts[0] == t.Name)
                        {
                            valuepath.Type = t;
                            break;
                        }
                    }

                    if (valuepath.Type != null && parts.Length == 2)
                    {
                        string propname = parts[1];
                        int    bracket  = propname.IndexOf('[');
                        if (bracket >= 0)
                        {
                            string content  = propname.Substring(bracket + 1, propname.Length - bracket - 2);
                            int    position = 0;
                            if (content.StartsWith("'") && content.EndsWith("'"))
                            {
                                // indexed by name
                                valuepath.Identifier = content.Substring(1, content.Length - 2);
                            }
                            else if (content.StartsWith("\"") && content.EndsWith("\""))
                            {
                                // indexed by name
                                valuepath.Identifier = content.Substring(1, content.Length - 2);
                            }
                            else if (Int32.TryParse(content, out position))
                            {
                                valuepath.Position = new Int32[] { position };
                            }
                            else if (content.StartsWith("@"))
                            {
                                // indexed by parameter for each line, e.g. value identifies column by name when importing/exporting spreadsheet
                                valuepath.Identifier = content;
                            }
                            else if (content.Length == 0)
                            {
                                valuepath.Vector = true;
                            }
                            else if (content == "*")
                            {
                                // do nothing
                            }
                            else
                            {
                                // assume string but without quites
                                valuepath.Identifier = content;
                            }

                            propname = propname.Substring(0, bracket);
                        }

                        valuepath.Property = valuepath.Type.GetProperty(propname);
                    }
                }

                // chain
                if (outerpath != null)
                {
                    outerpath.InnerPath = valuepath;
                }
                else
                {
                    rootpath = valuepath;
                }

                outerpath = valuepath;
            }

            // avoid empty head link
            if (rootpath.Type == null && rootpath.Property == null && rootpath.InnerPath != null)
            {
                rootpath = rootpath.InnerPath;
            }

            return(rootpath);
        }
Пример #3
0
        protected void SetValue(string path, object value)
        {
            ValuePath valpath = ValuePath.Parse(this._target.GetType().Assembly, path);

            valpath.SetValue(this._target, value, null);
        }
Пример #4
0
        protected object GetValue(string path)
        {
            ValuePath valpath = ValuePath.Parse(this._target.GetType().Assembly, path);

            return(valpath.GetValue(this._target, null));
        }