本文整理汇总了C#中Mono.Cecil.EventDefinition类的典型用法代码示例。如果您正苦于以下问题:C# EventDefinition类的具体用法?C# EventDefinition怎么用?C# EventDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventDefinition类属于Mono.Cecil命名空间,在下文中一共展示了EventDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzedEventOverridesTreeNode
public AnalyzedEventOverridesTreeNode(EventDefinition analyzedEvent)
{
if (analyzedEvent == null)
throw new ArgumentNullException("analyzedEvent");
this.analyzedEvent = analyzedEvent;
}
示例2: CheckSupport
private void CheckSupport(EventDefinition eventInfo, MethodAttributes methodAttributes)
{
EventAttributes eventAttributes = eventInfo.Attributes;
string warningTemplate = "Event '" + name + "' has unsupported attribute: '{0}'.";
// in order to reduce output we warn only about important attributes which are not currently
// supported:
// EventDefinition properties
// EventAttributes
//if ((eventAttributes & EventAttributes.RTSpecialName) != 0) { Logger.Warning(warningTemplate, "RTSpecialName"); }
//if ((eventAttributes & EventAttributes.SpecialName) != 0) { Logger.Warning(warningTemplate, "SpecialName"); }
// MethodAttributes
//if ((methodAttributes & MethodAttributes.CheckAccessOnOverride) != 0) { Logger.Warning(warningTemplate, "CheckAccessOnOverride"); }
//if ((methodAttributes & MethodAttributes.FamANDAssem) != 0) { Logger.Warning(warningTemplate, "FamANDAssem"); }
// TODO: support this: if ((methodAttributes & MethodAttributes.HasSecurity) != 0) { Logger.Warning(warningTemplate, "HasSecurity"); }
//if ((methodAttributes & MethodAttributes.HideBySig) != 0) { Logger.Warning(warningTemplate, "HideBySig"); }
//if ((methodAttributes & MethodAttributes.NewSlot) != 0) { Logger.Warning(warningTemplate, "NewSlot"); }
// TODO: support this: if ((methodAttributes & MethodAttributes.PinvokeImpl) != 0) { Logger.Warning(warningTemplate, "PinvokeImpl"); }
//if ((methodAttributes & MethodAttributes.PrivateScope) != 0) { Logger.Warning(warningTemplate, "PrivateScope"); }
// TODO: support this: if ((methodAttributes & MethodAttributes.RequireSecObject) != 0) { Logger.Warning(warningTemplate, "RequiresSecObject"); }
//if ((methodAttributes & MethodAttributes.ReuseSlot) != 0) { Logger.Warning(warningTemplate, "ReuseSlot"); }
//if ((methodAttributes & MethodAttributes.RTSpecialName) != 0) { Logger.Warning(warningTemplate, "RTSpecialName"); }
//if ((methodAttributes & MethodAttributes.SpecialName) != 0) { Logger.Warning(warningTemplate, "SpecialName"); }
// TODO: support this: if ((methodAttributes & MethodAttributes.UnmanagedExport) != 0) { Logger.Warning(warningTemplate, "UnmanagedExport"); }
}
示例3: ProcessEvent
public void ProcessEvent(EventDefinition eventt)
{
_logger.LogDebug("Beginning processing event " + eventt.Name);
FieldReference eventDelegate = eventt.GetEventDelegate();
if (eventDelegate != null)
{
if (eventDelegate.FieldType.IsValidEventDelegate())
{
WeakEventWeaver weakEventWeaver = new WeakEventWeaver(eventDelegate, _moduleImporter);
ProcessAddMethod(eventt.AddMethod, weakEventWeaver);
ProcessRemoveMethod(eventt.RemoveMethod, weakEventWeaver);
}
else
{
_logger.LogInfo("Skipping event " + eventt + ", incompatible event delegate type");
}
}
else
{
_logger.LogInfo("Skipping event " + eventt + ", could not determine the event delegate field");
}
_logger.LogDebug("Finished processing event " + eventt.Name);
}
示例4: EventKey
public EventKey (TypeKey typeKey, string type, string name, EventDefinition eventDefinition)
{
this.typeKey = typeKey;
this.type = type;
this.name = name;
this.eventDefinition = eventDefinition;
}
示例5: CreateSourceEventMethodFor
private static MethodDefinition CreateSourceEventMethodFor(EventDefinition eventDefinition)
{
var eventField = eventDefinition.DeclaringType.Fields.Single(x => x.FullName == eventDefinition.FullName);
var domainEventType = ((GenericInstanceType) eventField.FieldType).GenericArguments[0];
var invokeMethod = eventField.FieldType.Resolve().Methods.Single(x => x.Name == "Invoke").MakeGenericMethod(domainEventType);
var eventDelegate = eventDefinition.DeclaringType.Module.ImportReference(invokeMethod);
var noReturnValue = eventDefinition.DeclaringType.Module.TypeSystem.Void;
var eventSourcingMethod = new MethodDefinition("<Ichnaea>SourceEvent", SourceEventMethodAttributes, noReturnValue);
eventSourcingMethod.Parameters.Add(new ParameterDefinition("domainEvent", ParameterAttributes.None, domainEventType));
eventSourcingMethod.Body.Variables.Add(new VariableDefinition("eventSource", eventField.FieldType));
eventSourcingMethod.Body.MaxStackSize = 3;
eventSourcingMethod.Body.InitLocals = true;
var il = eventSourcingMethod.Body.GetILProcessor();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, eventField);
il.Emit(OpCodes.Stloc_0);
il.Emit(OpCodes.Ldloc_0);
var nullCheckPlaceholder = il.Create(OpCodes.Nop);
il.Append(nullCheckPlaceholder);
il.Emit(OpCodes.Ret);
var startOfCallSequence = il.Create(OpCodes.Ldloc_0);
il.Append(startOfCallSequence);
il.Replace(nullCheckPlaceholder, il.Create(OpCodes.Brtrue_S, startOfCallSequence));
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Callvirt, eventDelegate);
il.Emit(OpCodes.Ret);
return eventSourcingMethod;
}
示例6: GetEventArgsTypeForEvent
private static string GetEventArgsTypeForEvent(EventDefinition ei)
{
// Find the EventArgs type parameter of the event via digging around via reflection
var type = ei.EventType.Resolve();
var invoke = type.Methods.First(x => x.Name == "Invoke");
if (invoke.Parameters.Count < 2) return null;
var param = invoke.Parameters[1];
var ret = RenameBogusWinRTTypes(param.ParameterType.FullName);
var generic = ei.EventType as GenericInstanceType;
if (generic != null)
{
foreach (
var kvp in
type.GenericParameters.Zip(generic.GenericArguments, (name, actual) => new {name, actual}))
{
var realType = GetRealTypeName(kvp.actual);
ret = ret.Replace(kvp.name.FullName, realType);
}
}
// NB: Inner types in Mono.Cecil get reported as 'Foo/Bar'
return ret.Replace('/', '.');
}
示例7: Write
protected override void Write(EventDefinition @event)
{
WriteEventDeclaration(@event);
int startIndex = formatter.CurrentPosition;
WriteStartBlock();
WriteAttributes(@event.CustomAttributes);
WriteNestedMethod(".addon", @event.AddMethod);
WriteLine();
WriteNestedMethod(".removeon", @event.RemoveMethod);
WriteNestedMethod(".fire", @event.InvokeMethod);
foreach (var method in @event.OtherMethods)
{
WriteNestedMethod(".other", method);
}
WriteEndBlock();
this.currentWritingInfo.MemberDefinitionToFoldingPositionMap[@event] = new OffsetSpan(startIndex, formatter.CurrentPosition - 1);
}
示例8: UnattachedEvent
public void UnattachedEvent ()
{
var int32 = typeof (int).ToDefinition ();
var evt = new EventDefinition ("Event", EventAttributes.None, int32);
Assert.AreEqual (null, evt.AddMethod);
}
示例9: Add
public void Add(EventDefinition value)
{
if (!Contains (value))
Attach (value);
List.Add (value);
}
示例10: ProcessEvent
public override void ProcessEvent (EventDefinition @event)
{
foreach (var attribute in GetPreserveAttributes (@event)) {
MarkMethod (@event.AddMethod, attribute);
MarkMethod (@event.InvokeMethod, attribute);
MarkMethod (@event.RemoveMethod, attribute);
}
}
示例11: AnalyzedEventTreeNode
public AnalyzedEventTreeNode(EventDefinition analyzedEvent, string prefix = "")
{
if (analyzedEvent == null)
throw new ArgumentNullException("analyzedEvent");
this.analyzedEvent = analyzedEvent;
this.prefix = prefix;
this.LazyLoading = true;
}
示例12: CopyEvent
/// <summary>
/// Creates an event like the specified event, but doesn't add it anywhere.
/// </summary>
/// <param name="yourEvent"></param>
/// <param name="newName"></param>
/// <returns></returns>
private EventDefinition CopyEvent(EventDefinition yourEvent, string newName)
{
var targetEventType = FixTypeReference(yourEvent.EventType);
var targetEvent = new EventDefinition(newName,
yourEvent.Attributes,
targetEventType);
return targetEvent;
}
示例13: AnalyzedInterfaceEventImplementedByTreeNode
public AnalyzedInterfaceEventImplementedByTreeNode(EventDefinition analyzedEvent)
{
if (analyzedEvent == null)
throw new ArgumentNullException("analyzedEvent");
this.analyzedEvent = analyzedEvent;
this.analyzedMethod = this.analyzedEvent.AddMethod ?? this.analyzedEvent.RemoveMethod;
}
示例14: GetIcon
public static ImageSource GetIcon(EventDefinition eventDef)
{
MethodDefinition accessor = eventDef.AddMethod ?? eventDef.RemoveMethod;
if (accessor != null)
return Images.GetIcon(MemberIcon.Event, GetOverlayIcon(eventDef.AddMethod.Attributes), eventDef.AddMethod.IsStatic);
else
return Images.GetIcon(MemberIcon.Event, AccessOverlayIcon.Public, false);
}
示例15: Create
public static string Create(EventDefinition evt)
{
var method = evt.InvokeMethod ?? evt.AddMethod ?? evt.RemoveMethod;
if (method.IsPublic) return "event";
if (method.IsAssembly) return "event internal";
if (method.IsFamily) return "event protected";
if (method.IsFamilyOrAssembly) return "event protected_internal";
return "event private";
}