本文整理汇总了C#中EventDeclaration.AddAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# EventDeclaration.AddAnnotation方法的具体用法?C# EventDeclaration.AddAnnotation怎么用?C# EventDeclaration.AddAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventDeclaration
的用法示例。
在下文中一共展示了EventDeclaration.AddAnnotation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateEvent
AttributedNode CreateEvent(EventDefinition eventDef)
{
if (eventDef.AddMethod != null && eventDef.AddMethod.IsAbstract) {
// An abstract event cannot be custom
EventDeclaration astEvent = new EventDeclaration();
ConvertCustomAttributes(astEvent, eventDef);
astEvent.AddAnnotation(eventDef);
astEvent.Variables.Add(new VariableInitializer(CleanName(eventDef.Name)));
astEvent.ReturnType = ConvertType(eventDef.EventType, eventDef);
if (!eventDef.DeclaringType.IsInterface)
astEvent.Modifiers = ConvertModifiers(eventDef.AddMethod);
return astEvent;
} else {
CustomEventDeclaration astEvent = new CustomEventDeclaration();
ConvertCustomAttributes(astEvent, eventDef);
astEvent.AddAnnotation(eventDef);
astEvent.Name = CleanName(eventDef.Name);
astEvent.ReturnType = ConvertType(eventDef.EventType, eventDef);
if (eventDef.AddMethod == null || !eventDef.AddMethod.HasOverrides)
astEvent.Modifiers = ConvertModifiers(eventDef.AddMethod);
else
astEvent.PrivateImplementationType = ConvertType(eventDef.AddMethod.Overrides.First().DeclaringType);
if (eventDef.AddMethod != null) {
// Create mapping - used in debugger
MemberMapping methodMapping = eventDef.AddMethod.CreateCodeMapping(this.CodeMappings);
astEvent.AddAccessor = new Accessor {
Body = CreateMethodBody(eventDef.AddMethod)
}.WithAnnotation(eventDef.AddMethod);
ConvertAttributes(astEvent.AddAccessor, eventDef.AddMethod);
astEvent.AddAccessor.WithAnnotation(methodMapping);
}
if (eventDef.RemoveMethod != null) {
// Create mapping - used in debugger
MemberMapping methodMapping = eventDef.RemoveMethod.CreateCodeMapping(this.CodeMappings);
astEvent.RemoveAccessor = new Accessor {
Body = CreateMethodBody(eventDef.RemoveMethod)
}.WithAnnotation(eventDef.RemoveMethod);
ConvertAttributes(astEvent.RemoveAccessor, eventDef.RemoveMethod);
astEvent.RemoveAccessor.WithAnnotation(methodMapping);
}
MethodDefinition accessor = eventDef.AddMethod ?? eventDef.RemoveMethod;
if (accessor.IsVirtual ^ !accessor.IsNewSlot) {
if (TypesHierarchyHelpers.FindBaseMethods(accessor).Any())
astEvent.Modifiers |= Modifiers.New;
}
return astEvent;
}
}
示例2: ConvertEvent
EntityDeclaration ConvertEvent(IEvent ev)
{
if (this.UseCustomEvents) {
CustomEventDeclaration decl = new CustomEventDeclaration();
decl.Modifiers = GetMemberModifiers(ev);
if (ShowAttributes) {
decl.Attributes.AddRange (ev.Attributes.Select ((a) => new AttributeSection (ConvertAttribute (a))));
}
if (AddResolveResultAnnotations) {
decl.AddAnnotation(new MemberResolveResult(null, ev));
}
decl.ReturnType = ConvertType(ev.ReturnType);
decl.Name = ev.Name;
decl.AddAccessor = ConvertAccessor(ev.AddAccessor, ev.Accessibility, true);
decl.RemoveAccessor = ConvertAccessor(ev.RemoveAccessor, ev.Accessibility, true);
return decl;
} else {
EventDeclaration decl = new EventDeclaration();
decl.Modifiers = GetMemberModifiers(ev);
if (ShowAttributes) {
decl.Attributes.AddRange (ev.Attributes.Select ((a) => new AttributeSection (ConvertAttribute (a))));
}
if (AddResolveResultAnnotations) {
decl.AddAnnotation(new MemberResolveResult(null, ev));
}
decl.ReturnType = ConvertType(ev.ReturnType);
decl.Variables.Add(new VariableInitializer(ev.Name));
return decl;
}
}
示例3: CreateEvent
AttributedNode CreateEvent(EventDefinition eventDef)
{
if (eventDef.AddMethod != null && eventDef.AddMethod.IsAbstract) {
// An abstract event cannot be custom
EventDeclaration astEvent = new EventDeclaration();
ConvertCustomAttributes(astEvent, eventDef);
astEvent.AddAnnotation(eventDef);
astEvent.Variables.Add(new VariableInitializer(CleanName(eventDef.Name)));
astEvent.ReturnType = ConvertType(eventDef.EventType, eventDef);
if (!eventDef.DeclaringType.IsInterface)
astEvent.Modifiers = ConvertModifiers(eventDef.AddMethod);
return astEvent;
} else {
CustomEventDeclaration astEvent = new CustomEventDeclaration();
ConvertCustomAttributes(astEvent, eventDef);
astEvent.AddAnnotation(eventDef);
astEvent.Name = CleanName(eventDef.Name);
astEvent.ReturnType = ConvertType(eventDef.EventType, eventDef);
if (eventDef.AddMethod == null || !eventDef.AddMethod.HasOverrides)
astEvent.Modifiers = ConvertModifiers(eventDef.AddMethod);
else
astEvent.PrivateImplementationType = ConvertType(eventDef.AddMethod.Overrides.First().DeclaringType);
if (eventDef.AddMethod != null) {
astEvent.AddAccessor = new Accessor {
Body = AstMethodBodyBuilder.CreateMethodBody(eventDef.AddMethod, context)
}.WithAnnotation(eventDef.AddMethod);
ConvertAttributes(astEvent.AddAccessor, eventDef.AddMethod);
}
if (eventDef.RemoveMethod != null) {
astEvent.RemoveAccessor = new Accessor {
Body = AstMethodBodyBuilder.CreateMethodBody(eventDef.RemoveMethod, context)
}.WithAnnotation(eventDef.RemoveMethod);
ConvertAttributes(astEvent.RemoveAccessor, eventDef.RemoveMethod);
}
return astEvent;
}
}