示例#1
0
        private CSharpProperty BuildProperty(IPropertySymbol symbol, CSharpClass referencingClass, string nameSpace = null)
        {
            var prop = new CSharpProperty();

            var commentXml = symbol.GetDocumentationCommentXml();
            var typeName   = symbol.Type.Name.ToString();
            Dictionary <string, HashSet <string> > references = new Dictionary <string, HashSet <string> >();
            var newTypeName = context.GetTsType(symbol.Type, references);

            //if (newTypeName == null || string.IsNullOrEmpty(newTypeName))
            //{

            //}
            // remove the namespace if it's the same
            if (nameSpace != null && newTypeName.StartsWith(nameSpace))
            {
                newTypeName = newTypeName.Remove(0, nameSpace.Length + 1); // +1 for the dot
            }

            if (references.Count > 0)
            {
                referencingClass.AddReferences(references);
            }

            prop.SetSummaryViaXml(commentXml);
            var name = symbol.Name.ToString();

            prop.DisplayText = name + ": " + newTypeName + ";";

            return(prop);
        }
示例#2
0
        public override void VisitClassDeclaration(ClassDeclarationSyntax node)
        {
            var symbol = model.GetDeclaredSymbol(node);
            var fqName = symbol.ToDisplayString(_symDisplayFormat);

            string ns, name;

            Extensions.GetNamespaceAndName(fqName, out ns, out name);
            if (!string.IsNullOrWhiteSpace(ns))
            {
                CSharpNamespace nsObj;
                if (!CSFile.Elements.TryGetValue(ns, out nsObj))
                {
                    // This handles classes within classes
                    nsObj             = new CSharpNamespace();
                    nsObj.DisplayText = ns;
                    CSFile.Elements.Add(ns, nsObj);
                    _subClassConversions.Add(fqName, string.Format("{0}.{1}", fqName, name));
                }
                var classObj = new CSharpClass()
                {
                    IsPartial = symbol.DeclaringSyntaxReferences.Length > 1
                };

                Dictionary <string, HashSet <string> > references = new Dictionary <string, HashSet <string> >();
                string typeSuffix = GetGenericTypeSuffix(symbol, references);
                classObj.ExtendedInterface = GetExtendingType(symbol, references);
                if (string.IsNullOrEmpty(classObj.ExtendedInterface))
                {
                    foreach (var baseProperty in GetBasePropertiesFromExternalAssembly(symbol, classObj))
                    {
                        if (!baseProperty.Key.StartsWith("this", StringComparison.Ordinal) &&
                            !classObj.Children.ContainsKey(baseProperty.Key))
                        {
                            classObj.Children.Add(baseProperty.Key, baseProperty.Value);
                        }
                    }
                }

                var commentXml = symbol.GetDocumentationCommentXml();

                classObj.SetSummaryViaXml(commentXml);
                classObj.DisplayText = name + typeSuffix;

                if (references.Count > 0)
                {
                    classObj.AddReferences(references);
                }

                nsObj.Children.Add(name, classObj);
            }
            base.VisitClassDeclaration(node);
        }
示例#3
0
 private IEnumerable <KeyValuePair <string, CSharpProperty> > GetBasePropertiesFromExternalAssembly(INamedTypeSymbol symbol, CSharpClass referencingClass)
 {
     if (symbol.BaseType != null &&
         symbol.BaseType.ToDisplayString(_symDisplayFormat) != "System.Object" &&
         symbol.BaseType.ToDisplayString(_symDisplayFormat) != "System.Configuration.ApplicationSettingsBase" &&
         !symbol.BaseType.OriginalDefinition.Locations.Any(s => s.IsInSource))
     {
         var properties = symbol.GetAccessibleMembersInThisAndBaseTypes(SymbolKind.Property, Accessibility.Public);
         foreach (ISymbol property in properties)
         {
             var propSymbol = property as IPropertySymbol;
             if (propSymbol != null &&
                 propSymbol.GetMethod != null &&
                 propSymbol.SetMethod != null)
             {
                 yield return(new KeyValuePair <string, CSharpProperty>(propSymbol.Name, BuildProperty(propSymbol, referencingClass, null)));
             }
         }
     }
 }