Beispiel #1
0
        private void ParseTag(IEnumerable <string> tag)
        {
            var chars = tag.First().SkipWhile(c => c == ' ' || c == '<').TakeWhile(c => char.IsLetter(c));

            NodeName = new string(chars.ToArray());

            Regex attributes = new Regex("[ ,\t]{1}[a-z,A-Z,0-9]{1,}[ ]{0,}[=]{1}[ ]{0,}[\"]{1}[a-z,A-Z,0-9,_ ]{0,}[\"]{1}");

            System.Text.StringBuilder tagStr = new System.Text.StringBuilder();

            foreach (string str in tag)
            {
                tagStr.Append($" {str.Trim('\n')} ");
            }

            IEnumerable <string> attr = attributes.Matches(tagStr.ToString()).Select(m => m.Value);

            foreach (string attribute in attr)
            {
                string[] parts = attribute.Split('=');
                ObjectProperties.Add(parts[0].Trim(), parts[1].Trim().Trim('"'));
            }

            attributes = new Regex("[a-z,A-Z,0-9]{1,}[:]{1}[a-z,A-Z,0-9]{1,}[ ]{0,}[=]{1}[ ]{0,}[\"]{1}[a-z,A-Z,0-9]{0,}[\"]{1}");

            attr = attributes.Matches(tagStr.ToString()).Select(m => m.Value);

            foreach (string attribute in attr)
            {
                string[] parts = attribute.Split('=');
                AttachedProperties.Add(parts[0], parts[1].Trim('"'));
            }
        }
        /// <summary>
        /// Adds the DependencyPropertyInfo object for the given.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="typeInfo">The type info.</param>
        /// <param name="dependencyProperty">The dependency property.</param>
        /// <param name="propertyName">Name of the dependency property.</param>
        /// <param name="propertyList">The non-attached dependency property list for the given type.</param>
        private static void AddDependencyPropertyInfo(
            Type type,
            TypeInfo typeInfo,
            DependencyProperty dependencyProperty,
            string propertyName,
            ref List <DependencyPropertyInfo> propertyList)
        {
            try
            {
                bool?isAttached = null;

                // Check for plain property matching the dependency property.
                if (typeInfo.GetDeclaredProperty(propertyName) == null)
                {
                    isAttached = true;
                }
                else
                {
                    // Check for the Get method typically only specified for attached properties
                    var getMethodName = string.Format("Get{0}", propertyName);
                    var getMethod     = typeInfo.GetDeclaredMethod(getMethodName);

                    if (getMethod != null)
                    {
                        isAttached = true;
                    }
                    else
                    {
                        isAttached = false;
                    }
                }

                if (isAttached == true)
                {
                    // Attached property
                    var displayName = string.Format("{0}.{1}", type.Name, propertyName);

                    AttachedProperties.Add(
                        new DependencyPropertyInfo(
                            dependencyProperty,
                            propertyName,
                            type,
                            displayName,
                            true));
                }
                else
                {
                    // non-attached property
                    if (propertyList == null)
                    {
                        propertyList = new List <DependencyPropertyInfo>();
                        DependencyProperties.Add(type, propertyList);
                    }

                    propertyList.Add(
                        new DependencyPropertyInfo(
                            dependencyProperty,
                            propertyName,
                            type,
                            propertyName,
                            false));
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }