示例#1
0
        public static ObjectViewParameterLoader TryCreate(
            MetadataObjectView view,
            string name)
        {
            MetadataVirtualProperty metadataVirtualProperty = view.VirtualProperties.Find(name);

            if (metadataVirtualProperty == null)
            {
                return((ObjectViewParameterLoader)null);
            }
            MemberValueGetter memberValueGetter = metadataVirtualProperty.RefMemberType != MetadataClassMember.ObjectView ? (MemberValueGetter) new PropertyValueGetter(metadataVirtualProperty.RefMemberName) : (MemberValueGetter) new ObjectViewTextGetter(metadataVirtualProperty.RefMemberName);

            if (metadataVirtualProperty.SourceMember is MetadataAssociation sourceMember)
            {
                return((ObjectViewParameterLoader) new ObjectViewVirtualPropertyLoader(new Navigator[1]
                {
                    (Navigator) new AssociationNavigator(sourceMember.Property.Name, (MetadataClass)null)
                }, memberValueGetter, ObjectViewVirtualPropertyLoader.ValueCardinality.Single));
            }
            if (!(metadataVirtualProperty.SourceMember is MetadataChildRef sourceMember))
            {
                return((ObjectViewParameterLoader) new ObjectViewVirtualPropertyLoader(Navigator.ParseNavigation(view.Class, metadataVirtualProperty.SourceNavigation), memberValueGetter, ObjectViewVirtualPropertyLoader.ValueCardinality.Multiple));
            }
            return((ObjectViewParameterLoader) new ObjectViewVirtualPropertyLoader(new Navigator[1]
            {
                (Navigator) new ChildRefNavigator(sourceMember.ChildClass)
            }, memberValueGetter, ObjectViewVirtualPropertyLoader.ValueCardinality.Multiple));
        }
 private static int GetOneOf(
     XmlNode node,
     string attrName1,
     string attrName2,
     string attrName3,
     out string value)
 {
     if (MetadataVirtualProperty.TryGetNotEmptyAttribute(node, attrName1, out value))
     {
         return(1);
     }
     if (MetadataVirtualProperty.TryGetNotEmptyAttribute(node, attrName2, out value))
     {
         return(2);
     }
     return(MetadataVirtualProperty.TryGetNotEmptyAttribute(node, attrName3, out value) ? 3 : 0);
 }
        internal MetadataVirtualProperty(MetadataObjectView view, XmlNode sourceNode)
        {
            this.View       = view;
            this.SourceNode = sourceNode;
            this.Name       = XmlUtils.NeedAttr(sourceNode, "name");
            string str;

            switch (MetadataVirtualProperty.GetOneOf(sourceNode, "association", "aggregation", "navigation", out str))
            {
            case 1:
                this.SourceMember = (object)view.Class.Associations.Need(str);
                break;

            case 2:
                this.SourceMember = (object)view.Class.Childs.Need(str);
                break;

            case 3:
                this.SourceNavigation = XmlUtils.GetAttr(sourceNode, "navigation", (string)null);
                break;

            default:
                throw new MetadataException(string.Format("Не заданы атрибуты \"association\" или \"aggregation\" или \"navigation\" ({0})", (object)this));
            }
            switch (MetadataVirtualProperty.GetOneOf(sourceNode, "ref-property", "ref-view", (string)null, out this.RefMemberName))
            {
            case 1:
                this.RefMemberType = MetadataClassMember.Property;
                break;

            case 2:
                this.RefMemberType = MetadataClassMember.ObjectView;
                break;

            default:
                this.RefMemberType = MetadataClassMember.ObjectView;
                this.RefMemberName = "default";
                break;
            }
        }