示例#1
0
        public static List <AttributeItem> GetAttributeValue(IEnumerable <CsEntityAttribute> pList, string pAttrName)
        {
            List <AttributeItem> items = new List <AttributeItem>();

            if (pList == null)
            {
                return(items);
            }

            foreach (CsEntityAttribute attribute in pList)
            {
                string s;
                if (attribute.decl != null)
                {
                    CsNamespaceOrTypeName n = (CsNamespaceOrTypeName)attribute.decl.attribute_name;
                    s = n.identifier.original_text;
                }
                else if (attribute.type.parent != null && attribute.type.parent is CsEntityClass)
                {
                    s = attribute.type.parent.name;
                }
                else
                {
                    continue;
                }

                if (!s.Equals(pAttrName, StringComparison.Ordinal) && !(s + "Attribute").Equals(pAttrName, StringComparison.Ordinal))
                {
                    continue;
                }

                AttributeItem item = new AttributeItem();

                if (attribute.fixed_arguments != null)
                {
                    foreach (var argument in attribute.fixed_arguments)
                    {
                        string strval = argument.value as string;
                        item.Parameters.Add(string.IsNullOrEmpty(strval) ? argument.value : convertString(strval));
                    }
                }

                if (attribute.named_arguments != null)
                {
                    foreach (var argument in attribute.named_arguments)
                    {
                        item.NamedArguments.Add(argument.entity.name,
                                                new Expression(convertString(argument.value.ToString()), argument.type));
                    }
                }

                items.Add(item);
            }

            return(items);
        }
示例#2
0
		public static List<AttributeItem> GetAttributeValue(IEnumerable<CsEntityAttribute> pList, string pAttrName) {
			List<AttributeItem> items = new List<AttributeItem>();

			if (pList == null) {
				return items;
			}

			foreach (CsEntityAttribute attribute in pList) {
				string s;
				if (attribute.decl != null) {
					CsNamespaceOrTypeName n = (CsNamespaceOrTypeName)attribute.decl.attribute_name;
					s = n.identifier.original_text;
				} else if (attribute.type.parent != null && attribute.type.parent is CsEntityClass) {
					s = attribute.type.parent.name;
				} else {
					continue;
				}

				if (!s.Equals(pAttrName, StringComparison.Ordinal) && !(s + "Attribute").Equals(pAttrName, StringComparison.Ordinal)) {
					continue;
				}

				AttributeItem item = new AttributeItem();

				if (attribute.fixed_arguments != null) {
					foreach (var argument in attribute.fixed_arguments) {
						string strval = argument.value as string;
						item.Parameters.Add(string.IsNullOrEmpty(strval) ? argument.value : convertString(strval));
					}
				}

				if (attribute.named_arguments != null) {
					foreach (var argument in attribute.named_arguments) {
						item.NamedArguments.Add(argument.entity.name,
						                        new Expression(convertString(argument.value.ToString()), argument.type));
					}
				}

				items.Add(item);
			}

			return items;
		}
示例#3
0
		private static List<AttributeItem> getAttributeValue(CsAttribute pAttribute, string pAttrName, FactoryExpressionCreator pCreator) {
			string s;
			AttributeItem item = new AttributeItem();

			if (pAttribute.attribute_name != null) {
				CsNamespaceOrTypeName n = (CsNamespaceOrTypeName)pAttribute.attribute_name;
				s = n.identifier.original_text;
			} else {
				throw new Exception();
				//s = attribute.type.parent.name;
			}

			if (s.Equals(pAttrName, StringComparison.Ordinal) || (s + "Attribute").Equals(pAttrName, StringComparison.Ordinal)) {
				item.IsEmpty = false;
				foreach (var argument in pAttribute.positional_argument_list.list) {
					item.Parameters.Add(((CsLiteral)argument).literal);
				}

				foreach (var argument in pAttribute.named_argument_list) {
					item.NamedArguments.Add(argument.identifier.identifier, pCreator.Parse(argument.expression));
				}
			}

			return new List<AttributeItem> {item};
		}