コード例 #1
0
		public AnalyzedEventOverridesTreeNode(EventDefinition analyzedEvent)
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");

			this.analyzedEvent = analyzedEvent;
		}
コード例 #2
0
ファイル: EventKey.cs プロジェクト: alexzhaosheng/obfuscar
		public EventKey (TypeKey typeKey, string type, string name, EventDefinition eventDefinition)
		{
			this.typeKey = typeKey;
			this.type = type;
			this.name = name;
			this.eventDefinition = eventDefinition;
		}
コード例 #3
0
ファイル: MyEventInfo.cs プロジェクト: PrintFleet/ImmDoc.NET
    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"); }
    }
コード例 #4
0
        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('/', '.');
        }
コード例 #5
0
        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);
        }
        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);
        }
コード例 #7
0
        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;
        }
コード例 #8
0
ファイル: EventTests.cs プロジェクト: hhariri/cecil
		public void UnattachedEvent ()
		{
			var int32 = typeof (int).ToDefinition ();
			var evt = new EventDefinition ("Event", EventAttributes.None, int32);

			Assert.AreEqual (null, evt.AddMethod);
		}
コード例 #9
0
        public void Add(EventDefinition value)
        {
            if (!Contains (value))
                Attach (value);

            List.Add (value);
        }
コード例 #10
0
		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
0
		public AnalyzedInterfaceEventImplementedByTreeNode(EventDefinition analyzedEvent)
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");

			this.analyzedEvent = analyzedEvent;
			this.analyzedMethod = this.analyzedEvent.AddMethod ?? this.analyzedEvent.RemoveMethod;
		}
コード例 #12
0
		public AnalyzedEventTreeNode(EventDefinition analyzedEvent, string prefix = "")
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");
			this.analyzedEvent = analyzedEvent;
			this.prefix = prefix;
			this.LazyLoading = true;
		}
コード例 #13
0
ファイル: CreateNew.cs プロジェクト: GregRos/Patchwork
 /// <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;
 }
コード例 #14
0
ファイル: EventTreeNode.cs プロジェクト: x-strong/ILSpy
		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
0
        public EventSourcingMethod(EventDefinition eventDefinition)
        {
            if (eventDefinition == null)
                throw new ArgumentNullException(nameof(eventDefinition));

            this.eventSourcingMethod = CreateSourceEventMethodFor(eventDefinition);
            this.eventDefinition = eventDefinition;
            this.domainEventType = ((GenericInstanceType) eventDefinition.EventType).GenericArguments[0].Resolve();
        }
コード例 #16
0
ファイル: Icon.cs プロジェクト: Xtremrules/dot42
 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";
 }
コード例 #17
0
		public AnalyzedEventOverridesTreeNode(EventDefinition analyzedEvent)
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");

			this.analyzedEvent = analyzedEvent;
			this.threading = new ThreadingSupport();
			this.LazyLoading = true;
		}
コード例 #18
0
ファイル: TypeWeaver.cs プロジェクト: chartly/flood
 public EventDefinition AddDefinition(EventDefinition def, string name = "")
 {
     CheckOriginMember(def);
     var ret = copier.Copy(def);
     DestinationType.Events.Add(ret);
     if(name != "")
         ret.Name = name;
     return ret;
 }
コード例 #19
0
		public override void ProcessEvent (EventDefinition @event)
		{
			var attribute = GetPreserveAttribute (@event);
			if (attribute == null)
				return;

			MarkMethod (@event.AddMethod, attribute);
			MarkMethod (@event.InvokeMethod, attribute);
			MarkMethod (@event.RemoveMethod, attribute);
		}
