Exemplo n.º 1
0
        protected DataService()
        {
            Type type = this.GetType();
            AttributeCollection  attrs = TypeDescriptor.GetAttributes(type);
            DataAdapterAttribute attr  = (DataAdapterAttribute)attrs[typeof(DataAdapterAttribute)];

            if (attr != null)
            {
                _adapter = Activator.CreateInstance(attr.DataAdapterType);
            }
            _fillMethods = _fillMethodCache[type] as Hashtable;
            if (_fillMethods == null)
            {
                if (attr != null)
                {
                    string[] methodNames = attr.GetDataMethodNames;
                    _fillMethods = Hashtable.Synchronized(new Hashtable(methodNames.Length));
                    foreach (string methodName in methodNames)
                    {
                        MethodInfo method = attr.DataAdapterType.GetMethod(methodName, PublicIgnoreCaseBindingFlags);
                        _fillMethods[methodName] = method;
                        if (_defaultFillMethod == null)
                        {
                            _defaultFillMethod = method;
                        }
                    }
                    if (!String.IsNullOrEmpty(attr.UpdateMethodName))
                    {
                        MemberFilter filter        = new MemberFilter(FilterMethodWithDataTableParameter);
                        MemberInfo[] updateMethods = attr.DataAdapterType.FindMembers(
                            MemberTypes.Method,
                            PublicIgnoreCaseBindingFlags,
                            filter,
                            attr.UpdateMethodName);
                        if (updateMethods.Length != 0)
                        {
                            _updateMethod = (MethodInfo)updateMethods[0];
                        }
                    }
                }
                else
                {
                    _fillMethods = Hashtable.Synchronized(new Hashtable());
                }
                _updateMethodCache[type]      = _updateMethod;
                _defaultFillMethodCache[type] = _defaultFillMethod;
                _fillMethodCache[type]        = _fillMethods;
            }
            else
            {
                _updateMethod      = _updateMethodCache[type] as MethodInfo;
                _defaultFillMethod = _defaultFillMethodCache[type] as MethodInfo;
            }
        }
Exemplo n.º 2
0
        public override bool Equals(object obj)
        {
            DataAdapterAttribute other = obj as DataAdapterAttribute;

            if (other != null)
            {
                if (_getDataMethodNames.Length != other._getDataMethodNames.Length)
                {
                    return(false);
                }
                for (int i = 0; i < _getDataMethodNames.Length; i++)
                {
                    if (_getDataMethodNames[i] != other._getDataMethodNames[i])
                    {
                        return(false);
                    }
                }

                return((_dataAdapterType == other.DataAdapterType) &&
                       String.Equals(_updateMethodName, other._updateMethodName, StringComparison.OrdinalIgnoreCase));
            }
            return(false);
        }