public static string MakeSafeIdentifier(ICodeDocumentType codeDocumentType, string identifier, bool escape) { if (codeDocumentType.Name != "Javascript") { char[] chrArray = new char[] { '\u005F' }; identifier = Microsoft.Expression.Project.Build.CodeGenerator.FixUpIdentifier(identifier, chrArray); } else { char[] chrArray1 = new char[] { '\u005F', '$' }; identifier = Microsoft.Expression.Project.Build.CodeGenerator.FixUpIdentifier(identifier, chrArray1); } if (escape) { ICodeGeneratorHost codeGeneratorHost = codeDocumentType as ICodeGeneratorHost; if (codeGeneratorHost != null) { identifier = codeGeneratorHost.CodeDomProvider.CreateEscapedIdentifier(identifier); } } if (identifier == "_" && codeDocumentType.Name == "VB") { return("__"); } return(identifier); }
private static StringComparison GetMethodNameComparison(ITypeResolver typeResolver) { StringComparison stringComparison = StringComparison.Ordinal; ProjectXamlContext projectXamlContext = ProjectXamlContext.FromProjectContext(typeResolver as IProjectContext); if (projectXamlContext == null) { return(stringComparison); } IProject project = (IProject)projectXamlContext.GetService(typeof(IProject)); if (project == null || project.CodeDocumentType == null) { return(stringComparison); } ICodeGeneratorHost codeGeneratorHost = project.CodeDocumentType as ICodeGeneratorHost; if (codeGeneratorHost == null || (codeGeneratorHost.CodeDomProvider.LanguageOptions & LanguageOptions.CaseInsensitive) != LanguageOptions.CaseInsensitive) { return(stringComparison); } stringComparison = StringComparison.OrdinalIgnoreCase; return(stringComparison); }
private void CacheStateIfNecessary() { if (this.eventHandlers != null) { return; } this.eventHandlers = (ICollection <EventHandlerModel>) new List <EventHandlerModel>(); this.solution = this.designerContext.ProjectManager.CurrentSolution; this.project = ProjectHelper.GetProject(this.designerContext.ProjectManager, this.document.DocumentContext); if (this.project == null) { return; } ITypeId typeId = (ITypeId)this.document.XamlDocument.CodeBehindClass; if (typeId == null) { this.state = EventsModel.State.NoCodeBehind; } else { if (this.node == null) { return; } IProjectItem projectItem = this.project.FindItem(this.document.DocumentReference); if (projectItem == null) { return; } IProjectItem codeBehindItem = projectItem.CodeBehindItem; if (codeBehindItem == null) { this.state = EventsModel.State.NoCodeBehind; } else { ICodeGeneratorHost codeGeneratorHost = codeBehindItem.DocumentType as ICodeGeneratorHost; if (codeGeneratorHost == null) { return; } ITypeDeclaration typeInFile = this.designerContext.CodeModelService.FindTypeInFile((object)this.solution, (object)codeBehindItem, (IEnumerable <string>)EventsModel.Model.GetProjectItemPath(codeBehindItem), typeId.FullName); CodeDomProvider codeDomProvider = codeGeneratorHost.CodeDomProvider; EventHandlerProvider eventHandlerProvider = new EventHandlerProvider(this.designerContext, this.document, typeInFile); this.state = EventsModel.State.Enabled; IProjectContext projectContext = this.document.ProjectContext; IType type = this.node.Type; List <EventInformation> list = new List <EventInformation>(EventInformation.GetEventsForType((ITypeResolver)projectContext, type, MemberType.LocalEvent)); EventDescriptorCollection events = TypeUtilities.GetEvents(type.RuntimeType); list.Sort(new Comparison <EventInformation>(EventInformation.CompareNames)); foreach (EventInformation eventInfo in list) { EventDescriptor eventDescriptor = events[eventInfo.EventName]; AttributeCollection eventAttributes = eventDescriptor != null?TypeUtilities.GetAttributes((MemberDescriptor)eventDescriptor) : (AttributeCollection)null; this.eventHandlers.Add(new EventHandlerModel(eventInfo, this.node, codeDomProvider, (IEventHandlerProvider)eventHandlerProvider, eventAttributes)); } } } }