コード例 #20
0
		public AnalyzedEventFiredByTreeNode(EventDefinition analyzedEvent)
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");

			this.analyzedEvent = analyzedEvent;

			this.eventBackingField = GetBackingField(analyzedEvent);
			this.eventFiringMethod = analyzedEvent.EventType.Resolve().Methods.First(md => md.Name == "Invoke");
		}
		public AnalyzedInterfaceEventImplementedByTreeNode(EventDefinition analyzedEvent)
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");

			this.analyzedEvent = analyzedEvent;
			this.analyzedMethod = this.analyzedEvent.AddMethod ?? this.analyzedEvent.RemoveMethod;
			this.threading = new ThreadingSupport();
			this.LazyLoading = true;
		}
コード例 #22
0
		public  DomCecilEvent (EventDefinition eventDefinition)
		{
			this.eventDefinition     = eventDefinition;
			base.name                = eventDefinition.Name;
			base.Modifiers           = DomCecilType.GetModifiers (eventDefinition.AddMethod);
			base.ReturnType          = DomCecilMethod.GetReturnType (eventDefinition.EventType);
			DomCecilMethod.AddAttributes (this, eventDefinition.CustomAttributes);
			if (!eventDefinition.IsSpecialName)
				base.Modifiers &= ~MonoDevelop.Projects.Dom.Modifiers.SpecialName;
		}
コード例 #23
0
ファイル: MonoMember.cs プロジェクト: tralivali1234/debugger
 private MonoEventInfo(IMonoStructType klass, int index, Cecil.EventDefinition einfo,
                       TargetType type, bool is_static,
                       TargetMemberAccessibility accessibility, MonoFunctionType add,
                       MonoFunctionType remove, MonoFunctionType raise)
     : base(type, einfo.Name, index, is_static, accessibility, add, remove, raise)
 {
     this.Klass      = klass;
     this.AddType    = add;
     this.RemoveType = remove;
     this.RaiseType  = raise;
 }
コード例 #24
0
		public AnalyzedEventAccessorsTreeNode(EventDefinition analyzedEvent)
		{
			if (analyzedEvent == null)
				throw new ArgumentNullException("analyzedEvent");
			this.analyzedEvent = analyzedEvent;

			if (analyzedEvent.AddMethod != null)
				this.Children.Add(new AnalyzedEventAccessorTreeNode(analyzedEvent.AddMethod, "add"));
			if (analyzedEvent.RemoveMethod != null)
				this.Children.Add(new AnalyzedEventAccessorTreeNode(analyzedEvent.RemoveMethod, "remove"));
			foreach (var accessor in analyzedEvent.OtherMethods)
				this.Children.Add(new AnalyzedEventAccessorTreeNode(accessor, null));
		}
コード例 #25
0
ファイル: matchers.cs プロジェクト: cessationoftime/nroles
        public static bool IsMatch(EventDefinition event1, EventDefinition event2)
        {
            if (event1.Name != event2.Name) {
            return false;
              }

              if (!TypeMatcher.IsMatch(event1.EventType, event2.EventType)) {
            return false;
              }

              // TODO: event accessors comparison??

              return true;
        }
コード例 #26
0
 private void ImplementEventAccessorMethods(EventDefinition implementedEvent, MemberComposer propertyAccessorComposer)
 {
     if (RoleEvent.AddMethod != null) {
     var addMethodRoleGroup = Container.ResolveGroup(Role, RoleEvent.AddMethod);
     implementedEvent.AddMethod = (MethodDefinition)propertyAccessorComposer.Compose(addMethodRoleGroup, _accessSpecifier);
       }
       if (RoleEvent.RemoveMethod != null) {
     var removeMethodRoleGroup = Container.ResolveGroup(Role, RoleEvent.RemoveMethod);
     implementedEvent.RemoveMethod = (MethodDefinition)propertyAccessorComposer.Compose(removeMethodRoleGroup, _accessSpecifier);
       }
       if (RoleEvent.InvokeMethod != null) {
     var invokeMethodRoleGroup = Container.ResolveGroup(Role, RoleEvent.InvokeMethod);
     implementedEvent.RemoveMethod = (MethodDefinition)propertyAccessorComposer.Compose(invokeMethodRoleGroup, _accessSpecifier);
       }
 }
