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


C# EventDeclaration.HasModifier方法代码示例

本文整理汇总了C#中EventDeclaration.HasModifier方法的典型用法代码示例。如果您正苦于以下问题:C# EventDeclaration.HasModifier方法的具体用法?C# EventDeclaration.HasModifier怎么用?C# EventDeclaration.HasModifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EventDeclaration的用法示例。


在下文中一共展示了EventDeclaration.HasModifier方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateEventInvocator

		public static MethodDeclaration CreateEventInvocator (RefactoringContext context, TypeDeclaration declaringType, EventDeclaration eventDeclaration, VariableInitializer initializer, IMethod invokeMethod, bool useExplictType)
		{
			bool hasSenderParam = false;
			IEnumerable<IParameter> pars = invokeMethod.Parameters;
			if (invokeMethod.Parameters.Any()) {
				var first = invokeMethod.Parameters [0];
				if (first.Name == "sender" /*&& first.Type == "System.Object"*/) {
					hasSenderParam = true;
					pars = invokeMethod.Parameters.Skip(1);
				}
			}
			const string handlerName = "handler";

			var arguments = new List<Expression>();
			if (hasSenderParam)
				arguments.Add(eventDeclaration.HasModifier (Modifiers.Static) ? (Expression)new PrimitiveExpression (null) : new ThisReferenceExpression());
			bool useThisMemberReference = false;
			foreach (var par in pars) {
				arguments.Add(new IdentifierExpression(par.Name));
				useThisMemberReference |= par.Name == initializer.Name;
			}
			var proposedHandlerName = GetNameProposal(initializer);
			var modifiers = eventDeclaration.HasModifier(Modifiers.Static) ? Modifiers.Static : Modifiers.Protected | Modifiers.Virtual;
			if (declaringType.HasModifier (Modifiers.Sealed)) {
				modifiers = Modifiers.None;
			}
			var methodDeclaration = new MethodDeclaration {
				Name = proposedHandlerName,
				ReturnType = new PrimitiveType ("void"),
				Modifiers = modifiers,
				Body = new BlockStatement {
					new VariableDeclarationStatement (
						useExplictType ? eventDeclaration.ReturnType.Clone () : new PrimitiveType ("var"), handlerName, 
						useThisMemberReference ? 
						(Expression)new MemberReferenceExpression (new ThisReferenceExpression (), initializer.Name) 
						: new IdentifierExpression (initializer.Name)
						),
					new IfElseStatement {
						Condition = new BinaryOperatorExpression (new IdentifierExpression (handlerName), BinaryOperatorType.InEquality, new PrimitiveExpression (null)),
						TrueStatement = new InvocationExpression (new IdentifierExpression (handlerName), arguments)
					}
				}
			};

			foreach (var par in pars) {
				var typeName = context.CreateShortType(par.Type);
				var decl = new ParameterDeclaration(typeName, par.Name);
				methodDeclaration.Parameters.Add(decl);
			}
			return methodDeclaration;
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:51,代码来源:CreateEventInvocatorAction.cs

示例2: OverloadsCollection

 private OverloadsCollection(IEmitter emitter, EventDeclaration eventDeclaration)
 {
     this.Emitter = emitter;
     this.Name = emitter.GetEventName(eventDeclaration);
     this.JsName = this.Emitter.GetEntityName(eventDeclaration, false, true);
     this.Inherit = !eventDeclaration.HasModifier(Modifiers.Static);
     this.Static = eventDeclaration.HasModifier(Modifiers.Static);
     this.CancelChangeCase = true;
     this.Member = this.FindMember(eventDeclaration);
     this.TypeDefinition = this.Member.DeclaringTypeDefinition;
     this.Type = this.Member.DeclaringType;
     this.InitMembers();
     this.Emitter.OverloadsCache[eventDeclaration.GetHashCode().ToString()] = this;
 }
开发者ID:GavinHwa,项目名称:Bridge,代码行数:14,代码来源:OverloadsCollection.cs

示例3: VisitEventDeclaration

 public override void VisitEventDeclaration(EventDeclaration eventDeclaration)
 {
     bool isStatic = eventDeclaration.HasModifier(Modifiers.Static);
     foreach (var item in eventDeclaration.Variables)
     {
         Expression initializer = item.Initializer;
         this.CurrentType.EventsDeclarations.Add(item.Name, eventDeclaration);
         if (isStatic)
         {
             this.CurrentType.StaticConfig.Events.Add(new TypeConfigItem
             {
                 Name = item.Name,
                 Entity = eventDeclaration,
                 Initializer = initializer,
                 VarInitializer = item
             });
     }
     else
     {
             this.CurrentType.InstanceConfig.Events.Add(new TypeConfigItem
             {
                 Name = item.Name,
                 Entity = eventDeclaration,
                 Initializer = initializer,
                 VarInitializer = item
             });
         }
     }
 }
开发者ID:Oaz,项目名称:bridgedotnet_Builder,代码行数:29,代码来源:Inspector.Visitor.cs


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