// Visit Object Model public void VisitApis() { // store types // we have to do this after all assemblies are registered because the resolution may not work unless // all the assemblies we need are in the resolver cache //Console.WriteLine("storing types"); foreach (AssemblyNode assembly in assemblies) { //Console.WriteLine("assembly {0}", assembly.Name); //Console.WriteLine("has {0} types", assembly.Types.Count); StoreTypes(assembly.Types); //Console.WriteLine("done with assembly"); } //Console.WriteLine("done storing types"); //Console.WriteLine("visiting namespaces"); NamespaceList spaces = new NamespaceList(); foreach (Namespace space in catalog.Values) { if (filter.IsExposedNamespace(space)) { spaces.Add(space); } } VisitNamespaces(spaces); }
protected virtual void _WriteStartRootNode ( System.Xml.XmlWriter xmlWriter, string name, string ns, NamespaceList nsList ) { xmlWriter.WriteStartDocument(true); xmlWriter.WriteStartElement(name, ns); if (nsList != null) { StringBuilder schemaLocation = new StringBuilder(); foreach (NamespaceData nsd in nsList) { if (String.IsNullOrEmpty(nsd.NamespaceUri) == true) { continue; } if (String.IsNullOrEmpty(nsd.Prefix) == false) { xmlWriter.WriteAttributeString("xmlns", nsd.Prefix, null, nsd.NamespaceUri); } if (String.IsNullOrEmpty(nsd.XSDLocation) == false) { schemaLocation.AppendFormat("{0} {1} ", nsd.NamespaceUri, nsd.XSDLocation); } } xmlWriter.WriteAttributeString("xsi", "schemaLocation", null, schemaLocation.ToString().Trim()); } }
// POST: Service/PluginServices/Namespaces public virtual NamespaceList Namespaces(ComPluginSource args, Guid workspaceId, Guid dataListId) { var result = new NamespaceList(); try { if (args != null) { var broker = new ComPluginBroker(); return(broker.GetNamespaces(args)); } } catch (BadImageFormatException e) { RaiseError(e); throw; } catch (Exception ex) when(ex is COMException) { throw; } catch (Exception ex) { RaiseError(ex); } return(result); }
//===================================================================== /// <summary> /// This is called to visit all namespaces, types, and members in the list of assemblies to be documented /// </summary> public void VisitApis() { // Store types. We have to do this after all assemblies are registered because the resolution may // not work unless all the assemblies we need are in the resolver cache. foreach (AssemblyNode assembly in assemblies) { this.StoreTypes(assembly.Types); if (this.Canceled) { break; } } if (!this.Canceled) { NamespaceList spaces = new NamespaceList(); foreach (Namespace space in catalog.Values) { if (filter.IsExposedNamespace(space)) { spaces.Add(space); } } if (!this.Canceled) { this.VisitNamespaces(spaces); } } }
public static void init( ) { // if ( allNamespaces != null ) return; allNamespaces = new NamespaceList(); nsCached = new Dictionary <string, TypeNodeList>(); // Scan all assemblies referenced in parameters // and take all namespaces from them. // Put all these namespaces into the common list. System.Collections.Specialized.StringCollection assemblies = CONTEXT.options.ReferencedAssemblies; foreach (string assName in assemblies) { AssemblyNode assembly = AssemblyNode.GetAssembly(assName, true, false, true); if (assembly == null && !CONTEXT.AnalysisOnly) { ERROR.UnresolvedReference(assName); continue; } NamespaceList nss = assembly.GetNamespaceList(); for (int i = 0, n = nss.Length; i < n; i++) { allNamespaces.Add(nss[i]); } } }
public void PopulateTypeList(TypeNodeList types, NamespaceList namespaces) { if (types == null) { Debug.Assert(false); return; } for (int i = 0, n = namespaces == null ? 0 : namespaces.Length; i < n; i++) { Namespace ns = namespaces[i]; if (ns == null) { continue; } if (ns.NestedNamespaces != null) { this.PopulateTypeList(types, ns.NestedNamespaces); } TypeNodeList nTypes = ns.Types; for (int j = 0, m = nTypes == null ? 0 : nTypes.Length; j < m; j++) { TypeNode t = nTypes[j]; if (t == null) { continue; } this.PopulateTypeList(types, t); } } }
//Helper function used by other components if need to update import context item public static void AddImport(string importedNamespace, EditingContext editingContext) { //For types defined without any namespace, Type.Namespace is null instead of empty. We don't need to add any namespace to Import list in this case if (string.IsNullOrEmpty(importedNamespace)) { return; } Fx.Assert(editingContext != null, "EditingContext shouldn't be null."); ModelService modelService = editingContext.Services.GetService <ModelService>(); Fx.Assert(modelService != null, "EditingContext should contains ModelService."); ModelItemCollection importsCollection = modelService.Root.Properties[NamespaceListPropertyDescriptor.ImportCollectionPropertyName].Collection; NamespaceList namespaceList = importsCollection.GetCurrentValue() as NamespaceList; if (namespaceList.Lookup(importedNamespace) == -1) { importsCollection.Add(new NamespaceData { Namespace = importedNamespace }); } else { namespaceList.UpdateAssemblyInfo(importedNamespace); } }
/// <include file='doc\XmlSerializerNamespaces.uex' path='docs/doc[@for="XmlSerializerNamespaces.ToArray"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public XmlQualifiedName[] ToArray() { if (NamespaceList == null) { return(new XmlQualifiedName[0]); } return((XmlQualifiedName[])NamespaceList.ToArray(typeof(XmlQualifiedName))); }
/// <summary> /// Fetches the name space list object. /// </summary> /// <param name="pluginSource">The plugin source.</param> /// <returns></returns> public NamespaceList FetchNamespaceListObject(PluginSource pluginSource) { var interrogatePlugin = ReadNamespaces(pluginSource.AssemblyLocation, pluginSource.AssemblyName); var namespacelist = new NamespaceList(); namespacelist.AddRange(interrogatePlugin); return(namespacelist); }
/// <include file='doc\XmlSerializerNamespaces.uex' path='docs/doc[@for="XmlSerializerNamespaces.ToArray"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public XmlQualifiedName[] ToArray() { if (NamespaceList == null) { return(Array.Empty <XmlQualifiedName>()); } return(NamespaceList.ToArray()); }
/// <summary> /// Fetches the name space list object. /// </summary> /// <param name="pluginSource">The plugin source.</param> /// <returns></returns> public NamespaceList FetchNamespaceListObject(ComPluginSource pluginSource) { var interrogatePlugin = ReadNamespaces(pluginSource.ClsId, pluginSource.Is32Bit); var namespacelist = new NamespaceList(); namespacelist.AddRange(interrogatePlugin); namespacelist.Add(new NamespaceItem()); return(namespacelist); }
/// <summary> /// Fetches the name space list object. /// </summary> /// <param name="pluginSource">The plugin source.</param> /// <returns></returns> public NamespaceList FetchNamespaceListObject(PluginSource pluginSource) { // BUG 9500 - 2013.05.31 - TWR : added check to avoid nulling AssemblyLocation/Name in tests if (string.IsNullOrEmpty(pluginSource.AssemblyLocation)) { pluginSource = new PluginSources().Get(pluginSource.ResourceID.ToString(), Guid.Empty, Guid.Empty); } var interrogatePlugin = ReadNamespaces(pluginSource.AssemblyLocation, pluginSource.AssemblyName); var namespacelist = new NamespaceList(); namespacelist.AddRange(interrogatePlugin); return(namespacelist); }
internal static string ToString(NamespaceList list) { if (list == null) { return(null); } switch (list.Type) { case NamespaceList.ListType.Any: return("##any"); case NamespaceList.ListType.Other: return("##other"); case NamespaceList.ListType.Set: ArrayList ns = new ArrayList(); foreach (string s in list.Enumerate) { ns.Add(s); } ns.Sort(); StringBuilder sb = new StringBuilder(); bool first = true; foreach (string s in ns) { if (first) { first = false; } else { sb.Append(" "); } if (s.Length == 0) { sb.Append("##local"); } else { sb.Append(s); } } return(sb.ToString()); default: return(list.ToString()); } }
internal static string ToString(NamespaceList list) { if (list == null) { return(null); } switch (list.Type) { case NamespaceList.ListType.Any: return("##any"); case NamespaceList.ListType.Other: return("##other"); case NamespaceList.ListType.Set: { ArrayList list2 = new ArrayList(); foreach (string str in list.Enumerate) { list2.Add(str); } list2.Sort(); StringBuilder builder = new StringBuilder(); bool flag = true; foreach (string str2 in list2) { if (flag) { flag = false; } else { builder.Append(" "); } if (str2.Length == 0) { builder.Append("##local"); } else { builder.Append(str2); } } return(builder.ToString()); } } return(list.ToString()); }
/// <summary> /// This is used to visit a list of namespaces /// </summary> /// <param name="spaces">The list of namespaces to visit</param> protected virtual void VisitNamespaces(NamespaceList spaces) { // Visit the namespaces in sorted order foreach (Namespace space in spaces.OrderBy(s => s.FullName)) { if (filter.IsExposedNamespace(space)) { this.VisitNamespace(space); } if (this.Canceled) { break; } } }
protected virtual void VisitNamespaces(NamespaceList spaces) { // sort namespaces by name Namespace[] sorted_spaces = new Namespace[spaces.Count]; for (int i = 0; i < spaces.Count; i++) { sorted_spaces[i] = spaces[i]; } Array.Sort <Namespace>(sorted_spaces, namespaceComparison); // visit them foreach (Namespace space in sorted_spaces) { if (filter.IsExposedNamespace(space)) { VisitNamespace(space); } } }
// POST: Service/PluginServices/Namespaces public virtual NamespaceList Namespaces(string args, Guid workspaceId, Guid dataListId) { var result = new NamespaceList(); try { var pluginSource = JsonConvert.DeserializeObject <PluginSource>(args); if (pluginSource != null) { var broker = new PluginBroker(); return(broker.GetNamespaces(pluginSource)); } } catch (Exception ex) { RaiseError(ex); } return(result); }
private SBExpressionData ResolveDotIdentifierNamespace(SBExpressionData left, SBExpressionData right) { NamespaceList subs = null; var rightString = right.Value as string; if (left.NamespaceList.TryGetSubList(rightString, ref subs)) { return new SBExpressionData(HomeType.Immediate, SBExpressionType.Namespace, null, null, subs); } else { var type = left.NamespaceList.ListTypes(false).FirstOrDefault(ti => ti.Name == rightString); if (type != null) { return new SBExpressionData(HomeType.Immediate, SBExpressionType.TypeReference, (TypeReference)type, token: right.Token); } else { //throw new Exception("Sub-namespace was not found (" + right + ")."); return null; } } }
// POST: Service/PluginServices/Namespaces public virtual NamespaceList NamespacesWithJsonObjects(PluginSource pluginSource, Guid workspaceId, Guid dataListId) { var result = new NamespaceList(); try { if (pluginSource != null) { var broker = new PluginBroker(); return(broker.GetNamespacesWithJsonObjects(pluginSource)); } } catch (BadImageFormatException e) { RaiseError(e); throw; } catch (Exception ex) { RaiseError(ex); } return(result); }
protected virtual IList <XmlNode> _GetGeneratedNodes ( Action <System.Xml.XmlWriter> generateOutput ) { StringBuilder stringBuilder = new StringBuilder(); using (System.IO.StringWriter writer = new System.IO.StringWriter(stringBuilder)) { using (System.Xml.XmlWriter xmlWriter = System.Xml.XmlTextWriter.Create(writer, this._GetWriterSettings())) { this._WriteStartRootNode ( xmlWriter, "testNode", "http://www.craighawker.co.uk/xcri/1.1/tests", NamespaceList.GetNamespaces(NamespaceList.Namespaces.None) ); xmlWriter.Flush(); int startAt = stringBuilder.ToString().Length; generateOutput(xmlWriter); xmlWriter.Flush(); xmlWriter.WriteEndElement(); } } XmlDocument document = new XmlDocument(); document.LoadXml(stringBuilder.ToString()); List <XmlNode> toReturn = new List <XmlNode>(); foreach (XmlNode child in document.DocumentElement.ChildNodes) { toReturn.Add(child); } return(toReturn); }
public virtual void VisitNamespaceList(NamespaceList namespaces) { if (namespaces == null) return; for (int i = 0, n = namespaces.Count; i < n; i++) this.VisitNamespace(namespaces[i]); }
private void WriteNamespaces(NamespaceList spaces) { // This is a part of the doc model; don't do this anymore }
public NamespaceList GetNamespaceList() { if(this.reader != null) return this.GetNamespaceListFromReader(); TypeNodeList types = this.Types; int n = types == null ? 0 : types.Count; if(this.namespaceList == null || n > this.savedTypesLength) { lock(this) { if(this.namespaceList != null && this.types != null && this.types.Count == this.savedTypesLength) return this.namespaceList; NamespaceList nsList = this.namespaceList = new NamespaceList(); TrivialHashtable nsTable = this.validNamespaces = new TrivialHashtable(); for(int i = 0; i < n; i++) { //^ assert this.types != null; TypeNode t = this.types[i]; if(t == null) continue; if(t.Namespace == null) t.Namespace = Identifier.Empty; Namespace ns = nsTable[t.Namespace.UniqueIdKey] as Namespace; if(ns != null) { if(t.IsPublic) ns.isPublic = true; ns.Types.Add(t); continue; } ns = new Namespace(t.Namespace); ns.isPublic = t.IsPublic; ns.Types = new TypeNodeList(); ns.Types.Add(t); nsTable[t.Namespace.UniqueIdKey] = ns; nsList.Add(ns); } } } return this.namespaceList; }
public virtual Differences VisitNamespaceList(NamespaceList list1, NamespaceList list2, out NamespaceList changes, out NamespaceList deletions, out NamespaceList insertions){ changes = list1 == null ? null : list1.Clone(); deletions = list1 == null ? null : list1.Clone(); insertions = list1 == null ? new NamespaceList() : list1.Clone(); //^ assert insertions != null; Differences differences = new Differences(); //Compare definitions that have matching key attributes TrivialHashtable matchingPosFor = new TrivialHashtable(); TrivialHashtable matchedNodes = new TrivialHashtable(); for (int j = 0, n = list2 == null ? 0 : list2.Count; j < n; j++){ //^ assert list2 != null; Namespace nd2 = list2[j]; if (nd2 == null || nd2.Name == null) continue; matchingPosFor[nd2.Name.UniqueIdKey] = j; insertions.Add(null); } for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){ //^ assert list1 != null && changes != null && deletions != null; Namespace nd1 = list1[i]; if (nd1 == null || nd1.Name == null) continue; object pos = matchingPosFor[nd1.Name.UniqueIdKey]; if (!(pos is int)) continue; //^ assert pos != null; //^ assume list2 != null; //since there was entry int matchingPosFor int j = (int)pos; Namespace nd2 = list2[j]; //^ assume nd2 != null; //nd1 and nd2 have the same key attributes and are therefore treated as the same entity matchedNodes[nd1.UniqueKey] = nd1; matchedNodes[nd2.UniqueKey] = nd2; //nd1 and nd2 may still be different, though, so find out how different Differences diff = this.VisitNamespace(nd1, nd2); if (diff == null){Debug.Assert(false); continue;} if (diff.NumberOfDifferences != 0){ changes[i] = diff.Changes as Namespace; deletions[i] = diff.Deletions as Namespace; insertions[i] = diff.Insertions as Namespace; insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation Debug.Assert(diff.Changes == changes[i] && diff.Deletions == deletions[i] && diff.Insertions == insertions[i]); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; continue; } changes[i] = null; deletions[i] = null; insertions[i] = null; insertions[n+j] = nd1; //Records the position of nd2 in list2 in case the change involved a permutation } //Find deletions for (int i = 0, n = list1 == null ? 0 : list1.Count; i < n; i++){ //^ assert list1 != null && changes != null && deletions != null; Namespace nd1 = list1[i]; if (nd1 == null) continue; if (matchedNodes[nd1.UniqueKey] != null) continue; changes[i] = null; deletions[i] = nd1; insertions[i] = null; differences.NumberOfDifferences += 1; } //Find insertions for (int j = 0, n = list1 == null ? 0 : list1.Count, m = list2 == null ? 0 : list2.Count; j < m; j++){ //^ assert list2 != null; Namespace nd2 = list2[j]; if (nd2 == null) continue; if (matchedNodes[nd2.UniqueKey] != null) continue; insertions[n+j] = nd2; //Records nd2 as an insertion into list1, along with its position in list2 differences.NumberOfDifferences += 1; //REVIEW: put the size of the tree here? } if (differences.NumberOfDifferences == 0){ changes = null; deletions = null; insertions = null; } return differences; }
internal void GetNamespaces() //^ ensures this.namespaceTable != null; { TypeDefRow[] typeDefs = this.tables.TypeDefTable; int n = typeDefs.Length; TrivialHashtable nsT = this.namespaceTable = new TrivialHashtable(n * 2); TrivialHashtable nsFor = new TrivialHashtable(); NamespaceList nsL = this.namespaceList = new NamespaceList(); for(int i = 0; i < n; i++) { TypeDefRow typeDef = typeDefs[i]; TrivialHashtable ns = (TrivialHashtable)nsT[typeDef.NamespaceKey]; Namespace nSpace = (Namespace)nsFor[typeDef.NamespaceKey]; if(ns == null) { nsT[typeDef.NamespaceKey] = ns = new TrivialHashtable(); nsFor[typeDef.NamespaceKey] = nSpace = new Namespace(typeDef.NamespaceId); nsL.Add(nSpace); } Debug.Assert(nSpace != null); if((typeDef.Flags & (int)TypeFlags.VisibilityMask) == 0) ns[typeDef.NameKey] = i + 1; else if((typeDef.Flags & (int)TypeFlags.VisibilityMask) == 1) { nSpace.isPublic = true; ns[typeDef.NameKey] = i + 1; } } }
/// <include file='doc\XmlSerializerNamespaces.uex' path='docs/doc[@for="XmlSerializerNamespaces.ToArray"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public XmlQualifiedName[] ToArray() { return((XmlQualifiedName[])NamespaceList.ToArray(typeof(XmlQualifiedName))); }
// POST: Service/PluginServices/Namespaces public virtual NamespaceList Namespaces(string args, Guid workspaceId, Guid dataListId) { var result = new NamespaceList(); try { var pluginSource = JsonConvert.DeserializeObject<PluginSource>(args); if(pluginSource != null) { var broker = new PluginBroker(); return broker.GetNamespaces(pluginSource); } } catch(Exception ex) { RaiseError(ex); } return result; }
public virtual NamespaceList VisitNamespaceList(NamespaceList namespaces1, NamespaceList namespaces2) { if (namespaces1 == null) return null; for (int i = 0, n = namespaces1.Count, m = namespaces2 == null ? 0 : namespaces2.Count; i < n; i++) { //^ assert namespaces2 != null; if (i >= m) namespaces1[i] = this.VisitNamespace(namespaces1[i], null); else namespaces1[i] = this.VisitNamespace(namespaces1[i], namespaces2[i]); } return namespaces1; }
private NamespaceList GetNamespaceListFromReader() //^ requires this.reader != null; { if(this.namespaceList == null) { lock(Module.GlobalLock) { this.reader.GetNamespaces(); NamespaceList nsList = this.namespaceList = this.reader.namespaceList; TrivialHashtable nsTable = this.validNamespaces = new TrivialHashtable(); for(int i = 0, n = nsList == null ? 0 : nsList.Count; i < n; i++) { //^ assert nsList != null; Namespace ns = nsList[i]; if(ns == null || ns.Name == null) continue; ns.ProvideTypes = new Namespace.TypeProvider(this.GetTypesForNamespace); nsTable[ns.Name.UniqueIdKey] = ns; } } } return this.namespaceList; }
// static EXTERNALS ( ) public static void clear() { allNamespaces = null; }
/// <inheritdoc /> protected override void VisitNamespaces(NamespaceList spaces) { // Construct an assembly catalog foreach(AssemblyNode assembly in this.Assemblies) assemblyNames.Add(assembly.StrongName); // Catalog type hierarchy and interface implementors foreach(var ns in spaces) foreach(var type in ns.Types) if(base.ApiFilter.IsExposedType(type)) { if(type.NodeType == NodeType.Class) this.PopulateDescendantIndex(type); this.PopulateImplementorIndex(type); } // Start the document writer.WriteStartDocument(); writer.WriteStartElement("reflection"); // Write assembly info writer.WriteStartElement("assemblies"); foreach(AssemblyNode assembly in this.Assemblies) this.WriteAssembly(assembly); writer.WriteEndElement(); // Start API info writer.WriteStartElement("apis"); this.StartElementCallbacks("apis", spaces); // Write out information for each namespace. The overall list of namespaces is part of the document // model XSL transformation and isn't generated here. base.VisitNamespaces(spaces); // Finish API info this.EndElementCallbacks("apis", spaces); writer.WriteEndElement(); // Finish document writer.WriteEndElement(); writer.WriteEndDocument(); }
public virtual NamespaceList VisitNamespaceList(NamespaceList namespaces, NamespaceList changes, NamespaceList deletions, NamespaceList insertions){ if (namespaces == null) return changes; if (changes != null){ if (deletions == null || insertions == null) Debug.Assert(false); else{ } }else if (deletions != null) return null; return namespaces; }
private void RecordExtensionMethods(XmlWriter writer, Object info) { NamespaceList spaces = (NamespaceList)info; foreach (Namespace space in spaces) { TypeNodeList types = space.Types; foreach (TypeNode type in types) { MemberList members = type.Members; // go through the members, looking for fields signaling extension methods foreach (Member member in members) { Method method = member as Method; if (method == null) { continue; } if (!reflector.ApiFilter.IsExposedMember(method)) { continue; } if (!HasExtensionAttribute(method)) { continue; } ParameterList parameters = method.Parameters; TypeNode extendedType = parameters[0].Type; // recognize generic extension methods where the extended type is a specialization of a generic type, // and the extended type's specialized template arg is a type parameter declared by the generic extension method // In this case, we need to save a TypeNode for the non-specialized type in the index, // because a TypeNode for the specialized type won't match correctly in AddExtensionMethods // Note: we are not interested in extended types that are specialized by a specific type rather than by the extension method's template param. if (method.IsGeneric && (method.TemplateParameters.Count > 0)) { if (extendedType.IsGeneric && (extendedType.TemplateArguments != null) && (extendedType.TemplateArguments.Count == 1)) { // is the extended type's template arg a template parameter, rather than a specialized type? TypeNode arg = extendedType.TemplateArguments[0]; if (arg.IsTemplateParameter) { // is the template parameter declared on the extension method ITypeParameter gtp = (ITypeParameter)arg; if ((gtp.DeclaringMember == method) && (gtp.ParameterListIndex == 0)) { // get a TypeNode for the non-specialized type extendedType = ReflectionUtilities.GetTemplateType(extendedType); } } } } List <Method> methods = null; if (!index.TryGetValue(extendedType, out methods)) { methods = new List <Method>(); index.Add(extendedType, methods); } methods.Add(method); } } } }
//===================================================================== /// <summary> /// This is called to visit all namespaces, types, and members in the list of assemblies to be documented /// </summary> public void VisitApis() { // Store types. We have to do this after all assemblies are registered because the resolution may // not work unless all the assemblies we need are in the resolver cache. foreach(AssemblyNode assembly in assemblies) { this.StoreTypes(assembly.Types); if(this.Canceled) break; } if(!this.Canceled) { NamespaceList spaces = new NamespaceList(); foreach(Namespace space in catalog.Values) if(filter.IsExposedNamespace(space)) spaces.Add(space); if(!this.Canceled) this.VisitNamespaces(spaces); } }
/// <summary> /// Fetches the name space list object. /// </summary> /// <param name="pluginSource">The plugin source.</param> /// <returns></returns> public NamespaceList FetchNamespaceListObject(PluginSource pluginSource) { // BUG 9500 - 2013.05.31 - TWR : added check to avoid nulling AssemblyLocation/Name in tests if(string.IsNullOrEmpty(pluginSource.AssemblyLocation)) { pluginSource = new PluginSources().Get(pluginSource.ResourceID.ToString(), Guid.Empty, Guid.Empty); } var interrogatePlugin = ReadNamespaces(pluginSource.AssemblyLocation, pluginSource.AssemblyName); var namespacelist = new NamespaceList(); namespacelist.AddRange(interrogatePlugin); return namespacelist; }
//===================================================================== /// <summary> /// This finds all extension methods, adds information about them to the types, and tracks /// them for adding to the reflection data later in the other callbacks. /// </summary> /// <param name="writer">The reflection data XML writer</param> /// <param name="info">For this callback, the information object is a namespace list</param> private void RecordExtensionMethods(XmlWriter writer, object info) { NamespaceList spaces = (NamespaceList)info; foreach (Namespace space in spaces) { // !EFW - Don't bother checking unexposed namespaces if (!mrw.ApiFilter.IsExposedNamespace(space)) { continue; } TypeNodeList types = space.Types; foreach (TypeNode type in types) { // !EFW - Don't bother checking unexposed types if (!mrw.ApiFilter.IsExposedType(type)) { continue; } // Go through the members looking for fields signaling extension methods. Members may be // added so convert to a list first to avoid enumeration issues. foreach (Member member in type.Members.ToList()) { Method method = member as Method; if (method == null || !mrw.ApiFilter.IsExposedMember(method) || !method.Attributes.Any(a => a.Type.FullName == "System.Runtime.CompilerServices.ExtensionAttribute")) { continue; } ParameterList parameters = method.Parameters; // !EFW - This fix was reported without an example. Sometimes, there are no parameters. // In such cases, ignore it to prevent a crash. if (parameters == null || parameters.Count == 0) { continue; } TypeNode extendedType = parameters[0].Type; // Recognize generic extension methods where the extended type is a specialization of a // generic type and the extended type's specialized template argument is a type parameter // declared by the generic extension method. In this case, we need to save a TypeNode // for the non-specialized type in the index because a TypeNode for the specialized type // won't match correctly in AddExtensionMethods(). NOTE: we are not interested in // extended types that are specialized by a specific type rather than by the extension // method's template parameter. if (method.IsGeneric && method.TemplateParameters.Count > 0) { if (extendedType.IsGeneric && extendedType.TemplateArguments != null && extendedType.TemplateArguments.Count == 1) { // Is the extended type's template argument a template parameter rather than a // specialized type? TypeNode arg = extendedType.TemplateArguments[0]; if (arg.IsTemplateParameter) { // Is the template parameter declared on the extension method ITypeParameter gtp = (ITypeParameter)arg; if (gtp.DeclaringMember == method && gtp.ParameterListIndex == 0) { // Get a TypeNode for the non-specialized type extendedType = extendedType.GetTemplateType(); } } } } List <Method> methods = null; if (!index.TryGetValue(extendedType, out methods)) { methods = new List <Method>(); index.Add(extendedType, methods); } methods.Add(method); } } } }
public Namespace(Identifier name, Identifier fullName, AliasDefinitionList aliasDefinitions, UsedNamespaceList usedNamespaces, NamespaceList nestedNamespaces, TypeNodeList types) : base(NodeType.Namespace) { this.Name = name; this.FullNameId = fullName; if(fullName != null) this.fullName = fullName.ToString(); this.AliasDefinitions = aliasDefinitions; this.NestedNamespaces = nestedNamespaces; this.Types = types; this.UsedNamespaces = usedNamespaces; }
// Visit Object Model public void VisitApis() { // store types // we have to do this after all assemblies are registered because the resolution may not work unless // all the assemblies we need are in the resolver cache //Console.WriteLine("storing types"); foreach (AssemblyNode assembly in assemblies) { //Console.WriteLine("assembly {0}", assembly.Name); //Console.WriteLine("has {0} types", assembly.Types.Count); StoreTypes(assembly.Types); //Console.WriteLine("done with assembly"); } //Console.WriteLine("done storing types"); //Console.WriteLine("visiting namespaces"); NamespaceList spaces = new NamespaceList(); foreach (Namespace space in catalog.Values) { if (filter.IsExposedNamespace(space)) spaces.Add(space); } VisitNamespaces(spaces); }
public EventingVisitor(Action<NamespaceList> visitNamespaceList) { VisitedNamespaceList += visitNamespaceList; } public event Action<NamespaceList> VisitedNamespaceList; public override NamespaceList VisitNamespaceList(NamespaceList namespaces) { if (VisitedNamespaceList != null) VisitedNamespaceList(namespaces); return base.VisitNamespaceList(namespaces); }
protected virtual void VisitNamespaces(NamespaceList spaces) { // sort namespaces by name Namespace[] sorted_spaces = new Namespace[spaces.Count]; for (int i = 0; i < spaces.Count; i++) sorted_spaces[i] = spaces[i]; Array.Sort < Namespace >(sorted_spaces, namespaceComparison); // visit them foreach (Namespace space in sorted_spaces) { if (filter.IsExposedNamespace(space)) VisitNamespace(space); } }
public virtual NamespaceList VisitNamespaceList(NamespaceList namespaces){ if (namespaces == null) return null; for (int i = 0, n = namespaces.Count; i < n; i++) namespaces[i] = this.VisitNamespace(namespaces[i]); return namespaces; }
// visitation logic protected override void VisitNamespaces(NamespaceList spaces) { // construct a sorted assembly catalog foreach (AssemblyNode assembly in this.Assemblies) { assemblyNames.Add(assembly.StrongName, null); } // catalog type hierarchy and interface implementors for (int i = 0; i < spaces.Count; i++) { TypeNodeList types = spaces[i].Types; for (int j = 0; j < types.Count; j++) { TypeNode type = types[j]; if (ApiFilter.IsExposedType(type)) { if (type.NodeType == NodeType.Class) PopulateDescendentIndex(type); PopulateImplementorIndex(type); } } } // start the document writer.WriteStartDocument(); writer.WriteStartElement("reflection"); // write assembly info writer.WriteStartElement("assemblies"); foreach (AssemblyNode assembly in this.Assemblies) { WriteAssembly(assembly); } writer.WriteEndElement(); // start api info writer.WriteStartElement("apis"); StartElementCallbacks("apis", spaces); // write it WriteNamespaces(spaces); base.VisitNamespaces(spaces); // finish api info EndElementCallbacks("apis", spaces); writer.WriteEndElement(); // finish document writer.WriteEndElement(); writer.WriteEndDocument(); }
private void AddAttachedMembers(XmlWriter writer, object info) { NamespaceList spaces = (NamespaceList)info; foreach (Namespace space in spaces) { TypeNodeList types = space.Types; foreach (TypeNode type in types) { MemberList members = type.Members; // go through the members, looking for fields signaling attached properties foreach (Member member in members) { // we need a visible, static, field... if (!member.IsStatic || !member.IsVisibleOutsideAssembly || member.NodeType != NodeType.Field) { continue; } Field field = (Field)member; // of type dependency property.... if (field.Type.FullName != "System.Windows.DependencyProperty") { continue; } // with a name ending in "Property"... string name = field.Name.Name; if (!name.EndsWith("Property")) { continue; } name = name.Substring(0, name.Length - 8); // look for a getter and/or a setter Method getter = null; MemberList candidateGetters = type.GetMembersNamed(new Identifier("Get" + name)); for (int i = 0; i < candidateGetters.Count; i++) { Member candidateGetter = candidateGetters[i]; if ((candidateGetter.NodeType == NodeType.Method) && candidateGetter.IsStatic && candidateGetter.IsVisibleOutsideAssembly) { getter = (Method)candidateGetter; } } Method setter = null; MemberList candidateSetters = type.GetMembersNamed(new Identifier("Set" + name)); for (int i = 0; i < candidateSetters.Count; i++) { Member candidateSetter = candidateSetters[i]; if ((candidateSetter.NodeType == NodeType.Method) && candidateSetter.IsStatic && candidateSetter.IsVisibleOutsideAssembly) { setter = (Method)candidateSetter; } } if ((getter == null) && (setter == null)) { continue; } // make sure there isn't already such a property Property existingProperty = type.GetProperty(new Identifier(name), new TypeNode[0]); if (existingProperty != null && existingProperty.IsVisibleOutsideAssembly) { continue; } // okay, this really is an indication of an attached property, so create one Property attachedProperty = new Property(type, null, PropertyFlags.None, new Identifier(name), getter, setter); // attached properties have no parameters attachedProperty.Parameters = ParameterList.Empty; // attached properties are instance properties // somehow mark as attached? type.Members.Add(attachedProperty); attachedMembers.Add(attachedProperty, field); } // go through the members, looking for fields signaling attached events foreach (Member member in members) { if (!member.IsStatic || !member.IsVisibleOutsideAssembly) { continue; } if (member.NodeType != NodeType.Field) { continue; } Field field = (Field)member; if (field.Type.FullName != "System.Windows.RoutedEvent") { continue; } string name = field.Name.Name; if (!name.EndsWith("Event")) { continue; } name = name.Substring(0, name.Length - 5); Method adder = null; MemberList candidateAdders = type.GetMembersNamed(new Identifier("Add" + name + "Handler")); for (int i = 0; i < candidateAdders.Count; i++) { Member candidateAdder = candidateAdders[i]; if ((candidateAdder.NodeType == NodeType.Method) && candidateAdder.IsStatic) { adder = (Method)candidateAdder; } } Method remover = null; MemberList candidateRemovers = type.GetMembersNamed(new Identifier("Remove" + name + "Handler")); for (int i = 0; i < candidateRemovers.Count; i++) { Member candidateRemover = candidateRemovers[i]; if ((candidateRemover.NodeType == NodeType.Method) && candidateRemover.IsStatic) { remover = (Method)candidateRemover; } } if ((adder == null) || (remover == null)) { continue; } // make sure there isn't already such an event Event existingEvent = type.GetEvent(new Identifier(name)); if (existingEvent != null && existingEvent.IsVisibleOutsideAssembly) { continue; } // okay, this really is an indication of an attached event, so create one TypeNode handler = adder.Parameters[1].Type; Event attachedEvent = new Event(type, null, EventFlags.None, new Identifier(name), adder, null, remover, handler); attachedEvent.HandlerFlags = adder.Flags; // attached events are instance events // mark as attached? type.Members.Add(attachedEvent); attachedMembers.Add(attachedEvent, field); } } } }
public void PopulateTypeList(TypeNodeList types, NamespaceList namespaces){ if (types == null){Debug.Assert(false); return;} for (int i = 0, n = namespaces == null ? 0 : namespaces.Count; i < n; i++){ Namespace ns = namespaces[i]; if (ns == null) continue; if (ns.NestedNamespaces != null) this.PopulateTypeList(types, ns.NestedNamespaces); TypeNodeList nTypes = ns.Types; for (int j = 0, m = nTypes == null ? 0 : nTypes.Count; j < m; j++){ TypeNode t = nTypes[j]; if (t == null) continue; this.PopulateTypeList(types, t); } } }
/// <summary> /// This is used to visit a list of namespaces /// </summary> /// <param name="spaces">The list of namespaces to visit</param> protected virtual void VisitNamespaces(NamespaceList spaces) { // Visit the namespaces in sorted order var sortedNamespaces = spaces.OrderBy(s => s.FullName).ToList(); foreach(Namespace space in sortedNamespaces) { if(filter.IsExposedNamespace(space)) this.VisitNamespace(space); if(this.Canceled) break; } }
public Type[] Execute(System.Reflection.Assembly assembly) { var targetNamespaces = NamespaceList.Create(); var resourceNames = assembly.GetManifestResourceNames().Where(n => n.EndsWith("VenusIoc.config")); foreach (var resourceName in resourceNames) { var xmlDoc = new XmlDocument(); using (var sr = new StreamReader(assembly.GetManifestResourceStream(resourceName))) { xmlDoc.Load(sr); foreach (var node in xmlDoc.DocumentElement.SelectNodes("components/assemblyScan/namespace")) { var name = ((XmlElement)node).GetAttribute("name"); if (!string.IsNullOrWhiteSpace(name)) { targetNamespaces.Add(name.Split('.')); } } } } if (targetNamespaces.Count == 0) { return(new Type[0]); } var types = new List <Type>(); var checkList = new HashSet <string>(); var ignoreList = new HashSet <string>(); foreach (var type in assembly.GetTypes()) { bool toCheck = false; if (!ignoreList.Contains(type.Namespace) && type.Namespace != null) { if (checkList.Contains(type.Namespace)) { toCheck = true; } else { if (targetNamespaces.Include(type.Namespace.Split('.'))) { checkList.Add(type.Namespace); toCheck = true; } else { ignoreList.Add(type.Namespace); } } } if (toCheck) { if (!type.IsAbstract && type.IsDefined(typeof(NamedAttribute), false)) { types.Add(type); } } } return(types.ToArray()); }
//===================================================================== /// <summary> /// This finds all attached properties and events, adds information about them to the types, and tracks /// them for adding to the reflection data later in the other callbacks. /// </summary> /// <param name="writer">The reflection data XML writer</param> /// <param name="info">For this callback, the information object is a namespace list</param> private void AddAttachedMembers(XmlWriter writer, object info) { NamespaceList spaces = (NamespaceList)info; foreach (Namespace space in spaces) { TypeNodeList types = space.Types; foreach (TypeNode type in types) { MemberList members = new MemberList(type.Members); // Go through the members looking for fields signaling attached properties foreach (Member member in members) { // We need a visible, static, field... if (!member.IsStatic || !member.IsVisibleOutsideAssembly || member.NodeType != NodeType.Field) { continue; } Field field = (Field)member; // ... of type dependency property ... if (field.Type.FullName != dependencyPropertyTypeName) { continue; } // ... with a name ending in "Property". string name = field.Name.Name; if (!name.EndsWith(dependencyPropertySuffix, StringComparison.Ordinal)) { continue; } name = name.Substring(0, name.Length - dependencyPropertySuffix.Length); // Look for a getter and/or a setter Method getter = null; MemberList candidateGetters = type.GetMembersNamed(new Identifier("Get" + name)); foreach (var candidateGetter in candidateGetters) { if (candidateGetter.NodeType == NodeType.Method && candidateGetter.IsStatic && candidateGetter.IsVisibleOutsideAssembly) { getter = (Method)candidateGetter; } } Method setter = null; MemberList candidateSetters = type.GetMembersNamed(new Identifier("Set" + name)); foreach (var candidateSetter in candidateSetters) { if (candidateSetter.NodeType == NodeType.Method && candidateSetter.IsStatic && candidateSetter.IsVisibleOutsideAssembly) { setter = (Method)candidateSetter; } } if (getter == null && setter == null) { continue; } // Make sure there isn't already such a property Property existingProperty = type.GetProperty(new Identifier(name), new TypeNode[0]); if (existingProperty != null && existingProperty.IsVisibleOutsideAssembly) { continue; } // Okay, this really is an indication of an attached property, so create one Property attachedProperty = new Property(type, null, PropertyFlags.None, new Identifier(name), getter, setter); // Attached properties have no parameters attachedProperty.Parameters = ParameterList.Empty; // Attached properties are instance properties type.Members.Add(attachedProperty); attachedMembers.Add(attachedProperty, field); } // Go through the members, looking for fields signaling attached events foreach (Member member in members) { // Follow a similar approach as above but for an event if (!member.IsStatic || !member.IsVisibleOutsideAssembly) { continue; } if (member.NodeType != NodeType.Field) { continue; } Field field = (Field)member; if (field.Type.FullName != routedEventTypeName) { continue; } string name = field.Name.Name; if (!name.EndsWith(routedEventSuffix, StringComparison.Ordinal)) { continue; } name = name.Substring(0, name.Length - routedEventSuffix.Length); Method adder = null; MemberList candidateAdders = type.GetMembersNamed(new Identifier("Add" + name + "Handler")); foreach (var candidateAdder in candidateAdders) { if (candidateAdder.NodeType == NodeType.Method && candidateAdder.IsStatic) { adder = (Method)candidateAdder; } } Method remover = null; MemberList candidateRemovers = type.GetMembersNamed(new Identifier("Remove" + name + "Handler")); foreach (var candidateRemover in candidateRemovers) { if (candidateRemover.NodeType == NodeType.Method && candidateRemover.IsStatic) { remover = (Method)candidateRemover; } } if (adder == null || remover == null) { continue; } // Make sure there isn't already such an event Event existingEvent = type.GetEvent(new Identifier(name)); if (existingEvent != null && existingEvent.IsVisibleOutsideAssembly) { continue; } // Okay, this really is an indication of an attached event, so create one TypeNode handler = adder.Parameters[1].Type; Event attachedEvent = new Event(type, null, EventFlags.None, new Identifier(name), adder, null, remover, handler); attachedEvent.HandlerFlags = adder.Flags; type.Members.Add(attachedEvent); attachedMembers.Add(attachedEvent, field); } } } }
public virtual void FindTypesToBeDuplicated(NamespaceList namespaces) { if (namespaces == null) return; for (int i = 0, n = namespaces.Count; i < n; i++) { Namespace nspace = namespaces[i]; if (nspace == null) continue; this.FindTypesToBeDuplicated(nspace.Types); this.FindTypesToBeDuplicated(nspace.NestedNamespaces); } }
public override NamespaceList VisitNamespaceList(NamespaceList namespaces) { if(namespaces == null) return null; return base.VisitNamespaceList(new NamespaceList(namespaces)); }
internal Generator() : base() { base._Namespaces = NamespaceList.GetNamespaces(NamespaceList.Namespaces.XCRICAP11_All); }