public string GetInfo() { var builder = new StringBuilder(); builder.AppendLine("Type Summary"); builder.Append(Environment.NewLine); builder.AppendLine(string.Format("Name: {0}", Name)); builder.AppendLine(string.Format("TypeCode: {0}", TypeDefinition.KnownTypeCode)); builder.AppendLine(string.Format("Methods: {0}", Methods.Count())); builder.AppendLine(string.Format("Fields: {0}", Fields.Count())); builder.AppendLine(string.Format("Nested types: {0}", NestedTypes.Count())); builder.AppendLine(string.Format("Base types: {0}", BaseTypes.Count())); // more to come builder.Append(Environment.NewLine); // if (TypeDefinition.IsAbstract) // builder.AppendLine("IsAbstract"); // if (TypeDefinition. // if (IsInternal) // builder.AppendLine("IsInternal"); // if (IsNestedPrivate) // builder.AppendLine("IsNestedPrivate"); // if (IsNestedProtected) // builder.AppendLine("IsNestedProtected"); // if (IsNestedPublic) // builder.AppendLine("IsNestedPublic"); // if (IsPublic) // builder.AppendLine("IsPublic"); // if (IsSealed) // builder.AppendLine("IsSealed"); // if (IsStruct) // builder.AppendLine("IsStruct"); return(builder.ToString()); }
/// <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); }