private static IntellisenseType GetType(CodeClass rootElement, CodeTypeRef codeTypeRef, HashSet <string> traversedTypes, HashSet <string> references) { var isArray = codeTypeRef.TypeKind == vsCMTypeRef.vsCMTypeRefArray; var isCollection = codeTypeRef.AsString.StartsWith("System.Collections", StringComparison.Ordinal); var isDictionary = false; var effectiveTypeRef = codeTypeRef; if (isArray && codeTypeRef.ElementType != null) { effectiveTypeRef = effectiveTypeRef.ElementType; } else if (isCollection) { effectiveTypeRef = TryToGuessGenericArgument(rootElement, effectiveTypeRef); } if (isCollection) { isDictionary = codeTypeRef.AsString.StartsWith("System.Collections.Generic.Dictionary", StringComparison.Ordinal) || codeTypeRef.AsString.StartsWith("System.Collections.Generic.IDictionary", StringComparison.Ordinal); } string typeName = effectiveTypeRef.AsFullName; try { var codeClass = effectiveTypeRef.CodeType as CodeClass2; var codeEnum = effectiveTypeRef.CodeType as CodeEnum; var isPrimitive = IsPrimitive(effectiveTypeRef); var result = new IntellisenseType { IsArray = !isDictionary && (isArray || isCollection), IsDictionary = isDictionary, CodeName = effectiveTypeRef.AsString, ClientSideReferenceName = effectiveTypeRef.TypeKind == vsCMTypeRef.vsCMTypeRefCodeType && effectiveTypeRef.CodeType.InfoLocation == vsCMInfoLocation.vsCMInfoLocationProject ? (codeClass != null && HasIntellisense(codeClass.ProjectItem, references) ? (GetNamespace(codeClass) + "." + Utility.CamelCaseClassName(GetClassName(codeClass))) : null) ?? (codeEnum != null && HasIntellisense(codeEnum.ProjectItem, references) ? (GetNamespace(codeEnum) + "." + Utility.CamelCaseClassName(codeEnum.Name)) : null) : null }; if (!isPrimitive && codeClass != null && !traversedTypes.Contains(effectiveTypeRef.CodeType.FullName) && !isCollection) { traversedTypes.Add(effectiveTypeRef.CodeType.FullName); result.Shape = GetProperties(effectiveTypeRef.CodeType.Members, traversedTypes, references).ToList(); traversedTypes.Remove(effectiveTypeRef.CodeType.FullName); } return(result); } catch (InvalidCastException) { VSHelpers.WriteOnOutputWindow(string.Format("ERROR - Cannot find definition for {0}", typeName)); throw new ArgumentException(string.Format("Cannot find definition of {0}", typeName)); } }
private static IntellisenseType GetType(CodeClass rootElement, CodeTypeRef codeTypeRef, HashSet <string> traversedTypes, HashSet <string> references) { var isArray = codeTypeRef.TypeKind == vsCMTypeRef.vsCMTypeRefArray; var isCollection = codeTypeRef.AsString.StartsWith("System.Collections", StringComparison.Ordinal); var isDictionary = false; var effectiveTypeRef = codeTypeRef; if (isArray && codeTypeRef.ElementType != null) { effectiveTypeRef = effectiveTypeRef.ElementType; } else if (isCollection) { effectiveTypeRef = TryToGuessGenericArgument(rootElement, effectiveTypeRef); } if (isCollection) { isDictionary = codeTypeRef.AsString.StartsWith("System.Collections.Generic.Dictionary", StringComparison.Ordinal); } var codeClass = effectiveTypeRef.CodeType as CodeClass2; var codeEnum = effectiveTypeRef.CodeType as CodeEnum; var isPrimitive = IsPrimitive(effectiveTypeRef); var result = new IntellisenseType { IsArray = !isDictionary && (isArray || isCollection), IsDictionary = isDictionary, CodeName = effectiveTypeRef.AsString, ClientSideReferenceName = effectiveTypeRef.TypeKind == vsCMTypeRef.vsCMTypeRefCodeType && effectiveTypeRef.CodeType.InfoLocation == vsCMInfoLocation.vsCMInfoLocationProject ? (codeClass != null && HasIntellisense(codeClass.ProjectItem, Constants.FileExtension, references) ? (GetNamespace(codeClass) + "." + GetClassName(codeClass)) : null) ?? (codeEnum != null && HasIntellisense(codeEnum.ProjectItem, Constants.FileExtension, references) ? (GetNamespace(codeEnum) + "." + codeEnum.Name) : null) : null }; if (!isPrimitive && codeClass != null && !traversedTypes.Contains(effectiveTypeRef.CodeType.FullName) && !isCollection) { traversedTypes.Add(effectiveTypeRef.CodeType.FullName); result.Shape = GetProperties(effectiveTypeRef.CodeType.Members, traversedTypes, references).ToList(); traversedTypes.Remove(effectiveTypeRef.CodeType.FullName); } return(result); }
public IntellisenseProperty(IntellisenseType type, string propertyName) { Type = type; Name = propertyName; }
private static IntellisenseType GetType(CodeClass rootElement, CodeTypeRef codeTypeRef, HashSet <string> traversedTypes, HashSet <string> references) { var isArray = codeTypeRef.TypeKind == vsCMTypeRef.vsCMTypeRefArray; var isCollection = codeTypeRef.AsString.StartsWith("System.Collections", StringComparison.Ordinal); var isDictionary = false; var effectiveTypeRef = codeTypeRef; if (isArray && codeTypeRef.ElementType != null) { effectiveTypeRef = effectiveTypeRef.ElementType; } else if (isCollection) { effectiveTypeRef = TryToGuessGenericArgument(rootElement, effectiveTypeRef); } if (isCollection) { isDictionary = codeTypeRef.AsString.StartsWith("System.Collections.Generic.Dictionary", StringComparison.Ordinal) || codeTypeRef.AsString.StartsWith("System.Collections.Generic.IDictionary", StringComparison.Ordinal); } string typeName = effectiveTypeRef.AsFullName; try { //VSHelpers.WriteOnBuildDebugWindow($"%{(effectiveTypeRef.CodeType as CodeInterface2) != null}%"); var codeInterface = effectiveTypeRef.CodeType as CodeInterface2; var codeClass = effectiveTypeRef.CodeType as CodeClass2; var codeEnum = effectiveTypeRef.CodeType as CodeEnum; var isPrimitive = IsPrimitive(effectiveTypeRef); //VSHelpers.WriteOnBuildDebugWindow($"###{effectiveTypeRef.CodeType.GetType().FullName}"); var result = new IntellisenseType { IsArray = !isDictionary && (isArray || isCollection), IsDictionary = isDictionary, CodeName = effectiveTypeRef.AsString }; //VSHelpers.WriteOnBuildDebugWindow($"#{result.CodeName}#{result.TypeScriptName}#{effectiveTypeRef.AsString}#{effectiveTypeRef.AsFullName}#{effectiveTypeRef.CodeType}"); //VSHelpers.WriteOnBuildDebugWindow($"##{effectiveTypeRef.TypeKind}##{vsCMTypeRef.vsCMTypeRefCodeType}##{effectiveTypeRef.CodeType.InfoLocation}##{vsCMInfoLocation.vsCMInfoLocationProject}"); result.ClientSideReferenceName = null; if (effectiveTypeRef.TypeKind == vsCMTypeRef.vsCMTypeRefCodeType) { var hasIntellisense = Options.IgnoreIntellisense; if (effectiveTypeRef.CodeType.InfoLocation == vsCMInfoLocation.vsCMInfoLocationProject) { if (codeClass != null) { hasIntellisense = HasIntellisense(codeClass.ProjectItem, references); } if (codeEnum != null) { hasIntellisense = HasIntellisense(codeEnum.ProjectItem, references); } } //VSHelpers.WriteOnBuildDebugWindow($"@{codeClass != null}@{codeEnum != null}@{hasIntellisense}@{Options.DeclareModule}"); result.ClientSideReferenceName = (codeClass != null && hasIntellisense ? (Options.DeclareModule ? GetNamespace(codeClass) + "." : "") + Utility.CamelCaseClassName(GetClassName(codeClass)) : null) ?? (codeEnum != null && hasIntellisense ? (Options.DeclareModule ? GetNamespace(codeEnum) + "." : "") + Utility.CamelCaseClassName(GetEnumName(codeEnum)) : null) ?? (codeInterface != null && hasIntellisense ? (Options.DeclareModule ? GetNamespace(codeInterface) + "." : "") + Utility.CamelCaseClassName(GetInterfaceName(codeInterface)) : null); } if (!isPrimitive && (codeClass != null || codeEnum != null) && !traversedTypes.Contains(effectiveTypeRef.CodeType.FullName) && !isCollection) { traversedTypes.Add(effectiveTypeRef.CodeType.FullName); result.Shape = GetProperties(effectiveTypeRef.CodeType.Members, traversedTypes, references).ToList(); traversedTypes.Remove(effectiveTypeRef.CodeType.FullName); } return(result); } catch (InvalidCastException) { VSHelpers.WriteOnOutputWindow(string.Format("ERROR - Cannot find definition for {0}", typeName)); throw new ArgumentException(string.Format("Cannot find definition of {0}", typeName)); } }
private static IntellisenseType GetType(ProjectItem projectItem, DefinitionMapData definitionMapData, CodeClass rootElement, CodeTypeRef codeTypeRef, HashSet <string> traversedTypes, HashSet <string> references) { var isArray = codeTypeRef.TypeKind == vsCMTypeRef.vsCMTypeRefArray; var isCollection = codeTypeRef.AsString.StartsWith("System.Collections", StringComparison.Ordinal); var isNullable = codeTypeRef.AsFullName.StartsWith("System.Nullable", StringComparison.Ordinal); var isDictionary = false; var effectiveTypeRef = codeTypeRef; if (isArray && codeTypeRef.ElementType != null) { effectiveTypeRef = effectiveTypeRef.ElementType; } else if (isCollection || isNullable) { effectiveTypeRef = TryToGuessGenericArgument(rootElement, effectiveTypeRef); } if (isCollection) { isDictionary = codeTypeRef.AsString.StartsWith("System.Collections.Generic.Dictionary", StringComparison.Ordinal); } string typeName = effectiveTypeRef.AsFullName; try { var codeClass = effectiveTypeRef.CodeType as CodeClass2; var codeEnum = effectiveTypeRef.CodeType as CodeEnum; var isPrimitive = IsPrimitive(effectiveTypeRef); // Some definitions may be defined inside of another project if (Options.AssumeExternalType == false && (codeClass != null || codeEnum != null) && effectiveTypeRef.TypeKind == vsCMTypeRef.vsCMTypeRefCodeType && effectiveTypeRef.CodeType.InfoLocation == vsCMInfoLocation.vsCMInfoLocationExternal) { // Try retrieving the external codeclass by walking all references the current project has if (TryGetExternalType(projectItem, definitionMapData, codeClass != null ? codeClass.FullName : codeEnum.FullName, out CodeClass2 externalCodeClass, out CodeEnum externalCodeEnum)) { // If successful use the new type codeClass = externalCodeClass; codeEnum = externalCodeEnum; } } var result = new IntellisenseType { IsArray = !isDictionary && (isArray || isCollection), IsDictionary = isDictionary, IsOptional = isNullable, CodeName = effectiveTypeRef.AsString }; if (effectiveTypeRef.TypeKind == vsCMTypeRef.vsCMTypeRefCodeType && (effectiveTypeRef.CodeType.InfoLocation == vsCMInfoLocation.vsCMInfoLocationProject || (Options.AssumeExternalType == false && effectiveTypeRef.CodeType.InfoLocation == vsCMInfoLocation.vsCMInfoLocationExternal))) { try { result.ClientSideReferenceName = (codeClass != null && HasIntellisense(codeClass.ProjectItem, references) ? (GetNamespace(codeClass) + "." + Utility.CamelCaseClassName(GetClassName(codeClass))) : null) ?? (codeEnum != null && HasIntellisense(codeEnum.ProjectItem, references) ? (GetNamespace(codeEnum) + "." + Utility.CamelCaseClassName(codeEnum.Name)) : null); } catch (Exception) { } } else if (Options.AssumeExternalType && effectiveTypeRef.TypeKind == vsCMTypeRef.vsCMTypeRefCodeType && effectiveTypeRef.CodeType.InfoLocation == vsCMInfoLocation.vsCMInfoLocationExternal) { try { result.ClientSideReferenceName = (codeClass != null ? (GetNamespace(codeClass) + "." + Utility.CamelCaseClassName(GetClassName(codeClass))) : null) ?? (codeEnum != null ? (GetNamespace(codeEnum) + "." + Utility.CamelCaseClassName(codeEnum.Name)) : null); } catch (Exception) { } } else { result.ClientSideReferenceName = null; } if (!isPrimitive && codeClass != null && !traversedTypes.Contains(effectiveTypeRef.CodeType.FullName) && !isCollection) { traversedTypes.Add(effectiveTypeRef.CodeType.FullName); result.Shape = GetProperties(projectItem, definitionMapData, effectiveTypeRef.CodeType.Members, traversedTypes, references).ToList(); traversedTypes.Remove(effectiveTypeRef.CodeType.FullName); } return(result); } catch (InvalidCastException) { VSHelpers.WriteOnOutputWindow(string.Format("ERROR - Cannot find definition for {0}", typeName)); throw new ArgumentException(string.Format("Cannot find definition of {0}", typeName)); } }