示例#1
0
        public PropertyPrototype(XmlElement node) : base(node)
        {
            Name = node.Name;
            if (node.HasAttribute("bind"))
            {
                Kind = PropertyPrototypeKind.BindValue;
                Path = new BindingPath(node.GetAttribute("bind"));
            }
            else if (node.HasAttribute("object"))
            {
                Kind = PropertyPrototypeKind.AssignFrom;
                Path = new BindingPath(node.GetAttribute("object"));
            }
            else
            {
                Kind = PropertyPrototypeKind.TextRepresentation;
                var typeHintValue =
                    node.GetAttributeNode("type")?.Value ??
                    node.GetAttributeNode("class")?.Value;
                TypeHint = typeHintValue != null?GenReflection.GetRWType(typeHintValue) : null;

                Value     = node.InnerText;
                Translate = node.GetAttribute("translate").ToLowerInvariant() == "true";
            }
        }
示例#2
0
        public BindingPrototype(XmlElement x)
        {
            var src = x.GetAttribute("object");

            Source = new BindingPath(src);

            var dst = x.GetAttribute("to");

            Target = new BindingPath(dst);

            if (Target.Member == null)
            {
                throw new FormatException($"{dst} is invalid target object path");
            }
        }
示例#3
0
        /// <summary>
        /// Reads the value at provided path
        /// </summary>
        /// <param name="path">path</param>
        /// <param name="objects">id to object map</param>
        /// <returns>value read</returns>
        internal static object ReadObject(BindingPath path, Dictionary <string, object> objects)
        {
            object obj = objects[path.Object];

            if (path.Member != null)
            {
                var srcProp = obj.GetType().GetMember(path.Member, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static).FirstOrDefault();
                if (srcProp != null)
                {
                    obj = srcProp.GetValue(obj);
                }
                else
                {
                    throw new InvalidOperationException($"object {obj} with id \"{path.Object}\" have no property \"{path.Member}\"");
                }
            }
            return(obj);
        }