LzmTW.uSystem.uCollection + SimpleFilter

Author:水如烟  

SimpleFilter.Array.vb

Namespace  LzmTW.uSystem.uCollection
    
Partial   Class  SimpleFilter( Of  T)

        
Public   Sub  Find( ByVal  collection  As  ICollection,  ByVal  propertyNameOfArray  As   String ByVal  locate  As   Object ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            Find(collection.GetEnumerator, propertyNameOfArray, locate, operate, searchValue)
        
End Sub

        
Public   Sub  Find( ByVal  enumerable  As  IEnumerable,  ByVal  propertyNameOfArray  As   String ByVal  locate  As   Object ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            Find(enumerable.GetEnumerator, propertyNameOfArray, locate, operate, searchValue)
        
End Sub

        
Public   Sub  Find( ByVal  items  As  T(),  ByVal  propertyNameOfArray  As   String ByVal  locate  As   Object ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            Find(items.GetEnumerator, propertyNameOfArray, locate, operate, searchValue)
        
End Sub

        
Public   Sub  Find( ByVal  enumerator  As  IEnumerator,  ByVal  propertyNameOfArray  As   String ByVal  locate  As   Object ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            
Dim  baseTypeObject  As   Object
            
Try
                
With  enumerator
                    
While  .MoveNext

                        baseTypeObject 
=   Me .GetArrayPropertyValue(.Current, propertyNameOfArray, locate)

                        
If  BaseTypeCompare.IsValid(baseTypeObject, operate, searchValue)  Then
                            InternalAddItem(
CType (.Current, T))
                        
End   If

                    
End   While
                
End   With
            
Catch  ex  As  Exception

            
End   Try
        
End Sub

        
Public   Sub  Find( ByVal  collection  As  ICollection,  ByVal  propertyNameOfArray  As   String ByVal  locate  As   Object ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )
            Find(collection.GetEnumerator, propertyNameOfArray, locate, operate, aValue, bValue)
        
End Sub

        
Public   Sub  Find( ByVal  enumerable  As  IEnumerable,  ByVal  propertyNameOfArray  As   String ByVal  locate  As   Object ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )
            Find(enumerable.GetEnumerator, propertyNameOfArray, locate, operate, aValue, bValue)
        
End Sub

        
Public   Sub  Find( ByVal  items  As  T(),  ByVal  propertyNameOfArray  As   String ByVal  locate  As   Object ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )
            Find(items.GetEnumerator, propertyNameOfArray, locate, operate, aValue, bValue)
        
End Sub


        
Public   Sub  Find( ByVal  enumerator  As  IEnumerator,  ByVal  propertyNameOfArray  As   String ByVal  locate  As   Object ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )
            
Dim  baseTypeObject  As   Object
            
With  enumerator
                
While  .MoveNext

                    baseTypeObject 
=   Me .GetArrayPropertyValue(.Current, propertyNameOfArray, locate)

                    
If  BaseTypeCompare.IsValid(baseTypeObject, operate, aValue, bValue)  Then
                        InternalAddItem(
CType (.Current, T))
                    
End   If
                
End   While
            
End   With
        
End Sub

        
Public   Sub  Find( ByVal  collection  As  ICollection,  ByVal  propertyNameOfArray  As   String ByVal  locate  As   Object ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            Find(collection.GetEnumerator, propertyNameOfArray, locate, operate, values)
        
End Sub

        
Public   Sub  Find( ByVal  enumerable  As  IEnumerable,  ByVal  propertyNameOfArray  As   String ByVal  locate  As   Object ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            Find(enumerable.GetEnumerator, propertyNameOfArray, locate, operate, values)
        
End Sub

        
Public   Sub  Find( ByVal  items  As  T(),  ByVal  propertyNameOfArray  As   String ByVal  locate  As   Object ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            Find(items.GetEnumerator, propertyNameOfArray, locate, operate, values)
        
End Sub


        
Public   Sub  Find( ByVal  enumerator  As  IEnumerator,  ByVal  propertyNameOfArray  As   String ByVal  locate  As   Object ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            
Dim  baseTypeObject  As   Object

            
With  enumerator
                
While  .MoveNext

                    baseTypeObject 
=   Me .GetArrayPropertyValue(.Current, propertyNameOfArray, locate)

                    
If  BaseTypeCompare.IsValid(baseTypeObject, operate, values)  Then
                        InternalAddItem(
CType (.Current, T))
                    
End   If
                
End   While
            
End   With
        
End Sub

    
End Class

End Namespace

 SimpleFilter.Member.vb

Namespace  LzmTW.uSystem.uCollection
    
Partial   Class  SimpleFilter( Of  T)

        
Public   Sub  Find( ByVal  collection  As  ICollection,  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            Find(collection.GetEnumerator, MemberNameNeedBaseType, operate, searchValue)
        
End Sub

        
Public   Sub  Find( ByVal  enumerable  As  IEnumerable,  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            Find(enumerable.GetEnumerator, MemberNameNeedBaseType, operate, searchValue)
        
End Sub

        
Public   Sub  Find( ByVal  items  As  T(),  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            Find(items.GetEnumerator, MemberNameNeedBaseType, operate, searchValue)
        
End Sub

        
Public   Sub  Find( ByVal  enumerator  As  IEnumerator,  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            
Dim  baseTypeObject  As   Object
            
Try
                
With  enumerator
                    
While  .MoveNext

                        baseTypeObject 
=  uReflection.MemberInfoFunction.GetMemberValue(.Current, MemberNameNeedBaseType)

                        
If  BaseTypeCompare.IsValid(baseTypeObject, operate, searchValue)  Then
                            InternalAddItem(
CType (.Current, T))
                        
End   If

                    
End   While
                
End   With
            
Catch  ex  As  Exception

            
End   Try
        
End Sub

        
Public   Sub  Find( ByVal  collection  As  ICollection,  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )
            Find(collection.GetEnumerator, MemberNameNeedBaseType, operate, aValue, bValue)
        
End Sub

        
Public   Sub  Find( ByVal  enumerable  As  IEnumerable,  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )
            Find(enumerable.GetEnumerator, MemberNameNeedBaseType, operate, aValue, bValue)
        
End Sub

        
Public   Sub  Find( ByVal  items  As  T(),  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )
            Find(items.GetEnumerator, MemberNameNeedBaseType, operate, aValue, bValue)
        
End Sub


        
Public   Sub  Find( ByVal  enumerator  As  IEnumerator,  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )
            
Dim  baseTypeObject  As   Object
            
With  enumerator
                
While  .MoveNext

                    baseTypeObject 
=  uReflection.MemberInfoFunction.GetMemberValue(.Current, MemberNameNeedBaseType)

                    
If  BaseTypeCompare.IsValid(baseTypeObject, operate, aValue, bValue)  Then
                        InternalAddItem(
CType (.Current, T))
                    
End   If
                
End   While
            
End   With
        
End Sub

        
Public   Sub  Find( ByVal  collection  As  ICollection,  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            Find(collection.GetEnumerator, MemberNameNeedBaseType, operate, values)
        
End Sub

        
Public   Sub  Find( ByVal  enumerable  As  IEnumerable,  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            Find(enumerable.GetEnumerator, MemberNameNeedBaseType, operate, values)
        
End Sub

        
Public   Sub  Find( ByVal  items  As  T(),  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            Find(items.GetEnumerator, MemberNameNeedBaseType, operate, values)
        
End Sub


        
Public   Sub  Find( ByVal  enumerator  As  IEnumerator,  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            
Dim  baseTypeObject  As   Object

            
With  enumerator
                
While  .MoveNext

                    baseTypeObject 
=  uReflection.MemberInfoFunction.GetMemberValue(.Current, MemberNameNeedBaseType)

                    
If  BaseTypeCompare.IsValid(baseTypeObject, operate, values)  Then
                        InternalAddItem(
CType (.Current, T))
                    
End   If
                
End   While
            
End   With
        
End Sub

    
End Class

End Namespace

SimpleFilter.Node.vb

Namespace  LzmTW.uSystem.uCollection
    
Partial   Class  SimpleFilter( Of  T)


        
Public   Sub  Find( ByVal  node  As  T,  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            
Dim  baseTypeObject  As   Object

            
Try
                baseTypeObject 
=  uReflection.MemberInfoFunction.GetMemberValue(node, MemberNameNeedBaseType)

                
If  BaseTypeCompare.IsValid(baseTypeObject, operate, searchValue)  Then
                    InternalAddItem(node)
                
End   If

                
Dim  mNodeChild  As   Object   =   Me .GetNodeChild(node)
                
If  mNodeChild  Is   Nothing   Then   Exit   Try

                
Dim  mEnumerator  As  IEnumerator
                mEnumerator 
=   CType (mNodeChild, Collections.IEnumerable).GetEnumerator

                
With  mEnumerator
                    
While  .MoveNext
                        Find(
CType (.Current, T), MemberNameNeedBaseType, operate, searchValue)
                    
End   While
                
End   With
            
Catch  ex  As  Exception

            
End   Try
        
End Sub


        
Public   Sub  Find( ByVal  node  As  T,  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )

            
Dim  baseTypeObject  As   Object

            
Try
                baseTypeObject 
=  uReflection.MemberInfoFunction.GetMemberValue(node, MemberNameNeedBaseType)

                
If  BaseTypeCompare.IsValid(baseTypeObject, operate, aValue, bValue)  Then
                    InternalAddItem(node)
                
End   If

                
Dim  mNodeChild  As   Object   =   Me .GetNodeChild(node)
                
If  mNodeChild  Is   Nothing   Then   Exit   Try

                
Dim  mEnumerator  As  IEnumerator
                mEnumerator 
=   CType (mNodeChild, Collections.IEnumerable).GetEnumerator

                
With  mEnumerator
                    
While  .MoveNext
                        Find(
CType (.Current, T), MemberNameNeedBaseType, operate, aValue, bValue)
                    
End   While
                
End   With
            
Catch  ex  As  Exception
            
End   Try
        
End Sub


        
Public   Sub  Find( ByVal  node  As  T,  ByVal  MemberNameNeedBaseType  As   String ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            
Dim  baseTypeObject  As   Object

            
Try
                baseTypeObject 
=  uReflection.MemberInfoFunction.GetMemberValue(node, MemberNameNeedBaseType)

                
If  BaseTypeCompare.IsValid(baseTypeObject, operate, values)  Then
                    InternalAddItem(node)
                
End   If

                
Dim  mNodeChild  As   Object   =   Me .GetNodeChild(node)
                
If  mNodeChild  Is   Nothing   Then   Exit   Try

                
Dim  mEnumerator  As  IEnumerator
                mEnumerator 
=   CType (mNodeChild, Collections.IEnumerable).GetEnumerator

                
With  mEnumerator
                    
While  .MoveNext
                        Find(
CType (.Current, T), MemberNameNeedBaseType, operate, values)
                    
End   While
                
End   With
            
Catch  ex  As  Exception
            
End   Try
        
End Sub

    
End Class

End Namespace

SimpleFilter.Simple.vb

Namespace  LzmTW.uSystem.uCollection
    
Partial   Class  SimpleFilter( Of  T)

        
Public   Sub  Find( ByVal  collection  As  ICollection,  ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            Find(collection.GetEnumerator, operate, searchValue)
        
End Sub

        
Public   Sub  Find( ByVal  enumerable  As  IEnumerable,  ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            Find(enumerable.GetEnumerator, operate, searchValue)
        
End Sub

        
Public   Sub  Find( ByVal  items  As  T(),  ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            Find(items.GetEnumerator, operate, searchValue)
        
End Sub

        
Public   Sub  Find( ByVal  enumerator  As  IEnumerator,  ByVal  operate  As  CompareOperate,  ByVal  searchValue  As   Object )
            
With  enumerator
                
While  .MoveNext
                    
If  BaseTypeCompare.IsValid( Of  T)( CType (.Current, T), operate, searchValue)  Then
                        InternalAddItem(
CType (.Current, T))
                    
End   If
                
End   While
            
End   With
        
End Sub

        
Public   Sub  Find( ByVal  collection  As  ICollection,  ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )
            Find(collection.GetEnumerator, operate, aValue, bValue)
        
End Sub

        
Public   Sub  Find( ByVal  enumerable  As  IEnumerable,  ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )
            Find(enumerable.GetEnumerator, operate, aValue, bValue)
        
End Sub

        
Public   Sub  Find( ByVal  items  As  T(),  ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )
            Find(items.GetEnumerator, operate, aValue, bValue)
        
End Sub


        
Public   Sub  Find( ByVal  enumerator  As  IEnumerator,  ByVal  operate  As  CompareOperate,  ByVal  aValue  As   Object ByVal  bValue  As   Object )
            
With  enumerator
                
While  .MoveNext
                    
If  BaseTypeCompare.IsValid( Of  T)( CType (.Current, T), operate, aValue, bValue)  Then
                        InternalAddItem(
CType (.Current, T))
                    
End   If
                
End   While
            
End   With
        
End Sub

        
Public   Sub  Find( ByVal  collection  As  ICollection,  ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            Find(collection.GetEnumerator, operate, values)
        
End Sub

        
Public   Sub  Find( ByVal  enumerable  As  IEnumerable,  ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            Find(enumerable.GetEnumerator, operate, values)
        
End Sub

        
Public   Sub  Find( ByVal  items  As  T(),  ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            Find(items.GetEnumerator, operate, values)
        
End Sub


        
Public   Sub  Find( ByVal  enumerator  As  IEnumerator,  ByVal  operate  As  CompareOperate,  ByVal   ParamArray  values()  As   Object )
            
With  enumerator
                
While  .MoveNext
                    
If  BaseTypeCompare.IsValid( Of  T)( CType (.Current, T), operate, values)  Then
                        InternalAddItem(
CType (.Current, T))
                    
End   If
                
End   While
            
End   With
        
End Sub

    
End Class

End Namespace

SimpleFilter.vb

Namespace  LzmTW.uSystem.uCollection
    
Public   Class  SimpleFilter( Of  T)
        
Private  gResult( - 1 As  T

        
Public   Sub  Clear()
            
ReDim  gResult( - 1 )
        
End Sub

        
Public   ReadOnly   Property  Result()  As  T()
            
Get
                
Return  gResult
            
End   Get
        
End Property

        
Private   Sub  InternalAddItem( ByVal  item  As  T)
            
SyncLock  LzmTW.uRuntimeHelper.InternalSyncObject
                CommonFunction.Append(
Of  T)(gResult, item)
            
End   SyncLock
        
End Sub

        
Private   Function  GetArrayPropertyValue( ByVal  item  As   Object ByVal  ArrayPropertyName  As   String ByVal  locate  As   Object As   Object
            
Dim  mResult  As   Object   =   Nothing

            
Dim  t  As  Type  =  item.GetType
            
Dim  locateType  As  Type  =  locate.GetType
            
Dim  m  As  Reflection.MemberInfo()
            
Dim  p  As  Reflection.PropertyInfo

            m 
=  t.GetMember(ArrayPropertyName)
            
If  m.Length  >   1   Then
                p 
=  t.GetProperty(ArrayPropertyName,  New  Type() {locateType})
                mResult 
=  p.GetValue(item,  New   Object () {locate})
            
Else
                p 
=  t.GetProperty(ArrayPropertyName)
                mResult 
=   CType (p.GetValue(item,  Nothing ),  Object ())( CType (locate,  Integer ))
            
End   If

            
Return  mResult
        
End Function

        
Private   Function  GetArrayFieldValue( ByVal  item  As   Object ByVal  ArrayPropertyName  As   String ByVal  locate  As   Object As   Object
            
Dim  mResult  As   Object   =   Nothing

            
Dim  t  As  Type  =  item.GetType
            
Dim  locateType  As  Type  =  locate.GetType
            
Dim  f  As  Reflection.FieldInfo

            f 
=  t.GetField(ArrayPropertyName)
            
If  locate.GetType.IsValueType  Then
                mResult 
=   CType (f.GetValue(item),  Object ())( CType (locate,  Integer ))
            
Else

            
End   If

            
Return  mResult
        
End Function

        
Private   Function  GetNodeChild( ByVal  item  As  T)  As   Object
            
Dim  mResult  As   Object   =   Nothing

            
Dim  mService  As   New  uReflection.GetSameTypeCollectionFromType
            mService.Read(
GetType (T))

            
' 暂只简单考虑
             If  mService.Result.Length  >   0   Then
                
Try
                    
Dim  p  As  Reflection.PropertyInfo  =   CType (mService.Result( 0 ), Reflection.PropertyInfo)
                    mResult 
=  p.GetValue(item,  Nothing )
                
Catch  ex  As  Exception
                
End   Try
            
Else
                mService.Clear()
                mService.Read(
GetType (T),  True )

                
If  mService.Result.Length  >   0   Then
                    
Try
                        
Dim  p  As  Reflection.PropertyInfo  =   CType (mService.Result( 0 ), Reflection.PropertyInfo)
                        mResult 
=  p.GetValue(item,  Nothing )
                    
Catch  ex  As  Exception
                    
End   Try
                
End   If

            
End   If

            
Return  mResult
        
End Function

        
Public   Sub  ForEach( ByVal  action  As  Action( Of  T))
            CommonFunction.ForEach(
Of  T)( Me .Result, action)
        
End Sub
    
End Class

End Namespace

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值