/// <summary> /// Parses typeof representation. /// </summary> /// <param name="valueRepresentation">The value representation.</param> /// <param name="contextType">Type of the context.</param> /// <param name="contextElement">The context element.</param> /// <returns>Descriptor of type if available, <c>null</c> otherwise.</returns> private TypeDescriptor parseType(ref string valueRepresentation, TypeDescriptor contextType, CodeElement contextElement) { var typePrefix = "typeof("; if (valueRepresentation.StartsWith(typePrefix)) { valueRepresentation = valueRepresentation.Substring(typePrefix.Length).Replace(")", ""); valueRepresentation = TranslatePath(valueRepresentation); //find type var implicitNamespaces = GetImplicitNamespaces(contextType); var namespaces = implicitNamespaces.Concat(GetNamespaces(contextElement)); foreach (var ns in namespaces) { var prefix = ns == "" ? "" : ns + "."; var descriptor = TypeDescriptor.Create(prefix + valueRepresentation); if (TypeServices.GetChain(descriptor) != null) { return(descriptor); } } return(TypeDescriptor.Create(valueRepresentation)); } return(null); }
/// <summary> /// Create <see cref="InheritanceChain" /> enumeration from given typeNodes. /// </summary> /// <param name="typeNodes">The type nodes.</param> /// <returns>IEnumerable<InheritanceChain>.</returns> private IEnumerable <InheritanceChain> createInheritanceChains(CodeElements typeNodes) { var chains = new List <InheritanceChain>(); foreach (CodeElement typeNode in typeNodes) { var descriptor = InfoBuilder.CreateDescriptor(typeNode); var chain = TypeServices.GetChain(descriptor); chains.Add(chain); } return(chains); }
public override InheritanceChain GetInheritanceChain(PathInfo typePath) { //informace o dědičnosti poskytujeme pouze //pro náš definovaný typ if (typePath.Signature == _declaringType.TypeName) { //definovaný typ je potomkem typu object InheritanceChain baseType = TypeServices.GetChain(TypeDescriptor.ObjectInfo); return(TypeServices.CreateChain(_declaringType, new[] { baseType })); } //dotaz se týkal typu, který nedefinujeme return(null); }
/// <summary> /// Get <see cref="TypeDescriptor" /> from mapped typeNameSuffix by /// namespace expansion. /// </summary> /// <param name="typeNameSuffix">Mapped suffix of searched type.</param> /// <returns><see cref="TypeDescriptor" /> from expanded type name suffix if type is available, <c>null</c> otherwise.</returns> internal TypeDescriptor DescriptorFromSuffix(string typeNameSuffix) { foreach (var ns in Source.Namespaces) { var fullname = ns == "" ? typeNameSuffix : ns + "." + typeNameSuffix; var typeDescriptor = TypeDescriptor.Create(fullname); var chain = Services.GetChain(typeDescriptor); if (chain != null) { return(typeDescriptor); } } return(null); }
/// <summary> /// Gets inheritance chain for type described by given path. /// </summary> /// <param name="typePath">The type path.</param> /// <returns>InheritanceChain.</returns> public override InheritanceChain GetInheritanceChain(PathInfo typePath) { requireBuilded(); var descriptor = TypeDescriptor.Create(typePath.Name); if (!_knownInheritance.ContainsKey(descriptor)) { //we handle only contained types return(null); } //inheritance according to known definitions return(TypeServices.CreateChain(descriptor, new[] { TypeServices.GetChain(_knownInheritance[descriptor]) })); }