本文整理汇总了C#中IType.GetMembers方法的典型用法代码示例。如果您正苦于以下问题:C# IType.GetMembers方法的具体用法?C# IType.GetMembers怎么用?C# IType.GetMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IType
的用法示例。
在下文中一共展示了IType.GetMembers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CollectBaseTypeMembers
private static void CollectBaseTypeMembers(List<IEntity> members, IType baseType)
{
if (null == baseType) return;
members.Extend(baseType.GetMembers().Where(m => !(m is IConstructor) && !IsHiddenBy(m, members)));
CollectBaseTypeMembers(members, baseType.BaseType);
}
示例2: GetInterfaceImplementation
static IMember GetInterfaceImplementation (IType typeDefinition, IMember interfaceMethod)
{
if (typeDefinition == null || interfaceMethod == null)
return null;
List<IMember> result = new List<IMember> ();
var typeMembers = typeDefinition.GetMembers ().ToList();
for (int i = 0; i < typeMembers.Count; i++)
{
if (MemberComparer.MembersEquals(typeMembers[i], interfaceMethod))
{
result.Add (typeMembers[i]);
}
}
return result.Count > 0 ? result[0] : null;
}
示例3: GetProtocolMember
IMember GetProtocolMember (RefactoringContext ctx, IType protocolType, IMember member)
{
foreach (var m in protocolType.GetMembers (m => m.SymbolKind == member.SymbolKind && m.Name == member.Name)) {
if (!SignatureComparer.Ordinal.Equals (m, member))
return null;
var prop = m as IProperty;
if (prop != null) {
if (prop.CanGet && GenerateExportAttribute (ctx, prop.Getter) != null ||
prop.CanSet && GenerateExportAttribute (ctx, prop.Setter) != null)
return m;
} else {
if (GenerateExportAttribute (ctx, m) != null)
return m;
}
}
return null;
}
示例4: CollectMembersToImplement
public static List<IMember> CollectMembersToImplement(ITypeDefinition implementingType, IType abstractType)
{
var toImplement = new List<IMember>();
bool alreadyImplemented;
foreach (var member in abstractType.GetMembers (d => !d.IsSynthetic && d.IsAbstract)) {
alreadyImplemented = false;
var allBaseTypes = member.DeclaringType.GetAllBaseTypes().ToList ();
foreach (var cmet in implementingType.GetMembers (d => d.SymbolKind == member.SymbolKind && d.Name == member.Name)) {
if (allBaseTypes.Contains(cmet.DeclaringType))
continue;
if (ImplementInterfaceAction.CompareMembers(member, cmet)) {
alreadyImplemented = true;
break;
}
}
if (!alreadyImplemented)
toImplement.Add(member);
}
return toImplement;
}
示例5: BooDeclarations
public BooDeclarations(Node context, IType varType, bool instance)
{
if (varType != null)
foreach (var member in varType.GetMembers())
{
switch (member.EntityType)
{
case EntityType.Method:
FormatMethod(context, (IMethod)member, instance);
break;
case EntityType.Property:
FormatProperty(context, (IProperty)member, instance);
break;
case EntityType.Event:
FormatEvent(context, (IEvent)member, instance);
break;
case EntityType.Field:
FormatField(context, (IField)member, instance);
break;
}
}
//for (var i = 1000; i < 1300; i += 6)
// list.Add("a" + i, new Declaration { DisplayText = "a" + i, ImageIndex = i - 1000 });
}
示例6: BuildRefactoryMenuForItem
//.........这里部分代码省略.........
if (cls.GetSourceProject () != null && includeModifyCommands && ((cls.ClassType == ClassType.Class) || (cls.ClassType == ClassType.Struct))) {
ciset.CommandInfos.Add (GettextCatalog.GetString ("_Encapsulate Fields..."), new RefactoryOperation (refactorer.EncapsulateField));
ciset.CommandInfos.Add (GettextCatalog.GetString ("Override/Implement members..."), new RefactoryOperation (refactorer.OverrideOrImplementMembers));
}
ciset.CommandInfos.Add (IdeApp.CommandService.GetCommandInfo (RefactoryCommands.FindReferences), new RefactoryOperation (refactorer.FindReferences));
// if (canRename)
// ciset.CommandInfos.Add (GettextCatalog.GetString ("_Rename"), new RefactoryOperation (refactorer.Rename));
if (canRename && cls.ClassType == ClassType.Interface && eclass != null) {
// An interface is selected, so just need to provide these 2 submenu items
ciset.CommandInfos.Add (GettextCatalog.GetString ("Implement Interface (implicit)"), new RefactoryOperation (refactorer.ImplementImplicitInterface));
ciset.CommandInfos.Add (GettextCatalog.GetString ("Implement Interface (explicit)"), new RefactoryOperation (refactorer.ImplementExplicitInterface));
} else if (canRename && includeModifyCommands && cls.BaseType != null && cls.ClassType != ClassType.Interface && cls == eclass) {
// Class might have interfaces... offer to implement them
CommandInfoSet impset = new CommandInfoSet ();
CommandInfoSet expset = new CommandInfoSet ();
CommandInfoSet abstactset = new CommandInfoSet ();
bool ifaceAdded = false;
bool abstractAdded = false;
foreach (IReturnType rt in cls.BaseTypes) {
IType iface = ctx.GetType (rt);
if (iface == null)
continue;
if (iface.ClassType == ClassType.Interface) {
Refactorer ifaceRefactorer = new Refactorer (ctx, pinfo, cls, iface, rt);
impset.CommandInfos.Add (ambience.GetString (rt, OutputFlags.IncludeGenerics), new RefactoryOperation (ifaceRefactorer.ImplementImplicitInterface));
expset.CommandInfos.Add (ambience.GetString (rt, OutputFlags.IncludeGenerics), new RefactoryOperation (ifaceRefactorer.ImplementExplicitInterface));
ifaceAdded = true;
} else if (ContainsAbstractMembers (iface)) {
Refactorer ifaceRefactorer = new Refactorer (ctx, pinfo, cls, iface, rt);
abstactset.CommandInfos.Add (ambience.GetString (rt, OutputFlags.IncludeGenerics), new RefactoryOperation (ifaceRefactorer.ImplementAbstractMembers));
abstractAdded = true;
}
}
if (ifaceAdded) {
impset.Text = GettextCatalog.GetString ("Implement Interface (implicit)");
ciset.CommandInfos.Add (impset, null);
expset.Text = GettextCatalog.GetString ("Implement Interface (explicit)");
ciset.CommandInfos.Add (expset, null);
}
if (abstractAdded) {
abstactset.Text = GettextCatalog.GetString ("Implement abstract members");
ciset.CommandInfos.Add (abstactset, null);
}
}
} else if (item is IField) {
txt = GettextCatalog.GetString ("Field <b>{0}</b>", itemName);
if (includeModifyCommands) {
if (canRename)
ciset.CommandInfos.Add (GettextCatalog.GetString ("_Encapsulate Field..."), new RefactoryOperation (refactorer.EncapsulateField));
AddRefactoryMenuForClass (ctx, pinfo, ciset, ((IField) item).ReturnType.FullName);
}
} else if (item is IProperty) {
if (((IProperty)item).IsIndexer) {
txt = GettextCatalog.GetString ("Indexer <b>{0}</b>", itemName);
} else {
txt = GettextCatalog.GetString ("Property <b>{0}</b>", itemName);
}
AddRefactoryMenuForClass (ctx, pinfo, ciset, ((IProperty) item).ReturnType.FullName);
} else if (item is IEvent) {
txt = GettextCatalog.GetString ("Event <b>{0}</b>", itemName);
} else if (item is IMethod) {
IMethod method = item as IMethod;
if (method.IsConstructor) {
txt = GettextCatalog.GetString ("Constructor <b>{0}</b>", EscapeName (method.DeclaringType.Name));
} else {
txt = GettextCatalog.GetString ("Method <b>{0}</b>", itemName);
if (method.IsOverride)
ciset.CommandInfos.Add (GettextCatalog.GetString ("Go to _base"), new RefactoryOperation (refactorer.GoToBase));
}
} else if (item is IParameter) {
txt = GettextCatalog.GetString ("Parameter <b>{0}</b>", itemName);
AddRefactoryMenuForClass (ctx, pinfo, ciset, ((IParameter) item).ReturnType.FullName);
} else if (item is LocalVariable) {
LocalVariable var = (LocalVariable) item;
AddRefactoryMenuForClass (ctx, pinfo, ciset, var.ReturnType.FullName);
txt = GettextCatalog.GetString ("Variable <b>{0}</b>", itemName);
} else {
return null;
}
ciset.Text = txt;
ciset.UseMarkup = true;
return ciset;
}
*/
public static bool ContainsAbstractMembers (IType cls)
{
if (cls == null)
return false;
return cls.GetMembers ().Any (m => m.IsAbstract);
}
示例7: ResolveInterfaceMembers
void ResolveInterfaceMembers(ClassDefinition node,
TypeReference baseTypeRef,
IType baseType)
{
foreach (IType entity in baseType.GetInterfaces())
{
ResolveInterfaceMembers(node, baseTypeRef, entity);
}
foreach (IMember entity in baseType.GetMembers())
{
ResolveAbstractMember(node, baseTypeRef, entity);
}
}
示例8: ResolveAbstractMembers
void ResolveAbstractMembers(ClassDefinition node,
TypeReference baseTypeRef,
IType baseType)
{
foreach (IEntity member in baseType.GetMembers())
{
switch (member.EntityType)
{
case EntityType.Method:
{
IMethod method = (IMethod)member;
if (method.IsAbstract)
{
ResolveAbstractMethod(node, baseTypeRef, method);
}
break;
}
case EntityType.Property:
{
IProperty property = (IProperty)member;
if (IsAbstractAccessor(property.GetGetMethod()) ||
IsAbstractAccessor(property.GetSetMethod()))
{
ResolveClassAbstractProperty(node, baseTypeRef, property);
}
break;
}
case EntityType.Event:
{
IEvent ev = (IEvent)member;
if (ev.IsAbstract)
{
ResolveAbstractEvent(node, baseTypeRef, ev);
}
break;
}
}
}
}
示例9: GetDesignerMembers
/// <summary>Filters out members whose names conflict with existing accessible members</summary>
/// <param name="members">Full list of CodeBehind members</param>
/// <param name="cls">The class to which these members' partial class will be added.</param>
/// <param name="designerFile">Members in this file will be ignored.</param>
/// <param name="resolveDom">The ITypeResolveContext to use for resolving base types.</param>
/// <param name="internalDom">The ITypeResolveContext to use for checking whether members are accessible as internal.</param>
/// <returns>The filtered list of non-conflicting members.</returns>
// TODO: check compatibilty with existing members
public static IEnumerable<CodeBehindMember> GetDesignerMembers (
IEnumerable<CodeBehindMember> members, IType cls, string designerFile)
{
var existingMembers = new HashSet<string> ();
while (cls != null) {
if (cls.GetDefinition () == null)
break;
foreach (var member in cls.GetMembers ()) {
if (member.Accessibility == Accessibility.Private || member.Accessibility == Accessibility.Internal)
continue;
if (member.Region.FileName == designerFile)
continue;
existingMembers.Add (member.Name);
}
if (!cls.DirectBaseTypes.Any (t => t.Kind != TypeKind.Interface))
break;
cls = cls.DirectBaseTypes.First(t => t.Kind != TypeKind.Interface);
}
return members.Where (m => !existingMembers.Contains (m.Name));
}
示例10: FindConversionOperator
private IMethod FindConversionOperator(string name, IType fromType, IType toType)
{
while (fromType != ObjectType)
{
IMethod method = FindConversionOperator(name, fromType, toType, fromType.GetMembers());
if (null != method) return method;
method = FindConversionOperator(name, fromType, toType, toType.GetMembers());
if (null != method) return method;
method = FindConversionOperator(name, fromType, toType, FindExtension(fromType, name));
if (null != method) return method;
fromType = fromType.BaseType;
if (null == fromType) break;
}
return null;
}
示例11: IsImplemented
public static bool IsImplemented (IType type, IMember protocolMember)
{
foreach (var m in type.GetMembers (m => m.SymbolKind == protocolMember.SymbolKind && m.Name == protocolMember.Name)) {
var p = m as IProperty;
if (p != null) {
if (p.CanGet && ((IProperty)protocolMember).CanGet && GetProtocol (p.Getter) == GetProtocol (((IProperty)protocolMember).Getter))
return true;
if (p.CanSet && ((IProperty)protocolMember).CanSet && GetProtocol (p.Setter) == GetProtocol (((IProperty)protocolMember).Setter))
return true;
continue;
}
if (GetProtocol (m) == GetProtocol (protocolMember))
return true;
}
return false;
}
示例12: ReadNamedArg
public KeyValuePair<IMember, ResolveResult> ReadNamedArg(IType attributeType)
{
SymbolKind memberType;
var b = ReadByte();
switch (b) {
case 0x53:
memberType = SymbolKind.Field;
break;
case 0x54:
memberType = SymbolKind.Property;
break;
default:
throw new NotSupportedException(string.Format("Custom member type 0x{0:x} is not supported.", b));
}
IType type = ReadCustomAttributeFieldOrPropType();
string name = ReadSerString();
ResolveResult val = ReadFixedArg(type);
IMember member = null;
// Use last matching member, as GetMembers() returns members from base types first.
foreach (IMember m in attributeType.GetMembers(m => m.SymbolKind == memberType && m.Name == name)) {
if (m.ReturnType.Equals(type))
member = m;
}
return new KeyValuePair<IMember, ResolveResult>(member, val);
}
示例13: ResolveMember
public static IEntity ResolveMember(IType type, string name, EntityType elementType)
{
foreach (IEntity member in type.GetMembers())
{
if (elementType == member.EntityType && name == member.Name)
{
return member;
}
}
return null;
}
示例14: PopulateTreeView
private void PopulateTreeView(IType type)
{
TreeStore store = (TreeStore)this.treeviewMembers.Model;
store.Clear ();
foreach (IMember member in type.GetMembers((m) => true, GetMemberOptions.ReturnMemberDefinitions | GetMemberOptions.IgnoreInheritedMembers)) {
#if MD_4_0 || MD_4_2
bool isMethod = (member.EntityType == EntityType.Method);
bool isProperty = (member.EntityType == EntityType.Property);
#endif
#if MD_5_0
bool isMethod = (member.SymbolKind == SymbolKind.Method);
bool isProperty = (member.SymbolKind == SymbolKind.Property);
#endif
if (isMethod) {
if (member.Name.StartsWith("get_")) {
continue;
}
if (member.Name.StartsWith("set_")) {
continue;
}
#if MD_4_0 || MD_4_2
store.AppendValues (false, ImageService.GetPixbuf (MonoDevelop.Ide.Gui.Stock.Method, IconSize.Menu), member.Name, member);
#endif
#if MD_5_0
store.AppendValues(false, ImageService.GetImage(MonoDevelop.Ide.Gui.Stock.Method, IconSize.Menu), member.Name, member);
#endif
}
if (isProperty) {
#if MD_4_0 || MD_4_2
store.AppendValues (false, ImageService.GetPixbuf (MonoDevelop.Ide.Gui.Stock.Property, IconSize.Menu), member.Name, member);
#endif
#if MD_5_0
store.AppendValues (false, ImageService.GetImage (MonoDevelop.Ide.Gui.Stock.Property, IconSize.Menu), member.Name, member);
#endif
}
}
}
示例15: GetMember
/// <summary>
/// Gets the member of the specified type with the specified name, assuming there is only one.
/// </summary>
private IEntity GetMember(IType type, string name, EntityType entityType)
{
// For external types we can use GetMethod or GetProperty to optimize things a little
ExternalType external = type as ExternalType;
if (external != null)
{
if (entityType == EntityType.Property)
{
return TypeSystemServices.Map(
((ExternalType)type).ActualType.GetProperty(name));
}
else if (entityType == EntityType.Method)
{
return TypeSystemServices.Map(
((ExternalType)type).ActualType.GetMethod(name));
}
}
// For constructed types which aren't external we can use the GenericMapping to
// (maybe) optimize things a little
if (type.ConstructedInfo != null)
{
return ((GenericConstructedType)type).GenericMapping.Map(
GetMember(type.ConstructedInfo.GenericDefinition, name, entityType));
}
// For other cases we just scan through the members collection
return Array.Find<IEntity>(
type.GetMembers(),
delegate(IEntity e) {
return entityType == e.EntityType && e.Name == name;
});
}