//public static TheClass Get(CsEntity pEntity) { // CsEntityClass typeRef = pEntity as CsEntityClass; // if (typeRef != null) { // CsClass theClass = typeRef.nodes.First.Value as CsClass; // if (theClass == null) { // return get(typeRef); // } // if (!_classes.ContainsKey(theClass)) // _classes[theClass] = new TheClass(theClass); // return _classes[theClass]; // } // CsEntityInterface entityInterface = pEntity as CsEntityInterface; //} public static TheClass Get(CsEntityTypeRef pEntityTyperef, FactoryExpressionCreator pCreator) { if (pEntityTyperef == null) { return(null); } if ( pEntityTyperef.u is CsEntityGenericParam || pEntityTyperef.u is CsEntityArraySpecifier ) { return(null); } CsEntityInstanceSpecifier entityInstanceSpecifier = pEntityTyperef.u as CsEntityInstanceSpecifier; CsEntity entityClass = entityInstanceSpecifier == null ? (CsEntity)pEntityTyperef.u : (CsEntity)entityInstanceSpecifier.type.u; return(Get(entityClass, pCreator)); //return Get(entityClass.nodes.First.Value); }
public static bool GetRealName(object pExpression, string pName, out string pRealName) { if (pExpression == null) { pRealName = pName; return(false); } CsEntityClass csEntityClass = pExpression as CsEntityClass; if (csEntityClass != null) { return(getRealName(csEntityClass.attributes, pName, out pRealName)); } CsEntityEnum csEntityEnum = pExpression as CsEntityEnum; if (csEntityEnum != null) { return(getRealName(csEntityEnum.attributes, pName, out pRealName)); } CsEntityStruct csEntityStruct = pExpression as CsEntityStruct; if (csEntityStruct != null) { return(getRealName(csEntityStruct.attributes, pName, out pRealName)); } CsEntityInterface csEntityInterface = pExpression as CsEntityInterface; if (csEntityInterface != null) { return(getRealName(csEntityInterface.attributes, pName, out pRealName)); } CsPrimaryExpressionMemberAccess csPrimaryExpressionMemberAccess = pExpression as CsPrimaryExpressionMemberAccess; if (csPrimaryExpressionMemberAccess != null) { return(GetRealName(csPrimaryExpressionMemberAccess.expression.entity, pName, out pRealName)); } CsEntityLocalVariable csEntityLocalVariable = pExpression as CsEntityLocalVariable; if (csEntityLocalVariable != null) { CsLocalVariableDeclaration v = (csEntityLocalVariable.decl.parent) as CsLocalVariableDeclaration; if (v != null) { GetRealName(v.type.entity_typeref.u, pName, out pRealName); //get new name but do not replace expression, as this is a local accessor... return(false); } } CsEntityVariable csEntityVariable = pExpression as CsEntityVariable; if (csEntityVariable != null) { return(GetRealName(csEntityVariable.type.u, pName, out pRealName)); } CsEntityConstant csEntityConstant = pExpression as CsEntityConstant; if (csEntityConstant != null) { return(GetRealName(csEntityConstant.type.u, pName, out pRealName)); } CsEntityMethod csEntityMethod = pExpression as CsEntityMethod; if (csEntityMethod != null) { return(GetRealName(csEntityMethod.parent, pName, out pRealName)); } CsSimpleName csSimpleName = pExpression as CsSimpleName; if (csSimpleName != null) { return(GetRealName(csSimpleName.entity_typeref == null ? csSimpleName.entity : csSimpleName.entity_typeref.u, pName, out pRealName)); } CsPredefinedTypeMemberAccess csPredefinedTypeMemberAccess = pExpression as CsPredefinedTypeMemberAccess; if (csPredefinedTypeMemberAccess != null) { return (GetRealName( csPredefinedTypeMemberAccess.entity_typeref == null ? csPredefinedTypeMemberAccess.entity : csPredefinedTypeMemberAccess.entity_typeref.u, pName, out pRealName)); } CsEntityInstanceSpecifier csEntityInstanceSpecifier = pExpression as CsEntityInstanceSpecifier; if (csEntityInstanceSpecifier != null) { return(GetRealName(csEntityInstanceSpecifier.type.u, pName, out pRealName)); } pRealName = pName; return(false); //CsEntityDelegate csEntityDelegate = pExpression as CsEntityDelegate; //if (csEntityDelegate != null) { // pRealName = pName; // return false; //} //throw new NotImplementedException(); }
public static string GetType(CsEntityTypeRef pDirective) { if (pDirective == null) { return(null); } if (_entityTypeRef.ContainsKey(pDirective.type)) { return(_entityTypeRef[pDirective.type]); } switch (pDirective.type) { case cs_entity_type.et_valuetype: return(null); case cs_entity_type.et_array: return(GetType(((CsEntityArraySpecifier)pDirective.u).type) + "[]"); case cs_entity_type.et_enum: return(((CsEntityEnum)pDirective.u).name); case cs_entity_type.et_generic_param: CsEntityGenericParam egp = pDirective.u as CsEntityGenericParam; //TODO: check generics parameters return("<" + egp.name + ">"); case cs_entity_type.et_genericinst: CsEntityInstanceSpecifier eis = pDirective.u as CsEntityInstanceSpecifier; if (eis != null) { string ret = GetType(eis.type); if (eis.arguments != null) { List <string> val = new List <string> { "<" }; foreach (CsEntityTypeRef argument in eis.arguments) { val.Add(GetType(argument)); val.Add(", "); } val.RemoveAt(val.Count - 1); val.Add(">"); ret += string.Join("", val.ToArray()); } return(ret); } throw new Exception(); case cs_entity_type.et_class: CsEntityInterface itf = pDirective.u as CsEntityInterface; if (itf != null) { if (itf.interfaces != null && itf.interfaces.Count > 0) { List <string> val = new List <string>(itf.interfaces.Count); foreach (CsEntityTypeRef typeRef in itf.interfaces) { val.Add(GetType(typeRef)); } return(string.Join(", ", val.ToArray())); } if (!string.IsNullOrEmpty(itf.name)) { return(itf.name); } } CsEntityClass cls = pDirective.u as CsEntityClass; if (cls != null) { //if (cls.indexers != null) { // foreach (CsEntityProperty indexer in cls.indexers) { // return GetType(indexer.type); // } //} return(cls.name); } CsEntityDelegate entityDelegate = pDirective.u as CsEntityDelegate; if (entityDelegate != null) { return("function"); } return("IHaveNOIdeaWhatShouldBeHere"); } throw new Exception("Unknown EntityTypeRef: " + pDirective.type); }