コード例 #27
0
ファイル: NotifierWeaver.cs プロジェクト: tritao/flood
        static NotifierWeaver()
        {
            var type = typeof(Template);
            var assemblyPath = type.Assembly.Location;
            var assembly = AssemblyDefinition.ReadAssembly(assemblyPath);
            var module = assembly.MainModule;
            originType = module.Import(type).Resolve();

            tNotifierEvent  = originType.Events.Single(e => e.Name == "PropertyChanged");
            tNotifierMethod = originType.Methods.Single(e => e.Name == "EventInvoke");
            tNotifierField  = originType.Fields.Single(e => e.Name == "handlers");

            tPropertyProperty = originType.Properties.Single(e => e.Name == "Property");
            tPropertyField    = originType.Fields.Single(e => e.Name == "pValue");
            tPropertyNameC    = originType.Fields.Single(e => e.Name == "pNameC");
        }
コード例 #28
0
        public EventTreeNode(EventDefinition ev)
        {
            if (ev == null)
                throw new ArgumentNullException("ev");
            this.ev = ev;

            if (ev.AddMethod != null)
                this.Children.Add(new MethodTreeNode(ev.AddMethod));
            if (ev.RemoveMethod != null)
                this.Children.Add(new MethodTreeNode(ev.RemoveMethod));
            if (ev.InvokeMethod != null)
                this.Children.Add(new MethodTreeNode(ev.InvokeMethod));
            if (ev.HasOtherMethods) {
                foreach (var m in ev.OtherMethods)
                    this.Children.Add(new MethodTreeNode(m));
            }
        }
コード例 #29
0
        protected override void ProcessEvent(EventDefinition eventDef)
        {
            if (eventDef.AddMethod != null && eventDef.AddMethod.Module == null) {
                eventDef.AddMethod = null;
            }
            if (eventDef.RemoveMethod != null && eventDef.RemoveMethod.Module == null) {
                eventDef.RemoveMethod = null;
            }
            eventDef.OtherMethods.RemoveWhere(methodDef => methodDef.Module == null);

            if (eventDef.AddMethod == null && eventDef.RemoveMethod == null && !eventDef.OtherMethods.Any()) {
                Trace.WriteLine(string.Format("Removing event {0}.", eventDef), "RemovePrivateMembers");
                eventDef.DeclaringType.Events.Remove(eventDef);
            }

            base.ProcessEvent(eventDef);
        }
コード例 #30
0
        void get_events()
        {
            lock (this) {
                if (events != null)
                {
                    return;
                }

                events = new MonoEventInfo [TypeDef.Events.Count];

                for (int i = 0; i < events.Length; i++)
                {
                    Cecil.EventDefinition ev = TypeDef.Events [i];
                    events [i] = MonoEventInfo.Create(this, i, ev);
                }
            }
        }
コード例 #31
0
ファイル: MonoMember.cs プロジェクト: tralivali1234/debugger
        internal static MonoEventInfo Create(IMonoStructType klass, int index,
                                             Cecil.EventDefinition einfo)
        {
            TargetType type = klass.File.MonoLanguage.LookupMonoType(einfo.EventType);

            bool             is_static = false;
            MonoFunctionType add, remove, raise;

            TargetMemberAccessibility accessibility = TargetMemberAccessibility.Private;

            if (einfo.AddMethod != null)
            {
                add           = klass.LookupFunction(einfo.AddMethod);
                is_static     = einfo.AddMethod.IsStatic;
                accessibility = MonoMethodInfo.GetAccessibility(einfo.AddMethod);
            }
            else
            {
                add = null;
            }

            if (einfo.RemoveMethod != null)
            {
                remove        = klass.LookupFunction(einfo.RemoveMethod);
                is_static     = einfo.RemoveMethod.IsStatic;
                accessibility = MonoMethodInfo.GetAccessibility(einfo.RemoveMethod);
            }
            else
            {
                remove = null;
            }

            if (einfo.InvokeMethod != null)
            {
                raise         = klass.LookupFunction(einfo.InvokeMethod);
                is_static     = einfo.InvokeMethod.IsStatic;
                accessibility = MonoMethodInfo.GetAccessibility(einfo.InvokeMethod);
            }
            else
            {
                raise = null;
            }

            return(new MonoEventInfo(
                       klass, index, einfo, type, is_static, accessibility, add, remove, raise));
        }
