private ISyntaxNode GetConceptFromPropertyBinding(ISyntaxNodeViewModel conceptViewModel)
        {
            if (conceptViewModel.Owner == null)
            {
                return(conceptViewModel.SyntaxNode); // it is syntax tree root node
            }
            ISyntaxNodeViewModel parentNode = conceptViewModel.Owner;
            string      propertyBinding     = conceptViewModel.PropertyBinding;
            ISyntaxNode parentConcept       = parentNode.SyntaxNode;

            PropertyInfo property = parentConcept.GetPropertyInfo(propertyBinding);
            IOptional    optional = null;

            if (property.IsOptional())
            {
                optional = (IOptional)property.GetValue(parentConcept);
            }
            ISyntaxNode concept = null;

            if (optional == null)
            {
                concept = (ISyntaxNode)property.GetValue(parentConcept);
            }
            else if (optional.HasValue)
            {
                concept = (ISyntaxNode)optional.Value;
            }
            return(concept);
        }
示例#2
0
        public static ISyntaxNode CreateRepeatableConcept(Type repeatable, ISyntaxNode parent, string propertyName)
        {
            ISyntaxNode concept = (ISyntaxNode)Activator.CreateInstance(repeatable);

            concept.Parent = parent;

            IList        list;
            PropertyInfo property = parent.GetPropertyInfo(propertyName);

            if (property.IsOptional())
            {
                IOptional optional = (IOptional)property.GetValue(parent);
                list = (IList)optional.Value;
                if (list == null)
                {
                    Type listType = property.PropertyType.GetProperty("Value").PropertyType;
                    list           = (IList)Activator.CreateInstance(listType);
                    optional.Value = list;
                }
            }
            else
            {
                list = (IList)property.GetValue(parent);
                if (list == null)
                {
                    Type listType = property.PropertyType;
                    list = (IList)Activator.CreateInstance(listType);
                    property.SetValue(parent, list);
                }
            }
            list.Add(concept);
            return(concept);
        }
示例#3
0
        public static bool IsAssemblyReference(this ISyntaxNode @this, string propertyName)
        {
            if (string.IsNullOrWhiteSpace(propertyName))
            {
                throw new ArgumentNullException(propertyName);
            }
            PropertyInfo property = @this.GetPropertyInfo(propertyName);

            if (property == null)
            {
                throw new ArgumentOutOfRangeException(propertyName);
            }
            return(property.PropertyType == typeof(Assembly));
        }
        private void InitializeSelectorViewModel(ISyntaxNodeViewModel selectorViewModel)
        {
            ISyntaxNodeViewModel parentNode = selectorViewModel.Owner;
            string       propertyBinding    = selectorViewModel.PropertyBinding;
            ISyntaxNode  parentConcept      = parentNode.SyntaxNode;
            PropertyInfo property           = parentConcept.GetPropertyInfo(propertyBinding);

            IOptional optional = null;

            if (property.IsOptional())
            {
                optional = (IOptional)property.GetValue(parentConcept);
            }
            object propertyValue = null;

            if (optional == null)
            {
                propertyValue = property.GetValue(parentConcept);
            }
            else if (optional.HasValue)
            {
                propertyValue = optional.Value;
            }
            if (propertyValue is Assembly)
            {
                selectorViewModel.SyntaxNode     = parentConcept;
                selectorViewModel.SyntaxNodeType = null;
            }
            else if (propertyValue is Type)
            {
                selectorViewModel.SyntaxNode     = null;
                selectorViewModel.SyntaxNodeType = (Type)propertyValue;
            }
            else if (propertyValue is SyntaxNode)
            {
                selectorViewModel.SyntaxNode     = (ISyntaxNode)propertyValue;
                selectorViewModel.SyntaxNodeType = null;
            }
            else
            {
                selectorViewModel.SyntaxNode     = null;
                selectorViewModel.SyntaxNodeType = null;
            }
            _ = ((SelectorViewModel)selectorViewModel).Presentation;
        }
示例#5
0
        public static ISyntaxNode CreateConcept(Type conceptType, ISyntaxNode parent, string propertyName)
        {
            ISyntaxNode concept = (ISyntaxNode)Activator.CreateInstance(conceptType);

            concept.Parent = parent;

            PropertyInfo property = parent.GetPropertyInfo(propertyName);

            if (property.IsOptional())
            {
                IOptional optional = (IOptional)property.GetValue(parent);
                optional.Value = concept;
            }
            else
            {
                property.SetValue(parent, concept);
            }
            return(concept);
        }
        private void InitializeRepeatableViewModel(ISyntaxNodeViewModel repeatableNode)
        {
            ISyntaxNodeViewModel parentNode = repeatableNode.Owner;
            ISyntaxNode          concept    = parentNode.SyntaxNode;
            string propertyBinding          = repeatableNode.PropertyBinding;

            IList        conceptChildren;
            PropertyInfo property = concept.GetPropertyInfo(propertyBinding);

            if (property.IsOptional())
            {
                IOptional optional = (IOptional)property.GetValue(concept);
                if (optional == null || !optional.HasValue)
                {
                    return;
                }
                conceptChildren = (IList)optional.Value;
            }
            else
            {
                conceptChildren = (IList)property.GetValue(concept);
            }
            if (conceptChildren == null || conceptChildren.Count == 0)
            {
                return;
            }
            foreach (var child in conceptChildren)
            {
                if (!(child is SyntaxNode))
                {
                    continue;
                }
                ConceptNodeViewModel conceptViewModel = CreateSyntaxNode(repeatableNode, (ISyntaxNode)child);
                if (conceptViewModel == null)
                {
                    continue;
                }
                repeatableNode.Add(conceptViewModel);
            }
        }
示例#7
0
        public static void SetConceptProperty(ISyntaxNode concept, string propertyName, object value)
        {
            PropertyInfo property = concept.GetPropertyInfo(propertyName);

            if (property == null)
            {
                throw new NullReferenceException($"Property \"{propertyName}\" of the \"{concept.GetType()}\" type is not found!");
            }
            if (property.IsRepeatable())
            {
                throw new InvalidOperationException($"Property \"{propertyName}\" can not be repeatable!");
            }

            if (property.IsOptional())
            {
                IOptional optional = (IOptional)property.GetValue(concept);
                optional.Value = value;
            }
            else
            {
                property.SetValue(concept, value);
            }
        }