Example #1
0
        void SetNON2008R2ObjectExplorerEventProvider(System.Type t)
        {
            // the old way of doing things
            //IObjectExplorerEventProvider objectExplorer = (IObjectExplorerEventProvider)Common.ObjectExplorerService.GetService(typeof(IObjectExplorerEventProvider));
            //objectExplorer.SelectionChanged += new NodesChangedEventHandler(objectExplorer_SelectionChanged);

            MethodInfo mi = this.GetType().GetMethod("Provider_SelectionChanged", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            // get the IObjectExplorerEventProvider from the ObjectExplorerService
            object objectExplorer = Connect.ObjectExplorer.GetService(t);
            EventInfo ei = t.GetEvent("SelectionChanged", System.Reflection.BindingFlags.Public | BindingFlags.Instance);
            // use this overload CreateDelegate(Type type, object firstArgument, MethodInfo method);
            // the 2nd param is "this" because the method to handle the event is in it.
            Delegate del = Delegate.CreateDelegate(ei.EventHandlerType, this, mi);
            ei.AddEventHandler(objectExplorer, del);
        }
 private static void AddNewProperties(List<CustomProperty> propCollection, System.Type customActivityType, IServiceProvider serviceProvider, List<CustomProperty> existingProps)
 {
     IMemberCreationService service = serviceProvider.GetService(typeof(IMemberCreationService)) as IMemberCreationService;
     if (service == null)
     {
         throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(IMemberCreationService).FullName }));
     }
     ITypeProvider provider = serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider;
     if (provider == null)
     {
         throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
     }
     foreach (CustomProperty property in propCollection)
     {
         bool flag = (property.oldPropertyName == null) || (property.oldPropertyType == null);
         if (!flag)
         {
             if (!property.IsEvent)
             {
                 flag = customActivityType.GetProperty(property.oldPropertyName, provider.GetType(property.oldPropertyType)) == null;
             }
             else
             {
                 flag = customActivityType.GetEvent(property.oldPropertyName) == null;
             }
         }
         if (flag)
         {
             AttributeInfo[] attributes = CreateCustomPropertyAttributeArray(property, serviceProvider);
             if (property.IsEvent)
             {
                 service.CreateEvent(customActivityType.FullName, property.Name, provider.GetType(property.Type), attributes, property.GenerateDependencyProperty);
             }
             else
             {
                 service.CreateProperty(customActivityType.FullName, property.Name, provider.GetType(property.Type), attributes, property.GenerateDependencyProperty, false, false, null, false);
             }
         }
         else
         {
             CustomProperty oldProperty = null;
             foreach (CustomProperty property3 in existingProps)
             {
                 if ((property3.Name == property.oldPropertyName) && (property3.Type == property.oldPropertyType))
                 {
                     oldProperty = property3;
                 }
             }
             if ((oldProperty == null) || ArePropertiesDifferent(property, oldProperty))
             {
                 AttributeInfo[] infoArray2 = CreateCustomPropertyAttributeArray(property, serviceProvider);
                 CreateCustomPropertyAttributeArray(oldProperty, serviceProvider);
                 System.Type newEventType = provider.GetType(property.Type, false);
                 System.Type type = provider.GetType(property.oldPropertyType, false);
                 if (newEventType != null)
                 {
                     if (property.IsEvent)
                     {
                         service.UpdateEvent(customActivityType.FullName, property.oldPropertyName, type, property.Name, newEventType, infoArray2, property.GenerateDependencyProperty, false);
                     }
                     else
                     {
                         service.UpdateProperty(customActivityType.FullName, property.oldPropertyName, type, property.Name, newEventType, infoArray2, property.GenerateDependencyProperty, false);
                     }
                 }
             }
         }
     }
 }