本文整理汇总了C#中Type.GetMember方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetMember方法的具体用法?C# Type.GetMember怎么用?C# Type.GetMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.GetMember方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Reports_RMLauncher
static Reports_RMLauncher()
{
_sendEmailMaint = System.Web.Compilation.BuildManager.GetType(_SENDEMAILMAINT_TYPE, false);
_sendEmailMethod = null;
MemberInfo[] search = null;
if (_sendEmailMaint != null)
{
_sendEmailMethod = _sendEmailMaint.GetMethod(_SENDEMAIL_METHOD, BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.Public);
search = _sendEmailMaint.GetMember(_SENDEMAILPARAMS_TYPE);
}
Type sendEmailParams = search != null && search.Length > 0 && search[0] is Type ? (Type)search[0] : null;
if (sendEmailParams != null)
{
_sendEmailParamsCtor = sendEmailParams.GetConstructor(new Type[0]);
_fromMethod = sendEmailParams.GetProperty("From");
_toMethod = sendEmailParams.GetProperty("To");
_ccMethod = sendEmailParams.GetProperty("Cc");
_bccMethod = sendEmailParams.GetProperty("Bcc");
_subjectMethod = sendEmailParams.GetProperty("Subject");
_bodyMethod = sendEmailParams.GetProperty("Body");
_activitySourceMethod = sendEmailParams.GetProperty("Source");
_parentSourceMethod = sendEmailParams.GetProperty("ParentSource");
_templateIDMethod = sendEmailParams.GetProperty("TemplateID");
_attachmentsMethod = sendEmailParams.GetProperty("Attachments");
}
_canSendEmail = _sendEmailParamsCtor != null && _sendEmailMaint != null && _sendEmailMethod != null &&
_fromMethod != null && _toMethod != null && _ccMethod != null && _bccMethod != null &&
_subjectMethod != null && _bodyMethod != null &&
_activitySourceMethod != null && _parentSourceMethod != null && _templateIDMethod != null && _attachmentsMethod != null;
}
示例2: Pages_ReportLauncher
static Pages_ReportLauncher()
{
_sendEmailMaint = System.Web.Compilation.BuildManager.GetType(_SENDEMAILMAINT_TYPE, false);
_sendEmailMethod = null;
MemberInfo[] search = null;
if (_sendEmailMaint != null)
{
_sendEmailMethod = _sendEmailMaint.GetMethod(_SENDEMAIL_METHOD, BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.Public);
search = _sendEmailMaint.GetMember(_SENDEMAILPARAMS_TYPE);
}
Type sendEmailParams = search != null && search.Length > 0 && search[0] is Type ? (Type)search[0] : null;
if (sendEmailParams != null)
{
_sendEmailParamsCtor = sendEmailParams.GetConstructor(new Type[0]);
_fromMethod = sendEmailParams.GetProperty("From");
_toMethod = sendEmailParams.GetProperty("To");
_ccMethod = sendEmailParams.GetProperty("Cc");
_bccMethod = sendEmailParams.GetProperty("Bcc");
_subjectMethod = sendEmailParams.GetProperty("Subject");
_bodyMethod = sendEmailParams.GetProperty("Body");
_activitySourceMethod = sendEmailParams.GetProperty("Source");
_parentSourceMethod = sendEmailParams.GetProperty("ParentSource");
_templateIDMethod = sendEmailParams.GetProperty("TemplateID");
_attachmentsMethod = sendEmailParams.GetProperty("Attachments");
}
_canSendEmail = _sendEmailParamsCtor != null && _sendEmailMaint != null && _sendEmailMethod != null &&
_fromMethod != null && _toMethod != null && _ccMethod != null && _bccMethod != null &&
_subjectMethod != null && _bodyMethod != null &&
_activitySourceMethod != null && _parentSourceMethod != null && _templateIDMethod != null && _attachmentsMethod != null && !PXSiteMap.IsPortal;
Type reportFunctionsType = System.Web.Compilation.BuildManager.GetType(_REPORTFUNCTIONS_TYPE, false);
if (reportFunctionsType != null)
ExpressionContext.RegisterExternalObject("Payments", Activator.CreateInstance(reportFunctionsType));
}
示例3: ImportElementInfo
XmlTypeMapElementInfoList ImportElementInfo (Type cls, string defaultName, string defaultNamespace, Type defaultType, XmlTypeMapMemberElement member, XmlAttributes atts)
{
EnumMap choiceEnumMap = null;
Type choiceEnumType = null;
XmlTypeMapElementInfoList list = new XmlTypeMapElementInfoList();
ImportTextElementInfo (list, defaultType, member, atts, defaultNamespace);
if (atts.XmlChoiceIdentifier != null) {
if (cls == null)
throw new InvalidOperationException ("XmlChoiceIdentifierAttribute not supported in this context.");
member.ChoiceMember = atts.XmlChoiceIdentifier.MemberName;
MemberInfo[] mems = cls.GetMember (member.ChoiceMember, BindingFlags.Instance|BindingFlags.Public);
if (mems.Length == 0)
throw new InvalidOperationException ("Choice member '" + member.ChoiceMember + "' not found in class '" + cls);
if (mems[0] is PropertyInfo) {
PropertyInfo pi = (PropertyInfo)mems[0];
if (!pi.CanWrite || !pi.CanRead)
throw new InvalidOperationException ("Choice property '" + member.ChoiceMember + "' must be read/write.");
choiceEnumType = pi.PropertyType;
}
else choiceEnumType = ((FieldInfo)mems[0]).FieldType;
member.ChoiceTypeData = TypeTranslator.GetTypeData (choiceEnumType);
if (choiceEnumType.IsArray)
choiceEnumType = choiceEnumType.GetElementType ();
choiceEnumMap = ImportTypeMapping (choiceEnumType).ObjectMap as EnumMap;
if (choiceEnumMap == null)
throw new InvalidOperationException ("The member '" + mems[0].Name + "' is not a valid target for XmlChoiceIdentifierAttribute.");
}
if (atts.XmlElements.Count == 0 && list.Count == 0)
{
XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(defaultType));
elem.ElementName = defaultName;
elem.Namespace = defaultNamespace;
if (elem.TypeData.IsComplexType)
elem.MappedType = ImportTypeMapping (defaultType, null, defaultNamespace);
list.Add (elem);
}
bool multiType = (atts.XmlElements.Count > 1);
foreach (XmlElementAttribute att in atts.XmlElements)
{
Type elemType = (att.Type != null) ? att.Type : defaultType;
XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(elemType, att.DataType));
elem.Form = att.Form;
if (elem.Form != XmlSchemaForm.Unqualified)
elem.Namespace = (att.Namespace != null) ? att.Namespace : defaultNamespace;
elem.IsNullable = att.IsNullable;
if (elem.IsNullable && !elem.TypeData.IsNullable)
throw new InvalidOperationException ("IsNullable may not be 'true' for value type " + elem.TypeData.FullTypeName + " in member '" + defaultName + "'");
if (elem.TypeData.IsComplexType)
{
if (att.DataType.Length != 0) throw new InvalidOperationException (
string.Format(CultureInfo.InvariantCulture, "'{0}' is "
+ "an invalid value for '{1}.{2}' of type '{3}'. "
+ "The property may only be specified for primitive types.",
att.DataType, cls.FullName, defaultName,
elem.TypeData.FullTypeName));
elem.MappedType = ImportTypeMapping (elemType, null, elem.Namespace);
}
if (att.ElementName.Length != 0) {
elem.ElementName = XmlConvert.EncodeLocalName(att.ElementName);
} else if (multiType) {
if (elem.MappedType != null) {
elem.ElementName = elem.MappedType.ElementName;
} else {
elem.ElementName = TypeTranslator.GetTypeData (elemType).XmlType;
}
} else {
elem.ElementName = defaultName;
}
if (choiceEnumMap != null) {
string cname = choiceEnumMap.GetEnumName (choiceEnumType.FullName, elem.ElementName);
if (cname == null)
throw new InvalidOperationException (string.Format (
CultureInfo.InvariantCulture, "Type {0} is missing"
+ " enumeration value '{1}' for element '{1} from"
+ " namespace '{2}'.", choiceEnumType, elem.ElementName,
elem.Namespace));
elem.ChoiceValue = Enum.Parse (choiceEnumType, cname, false);
}
list.Add (elem);
}
return list;
}
示例4: GetMember
public static MemberInfo[] GetMember(Type type, string name)
{
Requires.NotNull(type, "type");
return type.GetMember(name);
}
示例5: CreateGroupByMemberAssignments
private List<MemberAssignment> CreateGroupByMemberAssignments(Type type, IEnumerable<GroupByPropertyNode> properties)
{
List<MemberAssignment> wrapperTypeMemberAssignments = new List<MemberAssignment>();
foreach (var node in properties)
{
var member = type.GetMember(node.Name).Single();
if (node.Accessor != null)
{
wrapperTypeMemberAssignments.Add(Expression.Bind(member, BindAccessor(node.Accessor)));
}
else
{
var memberType = (member as PropertyInfo).PropertyType;
var expr = Expression.MemberInit(Expression.New(memberType), CreateGroupByMemberAssignments(memberType, node.Children));
wrapperTypeMemberAssignments.Add(Expression.Bind(member, expr));
}
}
return wrapperTypeMemberAssignments;
}
示例6: GetProperty
private static PropertyInfo GetProperty(Type targetType, string propertyName, BindingFlags bindingFlags)
{
// Properties may be overloaded (in VB), so we have to ---- out those that we can support,
// i.e., those that have no parameters.
MemberInfo[] members = targetType.GetMember(propertyName, MemberTypes.Property, bindingFlags);
for (int m = 0; m < members.Length; ++m)
{
PropertyInfo pi = (PropertyInfo)members[m];
ParameterInfo[] parms = pi.GetIndexParameters();
if (parms == null || parms.Length == 0)
return pi;
}
return null;
}
示例7: ResolveFieldOrProperty
internal MemberInfo ResolveFieldOrProperty(Type targetType, string name)
{
BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy;
if (AllowInternalMembers(targetType))
bindingFlags |= BindingFlags.NonPublic;
// Look up a field or property of the given name.
MemberInfo[] results = targetType.GetMember(name, MemberTypes.Field | MemberTypes.Property, bindingFlags);
if (results != null)
{
int numResults = results.Length;
if (numResults == 1)
{
// If we found exactly one, we're good.
return results[0];
}
else if (numResults > 1)
{
// We may have found more than one property if it's overloaded. If we find one without
// any parameters, return that one.
for (int i = 0; i < numResults; ++i)
{
MemberInfo member = results[i];
System.Diagnostics.Debug.Assert(member.MemberType == MemberTypes.Property, "only properties can be overloaded");
PropertyInfo pi = (PropertyInfo)member;
ParameterInfo[] parms = pi.GetIndexParameters();
if (parms == null || parms.Length == 0)
{
if (pi != null)
{
IsAuthorized(pi.PropertyType);
}
return pi;
}
}
}
}
// If we didn't find it, and if the target type is an interface, try resolving a property
// that may exist in its inheritance chain. (Fields cannot appear on interfaces.)
if (targetType.IsInterface)
return ResolveProperty(targetType, name, bindingFlags);
// Otherwise, it's no good.
return null;
}
示例8: GetAssociatedMetadata
public static Attribute[] GetAssociatedMetadata(Type type, string memberName) {
var memberTuple = new Tuple<Type, string>(type, memberName);
Attribute[] attributes;
if (_typeMemberCache.TryGetValue(memberTuple, out attributes)) {
return attributes;
}
// Allow fields and properties
MemberTypes allowedMemberTypes = MemberTypes.Property | MemberTypes.Field;
// Only public static/instance members
BindingFlags searchFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
// Try to find a matching member on type
MemberInfo matchingMember = type.GetMember(memberName, allowedMemberTypes, searchFlags).FirstOrDefault();
if (matchingMember != null) {
attributes = Attribute.GetCustomAttributes(matchingMember, true /* inherit */);
}
else {
attributes = emptyAttributes;
}
_typeMemberCache.TryAdd(memberTuple, attributes);
return attributes;
}
示例9: SetMethodCompletions
internal void SetMethodCompletions(Type computedType, Type thisType, string methodName, bool includeStatic, bool includeInstance, RuleValidation validation)
{
BindingFlags flags = BindingFlags.Public;
if (computedType.Assembly == thisType.Assembly)
flags |= BindingFlags.NonPublic;
if (includeInstance)
flags |= BindingFlags.Instance;
if (includeStatic)
flags |= BindingFlags.Static | BindingFlags.FlattenHierarchy;
List<MemberInfo> candidateMethods = new List<MemberInfo>();
MemberInfo[] methods = computedType.GetMember(methodName, MemberTypes.Method, flags);
AddCandidates(candidateMethods, methods);
if (computedType.IsInterface)
{
List<Type> parentInterfaces = new List<Type>();
parentInterfaces.AddRange(computedType.GetInterfaces());
for (int i = 0; i < parentInterfaces.Count; ++i)
{
methods = parentInterfaces[i].GetMember(methodName, MemberTypes.Method, flags);
AddCandidates(candidateMethods, methods);
Type[] pInterfaces = parentInterfaces[i].GetInterfaces();
if (pInterfaces.Length > 0)
parentInterfaces.AddRange(pInterfaces);
}
// Add members from System.Object as well.
methods = typeof(object).GetMember(methodName, MemberTypes.Method, flags);
AddCandidates(candidateMethods, methods);
}
// add in any extension methods
List<ExtensionMethodInfo> ext = validation.ExtensionMethods;
foreach (ExtensionMethodInfo extension in ext)
{
// does it have the right name and is the type compatible
ValidationError error;
if ((extension.Name == methodName) &&
(RuleValidation.TypesAreAssignable(computedType, extension.AssumedDeclaringType, null, out error)))
{
candidateMethods.Add(extension);
}
}
completions = candidateMethods;
}
示例10: ParseNestedType
// Parse nested types.
private Type ParseNestedType(ParserContext parserContext, Type currentType)
{
System.Diagnostics.Debug.Assert(parserContext.CurrentToken.TokenID == TokenID.Dot);
Type nestedType = null;
while (parserContext.CurrentToken.TokenID == TokenID.Dot)
{
// Save the state of the scanner. Since we can't tell if we're parsing a nested
// type or a member, we'll need to backtrack if we go too far.
int savedTokenState = parserContext.SaveCurrentToken();
Token token = parserContext.NextToken();
if (token.TokenID != TokenID.Identifier)
{
if (parserContext.provideIntellisense && token.TokenID == TokenID.EndOfInput)
{
parserContext.SetTypeMemberCompletions(currentType, validation.ThisType, true, validation);
return null;
}
else
{
throw new RuleSyntaxException(ErrorNumbers.Error_MissingIdentifierAfterDot, Messages.Parser_MissingIdentifierAfterDot, parserContext.CurrentToken.StartPosition);
}
}
string name = (string)token.Value;
BindingFlags bindingFlags = BindingFlags.Public;
if (currentType.Assembly == validation.ThisType.Assembly)
bindingFlags |= BindingFlags.NonPublic;
if (parserContext.NextToken().TokenID == TokenID.Less)
{
// Might be a generic type.
List<Type> candidateGenericTypes = new List<Type>();
Type[] nestedTypes = currentType.GetNestedTypes(bindingFlags);
string prefix = name + "`";
for (int i = 0; i < nestedTypes.Length; ++i)
{
Type candidateType = nestedTypes[i];
if (candidateType.Name.StartsWith(prefix, StringComparison.Ordinal))
candidateGenericTypes.Add(candidateType);
}
if (candidateGenericTypes.Count == 0)
{
// It wasn't a generic type. Reset the scanner to the saved state.
parserContext.RestoreCurrentToken(savedTokenState);
// Also reset the deepenst nested type.
nestedType = currentType;
break;
}
nestedType = ParseGenericType(parserContext, candidateGenericTypes, name);
currentType = nestedType;
}
else
{
// Might be a non-generic type.
MemberInfo[] mi = currentType.GetMember(name, bindingFlags);
if (mi == null || mi.Length != 1 || (mi[0].MemberType != MemberTypes.NestedType && mi[0].MemberType != MemberTypes.TypeInfo))
{
// We went too far, reset the state.
parserContext.RestoreCurrentToken(savedTokenState);
// Also reset the deepest nested type.
nestedType = currentType;
break;
}
nestedType = (Type)mi[0];
if (currentType.IsGenericType && nestedType.IsGenericTypeDefinition)
{
// The outer type was generic (and bound), but the nested type is not. We have
// to re-bind the generic arguments.
nestedType = nestedType.MakeGenericType(currentType.GetGenericArguments());
}
currentType = nestedType;
}
}
return nestedType;
}
示例11: ImportEnumMapping
XmlTypeMapping ImportEnumMapping (Type type, string defaultNamespace)
{
TypeData typeData = TypeTranslator.GetTypeData (type);
XmlTypeMapping map = helper.GetRegisteredClrType (type, GetTypeNamespace (typeData, defaultNamespace));
if (map != null) return map;
map = CreateTypeMapping (typeData, null, defaultNamespace);
helper.RegisterClrType (map, type, map.Namespace);
map.MultiReferenceType = true;
string [] names = Enum.GetNames (type);
EnumMap.EnumMapMember[] members = new EnumMap.EnumMapMember[names.Length];
for (int n=0; n<names.Length; n++)
{
MemberInfo[] mem = type.GetMember (names[n]);
string xmlName = names[n];
object[] atts = mem[0].GetCustomAttributes (typeof(SoapEnumAttribute), false);
if (atts.Length > 0) xmlName = ((SoapEnumAttribute)atts[0]).Name;
members[n] = new EnumMap.EnumMapMember (xmlName, names[n]);
}
bool isFlags = type.GetCustomAttributes (typeof(FlagsAttribute),false).Length > 0;
map.ObjectMap = new EnumMap (members, isFlags);
ImportTypeMapping (typeof(object), defaultNamespace).DerivedTypes.Add (map);
return map;
}
示例12: CreateSelectMemberAssigments
private List<MemberAssignment> CreateSelectMemberAssigments(Type type, MemberExpression propertyAccessor,
IEnumerable<GroupByPropertyNode> properties)
{
var wrapperTypeMemberAssignments = new List<MemberAssignment>();
if (_groupingProperties != null)
{
foreach (var node in properties)
{
var nodePropertyAccessor = Expression.Property(propertyAccessor, node.Name);
var member = type.GetMember(node.Name).Single();
if (node.Expression != null)
{
wrapperTypeMemberAssignments.Add(Expression.Bind(member, nodePropertyAccessor));
}
else
{
var memberType = (member as PropertyInfo).PropertyType;
var expr = Expression.MemberInit(Expression.New(memberType),
CreateSelectMemberAssigments(memberType, nodePropertyAccessor, node.ChildTransformations));
wrapperTypeMemberAssignments.Add(Expression.Bind(member, expr));
}
}
}
return wrapperTypeMemberAssignments;
}
示例13: ImportEnumMapping
XmlTypeMapping ImportEnumMapping (Type type, XmlRootAttribute root, string defaultNamespace)
{
TypeData typeData = TypeTranslator.GetTypeData (type);
XmlTypeMapping map = helper.GetRegisteredClrType (type, GetTypeNamespace (typeData, root, defaultNamespace));
if (map != null) return map;
map = CreateTypeMapping (typeData, root, null, defaultNamespace);
helper.RegisterClrType (map, type, map.XmlTypeNamespace);
string [] names = Enum.GetNames (type);
ArrayList members = new ArrayList();
foreach (string name in names)
{
MemberInfo[] mem = type.GetMember (name);
string xmlName = null;
object[] atts = mem[0].GetCustomAttributes (typeof(XmlIgnoreAttribute), false);
if (atts.Length > 0) continue;
atts = mem[0].GetCustomAttributes (typeof(XmlEnumAttribute), false);
if (atts.Length > 0) xmlName = ((XmlEnumAttribute)atts[0]).Name;
if (xmlName == null) xmlName = name;
members.Add (new EnumMap.EnumMapMember (xmlName, name));
}
bool isFlags = type.GetCustomAttributes (typeof(FlagsAttribute),false).Length > 0;
map.ObjectMap = new EnumMap ((EnumMap.EnumMapMember[])members.ToArray (typeof(EnumMap.EnumMapMember)), isFlags);
ImportTypeMapping (typeof(object)).DerivedTypes.Add (map);
return map;
}