当前位置: 首页>>代码示例>>C#>>正文


C# CodeDom.CodeAttachEventStatement类代码示例

本文整理汇总了C#中System.CodeDom.CodeAttachEventStatement的典型用法代码示例。如果您正苦于以下问题:C# CodeAttachEventStatement类的具体用法?C# CodeAttachEventStatement怎么用?C# CodeAttachEventStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CodeAttachEventStatement类属于System.CodeDom命名空间,在下文中一共展示了CodeAttachEventStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Constructor1

		public void Constructor1 ()
		{
			CodeEventReferenceExpression eventref = new CodeEventReferenceExpression ();
			CodeExpression listener = new CodeExpression ();

			CodeAttachEventStatement caes = new CodeAttachEventStatement (eventref, listener);
			Assert.AreSame (eventref, caes.Event, "#1");
			Assert.AreEqual (string.Empty, caes.Event.EventName, "#2");
			Assert.IsNull (caes.Event.TargetObject, "#3");
			Assert.AreSame (listener, caes.Listener, "#4");

			caes.Event = null;
			Assert.IsNotNull (caes.Event, "#5");
			Assert.AreEqual (string.Empty, caes.Event.EventName, "#6");
			Assert.IsNull (caes.Event.TargetObject, "#7");
			Assert.AreSame (listener, caes.Listener, "#8");

			caes.Listener = null;
			Assert.IsNull (caes.Listener, "#9");

			caes.Event = eventref;
			Assert.AreSame (eventref, caes.Event, "#10");

			caes.Listener = listener;
			Assert.AreSame (listener, caes.Listener, "#11");

			caes = new CodeAttachEventStatement ((CodeEventReferenceExpression) null, (CodeExpression) null);
			Assert.IsNotNull (caes.Event, "#12");
			Assert.IsNull (caes.Listener, "#13");
			Assert.AreEqual (string.Empty, caes.Event.EventName, "#14");
			Assert.IsNull (caes.Event.TargetObject, "#15");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:32,代码来源:CodeAttachEventStatementTest.cs

示例2: Constructor0

		public void Constructor0 ()
		{
			CodeAttachEventStatement caes = new CodeAttachEventStatement ();
			Assert.IsNotNull (caes.Event, "#1");
			Assert.IsNull (caes.Listener, "#2");
			Assert.AreEqual (string.Empty, caes.Event.EventName, "#3");
			Assert.IsNull (caes.Event.TargetObject, "#4");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:CodeAttachEventStatementTest.cs

示例3: Constructor0_Deny_Unrestricted

		public void Constructor0_Deny_Unrestricted ()
		{
			CodeAttachEventStatement caes = new CodeAttachEventStatement ();
			Assert.AreEqual (String.Empty, caes.Event.EventName, "Event.EventName");
			Assert.IsNull (caes.Event.TargetObject, "Event.TargetObject");
			caes.Event = new CodeEventReferenceExpression ();
			Assert.IsNull (caes.Listener, "Listener");
			caes.Listener = new CodeExpression ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:CodeAttachEventStatementCas.cs

示例4: TypescriptAttachEventStatement

 public TypescriptAttachEventStatement(
     IExpressionFactory expressionFactory,
     CodeAttachEventStatement statement,
     CodeGeneratorOptions options)
 {
     _expressionFactory = expressionFactory;
     _statement = statement;
     _options = options;
 }
开发者ID:s2quake,项目名称:TypescriptCodeDom,代码行数:9,代码来源:TypescriptAttachEventStatement.cs

示例5: Constructor1_Deny_Unrestricted

		public void Constructor1_Deny_Unrestricted ()
		{
			CodeEventReferenceExpression eventref = new CodeEventReferenceExpression ();
			CodeExpression listener = new CodeExpression ();
			CodeAttachEventStatement caes = new CodeAttachEventStatement (eventref, listener);
			Assert.AreSame (eventref, caes.Event, "Event");
			caes.Event = new CodeEventReferenceExpression ();
			Assert.AreSame (listener, caes.Listener, "Listener");
			caes.Listener = new CodeExpression ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:10,代码来源:CodeAttachEventStatementCas.cs

示例6: Clone

 public static CodeAttachEventStatement Clone(this CodeAttachEventStatement statement)
 {
     if (statement == null) return null;
     CodeAttachEventStatement s = new CodeAttachEventStatement();
     s.EndDirectives.AddRange(statement.EndDirectives);
     s.Event = statement.Event.Clone();
     s.LinePragma = statement.LinePragma;
     s.Listener = statement.Listener.Clone();
     s.StartDirectives.AddRange(statement.StartDirectives);
     s.UserData.AddRange(statement.UserData);
     return s;
 }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:12,代码来源:CodeAttachEventStatementExtensions.cs

示例7: Constructor2_Deny_Unrestricted

		public void Constructor2_Deny_Unrestricted ()
		{
			CodeExpression target = new CodeExpression ();
			string eventName = "Mono";
			CodeExpression listener = new CodeExpression ();
			CodeAttachEventStatement caes = new CodeAttachEventStatement (target, eventName, listener);
			Assert.AreEqual (eventName, caes.Event.EventName, "Event.EventName");
			Assert.AreSame (target, caes.Event.TargetObject, "Event.TargetObject");
			caes.Event = new CodeEventReferenceExpression ();
			Assert.AreSame (listener, caes.Listener, "Listener");
			caes.Listener = new CodeExpression ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:12,代码来源:CodeAttachEventStatementCas.cs

示例8: Serialize

 public override void Serialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor, CodeStatementCollection statements)
 {
     EventDescriptor e = descriptor as EventDescriptor;
     if (manager == null)
     {
         throw new ArgumentNullException("manager");
     }
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     if (e == null)
     {
         throw new ArgumentNullException("descriptor");
     }
     if (statements == null)
     {
         throw new ArgumentNullException("statements");
     }
     try
     {
         IEventBindingService service = (IEventBindingService) manager.GetService(typeof(IEventBindingService));
         if (service != null)
         {
             string methodName = (string) service.GetEventProperty(e).GetValue(value);
             if (methodName != null)
             {
                 CodeExpression targetObject = base.SerializeToExpression(manager, value);
                 if (targetObject != null)
                 {
                     CodeTypeReference delegateType = new CodeTypeReference(e.EventType);
                     CodeDelegateCreateExpression listener = new CodeDelegateCreateExpression(delegateType, _thisRef, methodName);
                     CodeEventReferenceExpression eventRef = new CodeEventReferenceExpression(targetObject, e.Name);
                     CodeAttachEventStatement statement = new CodeAttachEventStatement(eventRef, listener);
                     statement.UserData[typeof(Delegate)] = e.EventType;
                     statements.Add(statement);
                 }
             }
         }
     }
     catch (Exception innerException)
     {
         if (innerException is TargetInvocationException)
         {
             innerException = innerException.InnerException;
         }
         manager.ReportError(System.Design.SR.GetString("SerializerPropertyGenFailed", new object[] { e.Name, innerException.Message }));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:49,代码来源:EventMemberCodeDomSerializer.cs

示例9: GenerateAttachEventStatement

		protected override void GenerateAttachEventStatement (CodeAttachEventStatement statement)
		{
			TextWriter output = Output;

			Output.Write ("AddHandler ");
			if (statement.Event.TargetObject != null) {
				GenerateEventReferenceExpression (statement.Event);
			} else {
				Output.Write (CreateEscapedIdentifier (statement.Event.EventName));
			}
			Output.Write ( ", ");
			GenerateExpression (statement.Listener);
			output.WriteLine ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:14,代码来源:VBCodeGenerator.cs

示例10: Visit

			public void Visit (CodeAttachEventStatement o)
			{
				g.GenerateAttachEventStatement (o);
			}
开发者ID:carrie901,项目名称:mono,代码行数:4,代码来源:CodeGenerator.cs

示例11: GenerateAttachEventStatement

		protected abstract void GenerateAttachEventStatement (CodeAttachEventStatement s);
开发者ID:carrie901,项目名称:mono,代码行数:1,代码来源:CodeGenerator.cs

示例12: GenerateAttachEventStatement

        /// <summary>
        /// Generates code for the specified attach event statement.
        /// </summary>
        /// <remarks><c>EVENT->Add(LISTENER);</c></remarks>
        protected override void GenerateAttachEventStatement(CodeAttachEventStatement e)
        {
            GenerateEventReferenceExpression(e.Event);
            Output.Write(Tokens.Arrow);
            Output.Write(SpecialWords.Add);
            Output.Write(Tokens.ParenthesisLeft);

            GenerateExpression(e.Listener);

            Output.Write(Tokens.ParenthesisRight);
            Output.WriteLine(Tokens.Semicolon);
        }
开发者ID:jdluzen,项目名称:Phalanger,代码行数:16,代码来源:PhpGenerator.CLR.cs

示例13: GenerateAttachEventStatement

 protected override void GenerateAttachEventStatement(CodeAttachEventStatement e) {
   GenerateExpression(e.Event.TargetObject);
   Output.Write(".add_");
   Output.Write(e.Event.EventName);
   Output.Write("(");
   GenerateExpression(e.Listener);
   Output.WriteLine(");");
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:8,代码来源:jscodegenerator.cs

示例14: AddCLREvent

        private CodeStatement AddCLREvent(Type eventTarget, CodeContext cc, CodeExpression ce, MarkupEventInfo mei)
        {

            bool subClassed = _ccRoot.SubClass.Length > 0;
            CodeStatement csEvent = null;
            // param2: <FooEventHandler>
            CodeExpression cDelExp = GetEventDelegate(cc, mei.mi, mei.eventName, mei.eventHandler);

            if (mei.mi.DeclaringType.IsAssignableFrom(eventTarget))
            {
                // _element.FooEvent += new FooEventHandlerDelegate(OnFoo);
                csEvent = new CodeAttachEventStatement(ce, mei.eventName, cDelExp);
            }
            else if (eventTarget == null || // for known attached events on unknown local tags
                     KnownTypes.Types[(int)KnownElements.UIElement].IsAssignableFrom(eventTarget) ||
                     KnownTypes.Types[(int)KnownElements.ContentElement].IsAssignableFrom(eventTarget))
            {
                // _element.AddHandler(FooEvent, new FooEventHandlerDelegate(OnFoo));
                CodeFieldReferenceExpression cfreEvent = GetEvent(mei.mi, mei.eventName, mei.eventHandler);
                CodeMethodInvokeExpression cmieAddHandler = new CodeMethodInvokeExpression(ce, ADDHANDLER, cfreEvent, cDelExp);
                csEvent = new CodeExpressionStatement(cmieAddHandler);
            }
            else
            {
                string eventTargetName = eventTarget != null ? eventTarget.FullName : cc.LocalElementFullName;
                ThrowCompilerException(SRID.UnknownEventAttribute, mei.eventName, mei.eventHandler, eventTargetName);
            }

            // When x:SubClass is used, event handlers can be specified in a code-behind file, under this sub class.
            // But these handler methods need to be accessible from the intermediary generated sub class. So an empty
            // internal virtual method with the same signature as the handler method is generated in this intermediary
            // sub class (in the generated file):
            //
            //      internal virtual void OnFooEvent(object sender, FooEventArgs ea)
            //      {
            //      }
            //
            // Since a delegate cannot take the address of a virtual function, a non-virtual helper function
            // with the same signature as the above function & which calls the above function is also generated:
            //
            //      private void OnFooEventHelper(object sender, FooEventArgs ea)
            //      {
            //          OnFooEvent(sender, ea);
            //      }
            //
            // All this is done only if x:Subclass is specified, since this means that this sub class would need to be
            // defined in a code-behind file. This also means that inline events (in <x:Code>) will not be supported.

            if (subClassed)
            {
                GenerateProtectedEventHandlerMethod(mei);
            }

            AddLinePragma(csEvent, mei.lineNumber);
            return csEvent;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:56,代码来源:MarkupCompiler.cs

示例15: AddEventHandler

        public override bool AddEventHandler(EventDescription eventDescription, string objectName, string methodName)
        {
            const string Init = "__init__";
            //This is not the most optimal solution for WPF since we will call FindLogicalNode for each event handler,
            //but it simplifies the code generation for now.

            CodeDomDocDataAdapter adapter = GetDocDataAdapterForPyFile();

            //Find the __init__ method
            CodeMemberMethod method = null;
            foreach(CodeTypeMember ctMember in adapter.TypeDeclaration.Members)
            {
                if (ctMember is CodeConstructor)
                {
                    if (ctMember.Name == Init)
                    {
                        method = ctMember as CodeMemberMethod;
                        break;
                    }
                }
            }
            if (method == null)
            {
                method = new CodeConstructor();
                method.Name = Init;
            }

            //Create a code statement which looks like: LogicalTreeHelper.FindLogicalNode(self.Root, "button1").Click += self.button1_Click
            CodeTypeReferenceExpression logicalTreeHelper = new CodeTypeReferenceExpression("LogicalTreeHelper");
            CodeMethodReferenceExpression findLogicalNodeMethod = new CodeMethodReferenceExpression(logicalTreeHelper, "FindLogicalNode");
            CodeFieldReferenceExpression selfWindow = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "Root");
            CodeMethodInvokeExpression findLogicalNodeInvoke = new CodeMethodInvokeExpression( findLogicalNodeMethod, selfWindow, new CodeSnippetExpression("\'" + objectName + "\'"));
            CodeDelegateCreateExpression createDelegateExpression = new CodeDelegateCreateExpression(new CodeTypeReference("System.EventHandler"), new CodeThisReferenceExpression(), methodName);
            CodeAttachEventStatement attachEvent = new CodeAttachEventStatement(findLogicalNodeInvoke, eventDescription.Name, createDelegateExpression);
            method.Statements.Add(attachEvent);
            adapter.Generate();
            return true;
        }
开发者ID:smartmobili,项目名称:parsing,代码行数:38,代码来源:PythonEventBindingProvider.cs


注:本文中的System.CodeDom.CodeAttachEventStatement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。