public static TheClass Get(CsEntity pCsEntity, FactoryExpressionCreator pCreator) { if (pCsEntity == null) { return(null); } while (pCsEntity != null) { if (pCsEntity is CsEntityClass || pCsEntity is CsEntityStruct || pCsEntity is CsEntityInterface) { break; } pCsEntity = pCsEntity.parent; } CsEntityClass entityKlass = pCsEntity as CsEntityClass; if (entityKlass != null && entityKlass.nodes.Count != 0 && entityKlass.nodes.First.Value != null) { return(Get(entityKlass.nodes.First.Value, pCreator)); } CsEntityStruct entityStruct = pCsEntity as CsEntityStruct; if (entityStruct != null && entityStruct.nodes.Count != 0 && entityStruct.nodes.First.Value != null) { return(Get(entityStruct.nodes.First.Value, pCreator)); } CsEntityInterface entityInterface = pCsEntity as CsEntityInterface; if (entityInterface != null && entityInterface.nodes.Count != 0 && entityInterface.nodes.First.Value != null) { return(Get(entityInterface.nodes.First.Value, pCreator)); } if (pCsEntity != null) { if (!_entities.ContainsKey(pCsEntity)) { _entities[pCsEntity] = new TheClass(pCsEntity, pCreator); } return(_entities[pCsEntity]); } throw new Exception(); }
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 TheClass(CsEntity pCsEntity, FactoryExpressionCreator pCreator) { IsEntity = true; List <string> name = new List <string>(); CsEntity parent = pCsEntity.parent; while (parent != null && parent is CsEntityNamespace) { if (!string.IsNullOrEmpty(parent.name)) { name.Add(parent.name); } parent = parent.parent; } name.Reverse(); NameSpace = string.Join(".", name.ToArray()); //RealName = pCsEntity.name; //Name = Helpers.GetRealName(pCsEntity, RealName); Name = pCsEntity.name; FullName = NameSpace + "." + Name; //FullRealName = NameSpace + "." + RealName; CsEntityClass klass = pCsEntity as CsEntityClass; if (klass != null) { _baseEntityTyperef = klass.base_type; if (klass.base_type.type != cs_entity_type.et_object) { Extends.Add(Helpers.GetType(klass.base_type)); } if (klass.interfaces != null) { foreach (CsEntityTypeRef @interface in klass.interfaces) { Implements.Add(Helpers.GetType(@interface)); } } Dictionary <string, int> methodNames = new Dictionary <string, int>(); //bool constructorsDone = false; bool methodsDone = false; if (klass.method_implementations == null) { return; } foreach (CsEntityMethodImplementation methodImplementation in klass.method_implementations) { CsEntityMethod m = methodImplementation.implementation_method; TheMethod tm = new TheMethod(m, this, pCreator); if (methodNames.ContainsKey(tm.Name)) { methodNames[tm.Name]++; int index = tm._index = methodNames[tm.Name]; if (!methodsDone) { methodsDone = true; foreach (KeyValuePair <CsMethod, TheMethod> method in _methods) { method.Value._isUnique = false; method.Value._index = --index; } } tm._isUnique = false; } else { methodNames[tm.Name] = tm._index = 1; } _entityMethods.Add(m, tm); } return; } CsEntityInterface entityInterface = pCsEntity as CsEntityInterface; if (entityInterface != null) { _baseEntityTyperef = entityInterface.base_type; if (entityInterface.base_type.type != cs_entity_type.et_object) { Extends.Add(Helpers.GetType(entityInterface.base_type)); } if (entityInterface.interfaces != null) { foreach (CsEntityTypeRef @interface in entityInterface.interfaces) { Implements.Add(Helpers.GetType(@interface)); } } Dictionary <string, int> methodNames = new Dictionary <string, int>(); bool methodsDone = false; if (entityInterface.method_implementations == null) { return; } foreach (CsEntityMethodImplementation methodImplementation in entityInterface.method_implementations) { CsEntityMethod m = methodImplementation.implementation_method; TheMethod tm = new TheMethod(m, this, pCreator); if (methodNames.ContainsKey(tm.Name)) { methodNames[tm.Name]++; int index = tm._index = methodNames[tm.Name]; if (!methodsDone) { methodsDone = true; foreach (KeyValuePair <CsMethod, TheMethod> method in _methods) { method.Value._isUnique = false; method.Value._index = --index; } } tm._isUnique = false; } else { methodNames[tm.Name] = tm._index = 1; } _entityMethods.Add(m, tm); } return; } CsEntityStruct entityStruct = pCsEntity as CsEntityStruct; if (entityStruct != null) { _baseEntityTyperef = entityStruct.base_type; if (entityStruct.base_type.type != cs_entity_type.et_object) { Extends.Add(Helpers.GetType(entityStruct.base_type)); } if (entityStruct.interfaces != null) { foreach (CsEntityTypeRef @interface in entityStruct.interfaces) { Implements.Add(Helpers.GetType(@interface)); } } Dictionary <string, int> methodNames = new Dictionary <string, int>(); bool methodsDone = false; if (entityStruct.method_implementations == null) { return; } foreach (CsEntityMethodImplementation methodImplementation in entityStruct.method_implementations) { CsEntityMethod m = methodImplementation.implementation_method; TheMethod tm = new TheMethod(m, this, pCreator); if (methodNames.ContainsKey(tm.Name)) { methodNames[tm.Name]++; int index = tm._index = methodNames[tm.Name]; if (!methodsDone) { methodsDone = true; foreach (KeyValuePair <CsMethod, TheMethod> method in _methods) { method.Value._isUnique = false; method.Value._index = --index; } } tm._isUnique = false; } else { methodNames[tm.Name] = tm._index = 1; } _entityMethods.Add(m, tm); } return; } throw new NotImplementedException(); }