コード例 #32
0
ファイル: EventSignatureRule.cs プロジェクト: dbremner/smokey
		public void VisitEvent(EventDefinition evt)
		{							
			if (evt.AddMethod.ExternallyVisible(Cache))
			{
				Log.DebugLine(this, "-----------------------------------"); 
				Log.DebugLine(this, "event: {0}", evt.Name);	
				Log.DebugLine(this, "type: {0}", evt.EventType);	
				
				TypeDefinition type = evt.EventType as TypeDefinition;
				if (type != null)
				{
					MethodDefinition[] methods = type.Methods.GetMethod("Invoke");
					if (methods.Length == 1)
					{
						MethodDefinition method = methods[0];
						
						string details = string.Empty;
						if (method.ReturnType.ReturnType.ToString() != "System.Void")
							details += "Return type should be void. ";
							
						if (method.Parameters.Count == 2)
						{
							ParameterDefinition arg1 = method.Parameters[0];
							if (arg1.Name != "sender")
								details += "First argument should be named 'sender'. ";
							if (arg1.ParameterType.FullName != "System.Object")
								details += "First argument should be a System.Object. ";

							ParameterDefinition arg2 = method.Parameters[1];
							if (arg2.Name != "e")
								details += "Second argument should be named 'e'. ";
							if (!arg2.ParameterType.IsSameOrSubclassOf("System.EventArgs", Cache))
								details += "Second argument should be a System.EventArgs or a subclass. ";
						}
						else
							details += "The event should have two arguments. ";
							
						if (details.Length > 0)
						{
							Log.DebugLine(this, details);
							Reporter.TypeFailed(type, CheckID, details);
						}
					}
				}
			}
		}
コード例 #33
0
ファイル: ILLanguage.cs プロジェクト: Gobiner/ILSpy
		public override void DecompileEvent(EventDefinition ev, ITextOutput output, DecompilationOptions options)
		{
			ReflectionDisassembler rd = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken);
			rd.DisassembleEvent(ev);
			if (ev.AddMethod != null) {
				output.WriteLine();
				rd.DisassembleMethod(ev.AddMethod);
			}
			if (ev.RemoveMethod != null) {
				output.WriteLine();
				rd.DisassembleMethod(ev.RemoveMethod);
			}
			foreach (var m in ev.OtherMethods) {
				output.WriteLine();
				rd.DisassembleMethod(m);
			}
		}
コード例 #34
0
        public void Insert(int index, EventDefinition value)
        {
            Attach(value);

            List.Insert(index, value);
        }
コード例 #35
0
 public int IndexOf(EventDefinition value)
 {
     return(m_items.IndexOf(value));
 }
コード例 #36
0
 public bool Contains(EventDefinition value)
 {
     return(m_items.Contains(value));
 }
コード例 #37
0
        public void Add(EventDefinition value)
        {
            Attach(value);

            List.Add(value);
        }
コード例 #38
0
 public virtual void VisitEventDefinition(EventDefinition evt)
 {
 }
コード例 #39
0
 public bool Contains(EventDefinition value)
 {
     return(List.Contains(value));
 }
コード例 #40
0
        public new void RemoveAt(int index)
        {
            EventDefinition item = this [index];

            Remove(item);
        }
コード例 #41
0
 public int IndexOf(EventDefinition value)
 {
     return(List.IndexOf(value));
 }
コード例 #42
0
        public void Remove(EventDefinition value)
        {
            List.Remove(value);

            Detach(value);
        }
 public EventDefinitionEventArgs(EventDefinition item)
 {
     m_item = item;
 }