本文整理汇总了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;
}
示例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;
}
示例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
});
}
}
}