Exemplo n.º 1
0
        public override bool Equals(object other)
        {
            if (other == null)
            {
                return(false);
            }

            DelegateTypeInfo dtiOther = other as DelegateTypeInfo;

            if (dtiOther == null)
            {
                return(false);
            }

            if (ReturnType.BaseType != dtiOther.ReturnType.BaseType || Parameters.Length != dtiOther.Parameters.Length)
            {
                return(false);
            }

            for (int parameter = 0; parameter < Parameters.Length; parameter++)
            {
                CodeParameterDeclarationExpression otherParam = dtiOther.Parameters[parameter];
                if (otherParam.Type.BaseType != Parameters[parameter].Type.BaseType)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public override bool Equals(object other)
        {
            if (other == null)
            {
                return(false);
            }
            DelegateTypeInfo info = other as DelegateTypeInfo;

            if (info == null)
            {
                return(false);
            }
            if ((this.ReturnType.BaseType != info.ReturnType.BaseType) || (this.Parameters.Length != info.Parameters.Length))
            {
                return(false);
            }
            for (int i = 0; i < this.Parameters.Length; i++)
            {
                CodeParameterDeclarationExpression expression = info.Parameters[i];
                if (expression.Type.BaseType != this.Parameters[i].Type.BaseType)
                {
                    return(false);
                }
            }
            return(true);
        }
 internal static string CreateUniqueMethodName(IComponent component, string propName, System.Type delegateType)
 {
     IServiceProvider serviceProvider = component.Site;
     if (serviceProvider == null)
     {
         throw new ArgumentException("component");
     }
     IDesignerHost host = serviceProvider.GetService(typeof(IDesignerHost)) as IDesignerHost;
     if (host == null)
     {
         throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(IDesignerHost).FullName }));
     }
     if (((ITypeProvider) serviceProvider.GetService(typeof(ITypeProvider))) == null)
     {
         throw new InvalidOperationException(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).FullName }));
     }
     string name = null;
     IReferenceService service = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
     if (service != null)
     {
         name = service.GetName(component);
     }
     else
     {
         ISite site = component.Site;
         if (site != null)
         {
             name = site.Name;
         }
     }
     if (name == null)
     {
         name = component.GetType().Name;
     }
     name = (name.Replace('.', '_').Replace('/', '_') + "_" + propName).Replace('(', '_').Replace(')', '_').Replace(" ", "");
     DelegateTypeInfo info = new DelegateTypeInfo(delegateType);
     Activity rootComponent = host.RootComponent as Activity;
     if (rootComponent == null)
     {
         Activity activity2 = component as Activity;
         throw new InvalidOperationException(SR.GetString("Error_CantCreateMethod", new object[] { (activity2 != null) ? activity2.QualifiedName : string.Empty }));
     }
     System.Type dataSourceClass = Helpers.GetDataSourceClass(rootComponent, serviceProvider);
     if (dataSourceClass == null)
     {
         throw new InvalidOperationException(SR.GetString("Error_CantCreateMethod", new object[] { rootComponent.QualifiedName }));
     }
     BindingFlags bindingAttr = BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance;
     MethodInfo[] methods = dataSourceClass.GetMethods(bindingAttr);
     ArrayList list = new ArrayList();
     foreach (MethodInfo info2 in methods)
     {
         if (info2.GetParameters().Length != info.Parameters.Length)
         {
             continue;
         }
         bool flag = true;
         for (int i = 0; i < info.Parameters.Length; i++)
         {
             ParameterInfo info3 = info2.GetParameters()[i];
             CodeParameterDeclarationExpression expression = info.Parameters[i];
             FieldDirection direction = expression.Direction;
             if ((((direction == FieldDirection.In) && !info3.IsIn) || ((direction == FieldDirection.Out) && !info3.IsOut)) || (((direction == FieldDirection.Ref) && (!info3.IsIn || !info3.IsOut)) || !Helpers.TypesEqual(expression.Type, info3.ParameterType)))
             {
                 flag = false;
                 break;
             }
         }
         if (flag)
         {
             list.Add(info2.Name);
         }
     }
     int num2 = 0;
     bool flag2 = true;
     string strB = name;
     MemberInfo[] members = dataSourceClass.GetMembers();
     while (flag2 && (num2 < 0x7fffffff))
     {
         flag2 = false;
         foreach (string str3 in list)
         {
             if (string.Compare(str3, strB, StringComparison.OrdinalIgnoreCase) == 0)
             {
                 flag2 = true;
                 break;
             }
         }
         if (!flag2)
         {
             foreach (MemberInfo info4 in members)
             {
                 if (!(info4 is MethodInfo) && (string.Compare(info4.Name, strB, StringComparison.OrdinalIgnoreCase) == 0))
                 {
                     flag2 = true;
                     break;
                 }
             }
         }
         if (!flag2)
         {
             MethodInfo info5 = host.RootComponent.GetType().GetMethod(strB, bindingAttr, null, info.ParameterTypes, null);
             if ((info5 != null) && !info5.IsPrivate)
             {
                 flag2 = true;
             }
         }
         if (flag2)
         {
             strB = name + "_" + ++num2.ToString(CultureInfo.InvariantCulture);
         }
     }
     return strB;
 }