Ejemplo n.º 1
0
 /// <summary>
 /// AddBaseTypes
 /// </summary>
 /// <param name="statementSource"></param>
 private string AddBaseTypes(string statementSource)
 {
     //add baseTypes
     if (BaseTypes.Any())
     {
         //check if there are only interfaces and classes in the basetype list
         if (BaseTypes.Any(el => el.ElementType == TsElementTypes.Enumerations))
         {
             throw new Exception(string.Format("Type ({0}) contains baseTypes which are not interface/class", Name));
         }
         //if this element is a class, we need to add the baseType
         if (ElementType == TsElementTypes.Class)
         {
             //if there is more than one baseType which is not an interface, throw exeption, bec we can only extend a single class
             if (BaseTypes.Count(el => el.ElementType == TsElementTypes.Class) > 1)
             {
                 throw new Exception(string.Format("Type ({0}) can only only extend one baseclass", Name));
             }
             //Get baseType
             var baseType = BaseTypes.FirstOrDefault(el => el.ElementType == TsElementTypes.Class);
             if (baseType != null)
             {
                 statementSource = string.Format(TsDomConstants.TS_BASETYPE_EXTENDS_FORMAT, statementSource, baseType.TsTypeName);
             }
             //a class can only implement interfaces
             List <TsCodeTypeReference> implementTypes = BaseTypes.Where(el => el.ElementType == TsElementTypes.Interface).ToList();
             if (implementTypes.Count > 0)
             {
                 var typeStringList = implementTypes.Select(el => el.TsTypeName);
                 //combine types
                 var implementsString = string.Join(TsDomConstants.TS_BASETYPE_SEPERATOR, typeStringList);
                 //combine type
                 statementSource = string.Format(TsDomConstants.TS_BASETYPE_IMPLEMENTS_FORMAT, statementSource,
                                                 implementsString);
             }
         }
         else if (ElementType == TsElementTypes.Interface)
         {
             //interface impelments everything including types and baseTypes
             List <TsCodeTypeReference> implementTypes = BaseTypes.ToList();
             if (implementTypes.Count > 0)
             {
                 var typeStringList = implementTypes.Select(el => el.TsTypeName);
                 //combine types
                 var implementsString = string.Join(TsDomConstants.TS_BASETYPE_SEPERATOR, typeStringList);
                 //combine type
                 statementSource = string.Format(TsDomConstants.TS_BASETYPE_EXTENDS_FORMAT, statementSource, implementsString);
             }
         }
         //if we are using constants add all interface types
         else if (ElementType == TsElementTypes.Constant)
         {
             List <TsCodeTypeReference> implementTypes = BaseTypes.ToList();
             if (implementTypes.Count > 0)
             {
                 var implementsString = string.Join(TsDomConstants.MULTIPLETYPE_SEPERATOR, implementTypes.Select(el => el.Name));
                 //combine type
                 statementSource = string.Format(TsDomConstants.TS_ELEMENT_TYPE_FORMAT, statementSource, implementsString);
             }
         }
     }
     return(statementSource);
 }