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 }); }
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); }
public Expression Parse(CsExpression pStatement, FactoryExpressionCreator pCreator) { CsTypeofExpression ex = (CsTypeofExpression)pStatement; //"typeof" "(" type ")" CsNamespaceOrTypeName isClass = ex.type.type_name as CsNamespaceOrTypeName; if (isClass != null) { return(new Expression(isClass.identifier.identifier, ex.type.entity_typeref)); } throw new NotImplementedException(); }
public static string GetType(CsNamespaceOrTypeName pDirective) { string g = ""; //generics if (pDirective.type_argument_list != null && pDirective.type_argument_list.list.Count != 0) { g += "<"; foreach (CsTypeRef typeRef in pDirective.type_argument_list.list) { g += GetType(typeRef); g += ", "; } g = g.TrimEnd(_paramTrim) + ">"; } string ret = ""; if (pDirective.namespace_or_type_name == null) { if (pDirective.parent is CsTypeRef) { CsTypeRef parent = ((CsTypeRef)pDirective.parent); if (parent.entity_typeref.u is CsEntityClass) { if (IsClassDefinedAsObject(((CsEntityClass)parent.entity_typeref.u).attributes)) { return("object"); } return(((CsEntityClass)parent.entity_typeref.u).name); } if (parent.entity_typeref.type == cs_entity_type.et_generic_param) { return("<" + pDirective.identifier.identifier + ">"); //return "*"; } if (parent.entity_typeref.u is CsEntityInstanceSpecifier) { //if (IsClassDefinedAsObject(((CsEntityInstanceSpecifier)parent.entity_typeref.u))) //return "Object"; } } else if (pDirective.parent is CsUsingNamespaceDirective) { CsUsingNamespaceDirective parent = (CsUsingNamespaceDirective)pDirective.parent; if (parent.namespace_or_type_entity != null) { ret = "." + parent.namespace_or_type_entity.name; CsEntityNamespace p = parent.namespace_or_type_entity.parent as CsEntityNamespace; while (p != null) { ret = "." + p.name + ret; p = p.parent as CsEntityNamespace; } ret = ret.TrimStart('.'); return(ret + g); } } } ret = GetType(pDirective.namespace_or_type_name); if (!string.IsNullOrEmpty(ret)) { ret += "."; } return(ret + pDirective.identifier.identifier + g); }
public static string GetType(CsNamespaceOrTypeName pDirective) { string g = ""; //generics if (pDirective.type_argument_list != null && pDirective.type_argument_list.list.Count != 0) { g += "<"; foreach (CsTypeRef typeRef in pDirective.type_argument_list.list) { g += GetType(typeRef); g += ", "; } g = g.TrimEnd(_paramTrim) + ">"; } string ret = ""; if (pDirective.namespace_or_type_name == null) { if (pDirective.parent is CsTypeRef) { CsTypeRef parent = ((CsTypeRef)pDirective.parent); if (parent.entity_typeref.u is CsEntityClass) { if (IsClassDefinedAsObject(((CsEntityClass)parent.entity_typeref.u).attributes)) { return "object"; } return ((CsEntityClass)parent.entity_typeref.u).name; } if (parent.entity_typeref.type == cs_entity_type.et_generic_param) { return "<"+pDirective.identifier.identifier+">"; //return "*"; } if (parent.entity_typeref.u is CsEntityInstanceSpecifier) { //if (IsClassDefinedAsObject(((CsEntityInstanceSpecifier)parent.entity_typeref.u))) //return "Object"; } } else if (pDirective.parent is CsUsingNamespaceDirective) { CsUsingNamespaceDirective parent = (CsUsingNamespaceDirective)pDirective.parent; if (parent.namespace_or_type_entity != null) { ret = "." + parent.namespace_or_type_entity.name; CsEntityNamespace p = parent.namespace_or_type_entity.parent as CsEntityNamespace; while (p != null) { ret = "." + p.name + ret; p = p.parent as CsEntityNamespace; } ret = ret.TrimStart('.'); return ret + g; } } } ret = GetType(pDirective.namespace_or_type_name); if (!string.IsNullOrEmpty(ret)) { ret += "."; } return ret + pDirective.identifier.identifier + g; }