System.didirectory

xiaoxiao2021-03-06  166

/ / == ==

//

//

// Copyright (C) 2002 Microsoft Corporation. All Rights Reserved.

//

// the use and distribution terms for this Software Are Contained in The File

// Named license.txt, Which can be found in the root of this distribution.

// by using this software in any fashion, you are agreeing to be bound by the

// Terms of this license.

//

// You Must Not Remove this Notice, or Any Other, from this software.

//

//

/ / == - ==

// __filters.cs

//

// this class defines the Delegate Methods for the COM IMPLEMENTED FILTERS.

//

// Date: July 98

//

Namespace system {

Using system;

Using system.reflection;

USING SYSTEM.GLOBALIZATION;

[Serializable ()]

INTERNAL CLASS __FILTERS {

// filters ...

// The Following Are The Builtin Filters Defined for this class. These

// Should Really Be defined as static methods. They is used in As delegates

// Which Currently Doesn't Support Static Methods. We Will Change this

// Once the compiler supports delegates.

// Filterattribute

// this Method Will Search for a Member Based Upon The Attribute Passed IN.

// filtercriteria - an Int32 representing the attribute

Internal Virtual Bool Filterattribute (MemberInfo M, Object Filtercriteria)

{

// check what the criteria object is an integer object ibject

IF (Filtercriteria == NULL)

Throw new invalidfiltercriteriaException (Environment.GetResourceString ("RFLCT.FLTCRITITINT")));

Switch (m.membertype)

{

Case MEMBERTYPES.CONSTRUCTOR:

Case membertypes.method: {

MethodAttributes criteria = 0;

Try {

INT i = (int) filtercriteria;

Criteria = (Methodattributes) i;

}

Catch (exception) {

Throw new invalidfiltercriteriaException ("RFLCT.FLTCRITITINT");}

MethodAttributes attr;

IF (M.Membertype == MEMBERTYPES.METHOD)

Attr = (MethodInfo) .attributes;

Else

Attr = (constructorinfo) .attribute;

IF ((criteria & methodattributes.member! = 0) && (attr & methodattributes.membraccessmask)! = (criteria & methodattributes.memberaccessmask)

Return False;

IF ((criteria & methodattributes.static)! = 0) && (attr & methodattributes.static) == 0)

Return False;

IF ((criteria & methodattributes.Final)! = 0) && (attr & methodattributes.final) == 0)

Return False;

IF ((criteria & methodattributes.virtual! = 0) && (attr & methodattributes.virtual) == 0)

Return False;

IF ((criteria & methodattributes.abstract)! = 0) && (Attr & Methodattributes.abstract) == 0)

Return False;

IF ((criteria & methodattributes.specialname)! = 0) && (attr & methodattributes.specialname) == 0)

Return False;

Return True;

}

Case membertypes.field:

{

FIELDATTRIBUTES criteria = 0;

Try {

INT i = (int) filtercriteria;

Criteria = (Fieldattributes) i;

}

Catch (exception) {

Throw new invalidfiltercriteriaException (Environment.GetResourceString ("RFLCT.FLTCRITITINT")));

}

Fieldattributes attr = (FieldInfo) .attributes;

IF ((Criteria & Fieldattributes.fieldAccessmask)! = 0) && (Attr & Fieldattributes.fieldAccessMask)! = (criteria & Fieldattributes.fieldAccessmask))

Return False;

IF ((criteria & fieldattributes.static)! = 0) && (Attr & Fieldattributes.static) == 0) Return False;

IF ((criteria & fieldattributes.initonly! = 0) && (attr & fieldttributes.initonly) == 0)

Return False;

IF ((criteria & fieldattributes.literal! = 0) && (attr & fieldttributes.literal == 0)

Return False;

IF ((criteria & fieldattributes.notserialized! = 0) && (attr & fieldttributes.notserialized) == 0)

Return False;

IF ((criteria & fieldattributes.pinvokeimpl)! = 0) && (attr & fieldttributes.pinvokeimpl) == 0)

Return False;

Return True;

}

}

Return False;

}

// filtername

// this Method Will Filter Based Upon the name. A Partial Wildcard

// at the end of the string is supported.

// filtercriteria - this is the string name

Internal Virtual Bool Filtername (MemberInfo M, Object Filtercriteria)

{

// check what the criteria object is a string object

IF (Filtercriteria == Null ||! (Filtercriteria Is String))

Throw new invalidfiltercriteriaException (Environment.GetResourceString ("RFLCT.FLTCRITSTRING");

// at the moment this fails if its done on a sales ....

String str = (String) Filtercriteria;

Str = str.trim ();

String name = m.Name;

// Hack to Skip The Get The Nest Class Name Only, as opposed to the mang one

IF (M.Membertype == MEMBERTYPES.NESTEDTYPE)

Name = name.substring (name.lastIndexof (' ') 1);

// Check to see if this is a prefix or exact match request

IF (str.length> 0 && str [str.length - 1] == '*') {

Str = str.substring (0, str.Length - 1); return (name.startswith (STR));

}

Return (Name.Equals (STR));

}

// filterignorecase

// this delegate Will Do a name search but does it with the

// Ignore Case Specified.

Internal Virtual Bool FilterignoreCase (MemberInfo M, Object Filtercriteria)

{

// check what the criteria object is a string object

IF (Filtercriteria == Null ||! (Filtercriteria Is String))

Throw new invalidfiltercriteriaException (Environment.GetResourceString ("RFLCT.FLTCRITSTRING");

String str = (string) filtercriteria;

Str = str.trim ();

String name = m.Name;

// Hack to Skip The Get The Nest Class Name Only, as opposed to the mang one

IF (M.Membertype == MEMBERTYPES.NESTEDTYPE)

Name = name.substring (name.lastIndexof (' ') 1);

// Check to see if this is a prefix or exact match request

IF (str.length> 0 && str [str.length - 1] == '*') {

Str = str.substring (0, str.length - 1);

Return (String.Compare (Name, 0, Str, 0, Str.Length, true, cultureinfo.invariantculture) == 0);

}

Return (String.comPare (Str, Name, True, CultureInfo.invariantculture) == 0);

}

}

}

转载请注明原文地址:https://www.9cbs.com/read-128279.html

New Post(0)