コード例 #1
0
 public Model(DesignerContext designerContext, SceneDocument document, DocumentCompositeNode node)
 {
     this.designerContext = designerContext;
     this.document        = document;
     this.node            = node;
     this.state           = EventsModel.State.Unknown;
 }
コード例 #2
0
            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));
                        }
                    }
                }
            }