/// <summary> /// Gets a tag prefix, also returning the directive that would have to be added if necessary. /// </summary> public string GetTagPrefixWithNewDirective(IType control, string assemblyName, string desiredPrefix, out RegisterDirective directiveNeededToAdd) { directiveNeededToAdd = null; string existingPrefix = GetTagPrefix(control); if (existingPrefix != null) { return(existingPrefix); } //TODO: detect control name conflicts string prefix = desiredPrefix; if (desiredPrefix == null) { prefix = GetPrefix(control); } var an = MonoDevelop.Core.Assemblies.SystemAssemblyService.ParseAssemblyName(assemblyName); directiveNeededToAdd = new AssemblyRegisterDirective(prefix, control.Namespace, an.Name); return(prefix); }
public void AddReference(Type type, string prefix) { if (type.Assembly == typeof(System.Web.UI.WebControls.WebControl).Assembly) { return; } //check namespace is not already registered foreach (var directive in RegisteredTags) { AssemblyRegisterDirective ard = directive as AssemblyRegisterDirective; if (0 == string.Compare(ard.Namespace, type.Namespace, StringComparison.Ordinal)) { throw new Exception("That namespace is already registered with another prefix"); } if (0 == string.Compare(directive.TagPrefix, prefix, StringComparison.OrdinalIgnoreCase)) { //duplicate prefix; generate a new one. //FIXME: possibility of stack overflow with too many default prefixes in existing document AddReference(type); return; } } Project.References.Add(new ProjectReference(ReferenceType.Assembly, type.Assembly.ToString())); /* * TODO: insert the reference into the document tree */ }
public IType GetControlType(string tagPrefix, string tagName) { if (String.IsNullOrEmpty(tagPrefix)) { return(null); } IType type = null; if (0 == string.Compare(tagPrefix, "asp", StringComparison.OrdinalIgnoreCase)) { type = TypeCtx.SystemTypeLookup(tagName); if (type != null) { return(type); } } foreach (var rd in RegisteredTags) { if (string.Compare(rd.TagPrefix, tagPrefix, StringComparison.OrdinalIgnoreCase) != 0) { continue; } AssemblyRegisterDirective ard = rd as AssemblyRegisterDirective; if (ard != null) { string assembly = ard.Assembly; var dom = TypeCtx.ResolveAssembly(ard.Assembly); if (dom == null) { continue; } type = WebTypeContext.AssemblyTypeLookup(dom, ard.Namespace, tagName); if (type != null) { return(type); } continue; } var crd = rd as ControlRegisterDirective; if (crd != null && string.Compare(crd.TagName, tagName, StringComparison.OrdinalIgnoreCase) == 0) { return(TypeCtx.GetUserControlType(crd.Src, Doc.FileName)); } } //returns null if type not found return(TypeCtx.GetRegisteredType(DirectoryPath, tagPrefix, tagName)); }
public string GetTagPrefix(Type objectType) { if (objectType.Namespace.StartsWith("System.Web.UI")) { return("asp"); } foreach (var directive in RegisteredTags) { AssemblyRegisterDirective ard = directive as AssemblyRegisterDirective; if (ard != null) { if (string.Compare(ard.Namespace, objectType.Namespace, StringComparison.OrdinalIgnoreCase) == 0) { return(directive.TagPrefix); } } } throw new Exception("A tag prefix has not been registered for " + objectType.ToString()); }
/// <summary> /// Gets a tag prefix, also returning the directive that would have to be added if necessary. /// </summary> public string GetTagPrefixWithNewDirective (IType control, string assemblyName, string desiredPrefix, out RegisterDirective directiveNeededToAdd) { directiveNeededToAdd = null; string existingPrefix = GetTagPrefix (control); if (existingPrefix != null) return existingPrefix; //TODO: detect control name conflicts string prefix = desiredPrefix; if (desiredPrefix == null) prefix = GetPrefix (control); var an = MonoDevelop.Core.Assemblies.SystemAssemblyService.ParseAssemblyName (assemblyName); directiveNeededToAdd = new AssemblyRegisterDirective (prefix, control.Namespace, an.Name); return prefix; }