本文整理汇总了C#中ITypeDefinition.GetAllBaseTypeDefinitions方法的典型用法代码示例。如果您正苦于以下问题:C# ITypeDefinition.GetAllBaseTypeDefinitions方法的具体用法?C# ITypeDefinition.GetAllBaseTypeDefinitions怎么用?C# ITypeDefinition.GetAllBaseTypeDefinitions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITypeDefinition
的用法示例。
在下文中一共展示了ITypeDefinition.GetAllBaseTypeDefinitions方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CollectMembersToImplement
public static List<IMember> CollectMembersToImplement(ITypeDefinition implementingType, IType abstractType)
{
// var def = abstractType.GetDefinition();
var toImplement = new List<IMember>();
bool alreadyImplemented;
// Stub out non-implemented events defined by @iface
foreach (var ev in abstractType.GetEvents (e => !e.IsSynthetic && e.IsAbstract)) {
alreadyImplemented = implementingType.GetAllBaseTypeDefinitions().Any(
x => x.Kind != TypeKind.Interface && x.Events.Any (y => y.Name == ev.Name)
);
if (!alreadyImplemented)
toImplement.Add(ev);
}
// Stub out non-implemented methods defined by @iface
foreach (var method in abstractType.GetMethods (d => !d.IsSynthetic && d.IsAbstract)) {
alreadyImplemented = false;
var allBaseTypes = method.DeclaringType.GetAllBaseTypes().ToList ();
foreach (var cmet in implementingType.GetMethods (d => !d.IsAbstract && d.Name == method.Name)) {
if (allBaseTypes.Contains(cmet.DeclaringType))
continue;
if (ImplementInterfaceAction.CompareMethods(method, cmet)) {
alreadyImplemented = true;
break;
}
}
if (!alreadyImplemented)
toImplement.Add(method);
}
// Stub out non-implemented properties defined by @iface
foreach (var prop in abstractType.GetProperties (p => !p.IsSynthetic && p.IsAbstract)) {
alreadyImplemented = false;
foreach (var t in implementingType.GetAllBaseTypeDefinitions ()) {
if (t.Kind == TypeKind.Interface)
continue;
foreach (IProperty cprop in t.Properties) {
if (!cprop.IsAbstract && cprop.Name == prop.Name) {
alreadyImplemented = true;
}
}
}
if (!alreadyImplemented)
toImplement.Add(prop);
}
return toImplement;
}
示例2: MakePopupWithBaseClasses
static ContextActionsPopup MakePopupWithBaseClasses(ITypeDefinition @class)
{
var baseClassList = @class.GetAllBaseTypeDefinitions().Where(baseClass => baseClass != @class).ToList();
var popupViewModel = new ContextActionsPopupViewModel();
popupViewModel.Title = MenuService.ConvertLabel(StringParser.Parse(
"${res:SharpDevelop.Refactoring.BaseClassesOf}", new StringTagPair("Name", @class.Name)));
popupViewModel.Actions = BuildListViewModel(baseClassList);
return new ContextActionsPopup { Actions = popupViewModel };
}
示例3: CollectMembersToImplement
public static List<Tuple<IMember, bool>> CollectMembersToImplement(ITypeDefinition implementingType, IType interfaceType, bool explicitly)
{
var def = interfaceType.GetDefinition();
List<Tuple<IMember, bool>> toImplement = new List<Tuple<IMember, bool>>();
bool alreadyImplemented;
// Stub out non-implemented events defined by @iface
foreach (var ev in interfaceType.GetEvents (e => !e.IsSynthetic && e.DeclaringTypeDefinition.ReflectionName == def.ReflectionName)) {
bool needsExplicitly = explicitly;
alreadyImplemented = implementingType.GetAllBaseTypeDefinitions().Any(
x => x.Kind != TypeKind.Interface && x.Events.Any (y => y.Name == ev.Name)
);
if (!alreadyImplemented)
toImplement.Add(new Tuple<IMember, bool>(ev, needsExplicitly));
}
// Stub out non-implemented methods defined by @iface
foreach (var method in interfaceType.GetMethods (d => !d.IsSynthetic && d.DeclaringTypeDefinition.ReflectionName == def.ReflectionName)) {
bool needsExplicitly = explicitly;
alreadyImplemented = false;
foreach (var cmet in implementingType.GetMethods ()) {
if (CompareMethods(method, cmet)) {
if (!needsExplicitly && !cmet.ReturnType.Equals(method.ReturnType))
needsExplicitly = true;
else
alreadyImplemented |= !needsExplicitly /*|| cmet.InterfaceImplementations.Any (impl => impl.InterfaceType.Equals (interfaceType))*/;
}
}
if (!alreadyImplemented)
toImplement.Add(new Tuple<IMember, bool>(method, needsExplicitly));
}
// Stub out non-implemented properties defined by @iface
foreach (var prop in interfaceType.GetProperties (p => !p.IsSynthetic && p.DeclaringTypeDefinition.ReflectionName == def.ReflectionName)) {
bool needsExplicitly = explicitly;
alreadyImplemented = false;
foreach (var t in implementingType.GetAllBaseTypeDefinitions ()) {
if (t.Kind == TypeKind.Interface)
continue;
foreach (IProperty cprop in t.Properties) {
if (cprop.Name == prop.Name) {
if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType))
needsExplicitly = true;
else
alreadyImplemented |= !needsExplicitly/* || cprop.InterfaceImplementations.Any (impl => impl.InterfaceType.Resolve (ctx).Equals (interfaceType))*/;
}
}
}
if (!alreadyImplemented)
toImplement.Add(new Tuple<IMember, bool>(prop, needsExplicitly));
}
return toImplement;
}
示例4: GenerateCode
protected override string GenerateCode(ITypeDefinition currentClass)
{
bool implementInterface = this.implementInterface.IsChecked == true;
bool hasOnPropertyChanged = HasOnPropertyChanged(currentClass);
bool useEventArgs = false;
AstNode insertionAnchorElement = refactoringContext.GetNode();
if ((insertionAnchorElement == null) || !(insertionAnchorElement.Parent is TypeDeclaration)) {
return null;
}
NewLineNode newLineNode = insertionAnchorElement as NewLineNode;
while (insertionAnchorElement.PrevSibling is NewLineNode)
insertionAnchorElement = insertionAnchorElement.PrevSibling ?? insertionAnchorElement;
using (Script script = refactoringContext.StartScript()) {
TypeDeclaration currentClassDeclaration = insertionAnchorElement.Parent as TypeDeclaration;
if (implementInterface && !currentClass.IsStatic) {
if (!hasOnPropertyChanged) {
var nodes = new List<AstNode>();
if (!currentClass.GetAllBaseTypeDefinitions().Any(bt => bt.FullName == "System.ComponentModel.INotifyPropertyChanged")) {
AstNode nodeBeforeClassBlock = currentClassDeclaration.LBraceToken;
if (nodeBeforeClassBlock.PrevSibling is NewLineNode) {
// There's a new line before the brace, insert before it!
nodeBeforeClassBlock = nodeBeforeClassBlock.PrevSibling;
}
int insertion = editor.Document.GetOffset(nodeBeforeClassBlock.StartLocation);
AstType interfaceTypeNode = refactoringContext.CreateShortType("System.ComponentModel", "INotifyPropertyChanged", 0);
var directBaseTypes = currentClass.DirectBaseTypes.Where(t => t.FullName != "System.Object");
if (currentClassDeclaration.BaseTypes.Count > 0) {
script.InsertText(insertion, ", " + interfaceTypeNode + " ");
} else {
script.InsertText(insertion, " : " + interfaceTypeNode + " ");
}
}
var rt = new GetClassTypeReference("System.ComponentModel", "INotifyPropertyChanged", 0);
var rtResolved = rt.Resolve(refactoringContext.Compilation);
var ev = rtResolved.GetEvents().First(e => e.Name == "PropertyChanged");
EventDeclaration propertyChangedEvent = new EventDeclaration();
propertyChangedEvent.Variables.Add(new VariableInitializer(ev.Name));
propertyChangedEvent.Modifiers = Modifiers.Public;
propertyChangedEvent.ReturnType = refactoringContext.CreateShortType(ev.ReturnType);
nodes.Add(propertyChangedEvent);
MethodDeclaration onEvent = CreateOnEventMethod(ev, currentClass);
nodes.Add(onEvent);
foreach (var node in nodes) {
script.InsertAfter(insertionAnchorElement, node);
AppendNewLine(script, insertionAnchorElement, newLineNode);
}
useEventArgs = false;
} else {
useEventArgs = currentClass.GetMethods().First(m => m.Name == "OnPropertyChanged").Parameters[0].Type.FullName != "System.String";
}
}
foreach (FieldWrapper field in fields.Where(f => f.IsIncluded)) {
var prop = CreateProperty(field.Field, true, field.AddSetter);
if (!field.Field.IsStatic && !currentClass.IsStatic && field.AddSetter && implementInterface) {
var invocation = new ExpressionStatement(CreateInvocation(field.PropertyName, useEventArgs));
var assignment = prop.Setter.Body.Children.ElementAt(0) as Statement;
prop.Setter.Body = new BlockStatement();
BlockStatement elseBlock = new BlockStatement();
elseBlock.Add(assignment.Clone());
elseBlock.Add(invocation);
prop.Setter.Body.Add(
new IfElseStatement(
new BinaryOperatorExpression(new IdentifierExpression(field.MemberName), BinaryOperatorType.InEquality, new IdentifierExpression("value")),
elseBlock
)
);
}
script.InsertAfter(insertionAnchorElement, prop);
AppendNewLine(script, insertionAnchorElement, newLineNode);
}
}
return null;
}
示例5: IsSerializable
public static bool IsSerializable(ITypeDefinition type) {
return AttributeReader.HasAttribute<SerializableAttribute>(type) || (type.GetAllBaseTypeDefinitions().Any(td => td.FullName == "System.Record") && type.FullName != "System.Record");
}
示例6: ProcessTypeMembers
private void ProcessTypeMembers(ITypeDefinition typeDefinition) {
if (typeDefinition.Kind == TypeKind.Delegate)
return;
var baseMembersByType = typeDefinition.GetAllBaseTypeDefinitions().Where(x => x != typeDefinition).Select(t => new { Type = t, MemberNames = GetInstanceMemberNames(t) }).ToList();
for (int i = 0; i < baseMembersByType.Count; i++) {
var b = baseMembersByType[i];
for (int j = i + 1; j < baseMembersByType.Count; j++) {
var b2 = baseMembersByType[j];
if (!b.Type.GetAllBaseTypeDefinitions().Contains(b2.Type) && !b2.Type.GetAllBaseTypeDefinitions().Contains(b.Type)) {
foreach (var dup in b.MemberNames.Where(b2.MemberNames.Contains)) {
Message(Messages._7018, typeDefinition, b.Type.FullName, b2.Type.FullName, dup);
}
}
}
}
var instanceMembers = baseMembersByType.SelectMany(m => m.MemberNames).Distinct().ToDictionary(m => m, m => false);
if (_instanceMemberNamesByType.ContainsKey(typeDefinition))
_instanceMemberNamesByType[typeDefinition].ForEach(s => instanceMembers[s] = true);
_unusableInstanceFieldNames.ForEach(n => instanceMembers[n] = false);
var staticMembers = _unusableStaticFieldNames.ToDictionary(n => n, n => false);
if (_staticMemberNamesByType.ContainsKey(typeDefinition))
_staticMemberNamesByType[typeDefinition].ForEach(s => staticMembers[s] = true);
var membersByName = from m in typeDefinition.GetMembers(options: GetMemberOptions.IgnoreInheritedMembers)
where !_ignoredMembers.Contains(m)
let name = DeterminePreferredMemberName(m)
group new { m, name } by name.Item1 into g
select new { Name = g.Key, Members = g.Select(x => new { Member = x.m, NameSpecified = x.name.Item2 }).ToList() };
bool isSerializable = GetTypeSemanticsInternal(typeDefinition).IsSerializable;
foreach (var current in membersByName) {
foreach (var m in current.Members.OrderByDescending(x => x.NameSpecified).ThenBy(x => x.Member, MemberOrderer.Instance)) {
if (m.Member is IMethod) {
var method = (IMethod)m.Member;
if (method.IsConstructor) {
ProcessConstructor(method, current.Name, m.NameSpecified, staticMembers);
}
else {
ProcessMethod(method, current.Name, m.NameSpecified, m.Member.IsStatic || isSerializable ? staticMembers : instanceMembers);
}
}
else if (m.Member is IProperty) {
var p = (IProperty)m.Member;
ProcessProperty(p, current.Name, m.NameSpecified, m.Member.IsStatic ? staticMembers : instanceMembers);
var ps = GetPropertySemantics(p);
if (p.CanGet)
_methodSemantics[p.Getter] = ps.Type == PropertyScriptSemantics.ImplType.GetAndSetMethods ? ps.GetMethod : MethodScriptSemantics.NotUsableFromScript();
if (p.CanSet)
_methodSemantics[p.Setter] = ps.Type == PropertyScriptSemantics.ImplType.GetAndSetMethods ? ps.SetMethod : MethodScriptSemantics.NotUsableFromScript();
}
else if (m.Member is IField) {
ProcessField((IField)m.Member, current.Name, m.NameSpecified, m.Member.IsStatic ? staticMembers : instanceMembers);
}
else if (m.Member is IEvent) {
var e = (IEvent)m.Member;
ProcessEvent((IEvent)m.Member, current.Name, m.NameSpecified, m.Member.IsStatic ? staticMembers : instanceMembers);
var es = GetEventSemantics(e);
_methodSemantics[e.AddAccessor] = es.Type == EventScriptSemantics.ImplType.AddAndRemoveMethods ? es.AddMethod : MethodScriptSemantics.NotUsableFromScript();
_methodSemantics[e.RemoveAccessor] = es.Type == EventScriptSemantics.ImplType.AddAndRemoveMethods ? es.RemoveMethod : MethodScriptSemantics.NotUsableFromScript();
}
}
}
_instanceMemberNamesByType[typeDefinition] = new HashSet<string>(instanceMembers.Where(kvp => kvp.Value).Select(kvp => kvp.Key));
_staticMemberNamesByType[typeDefinition] = new HashSet<string>(staticMembers.Where(kvp => kvp.Value).Select(kvp => kvp.Key));
}
示例7: UpdateTypeMembers
void UpdateTypeMembers (TypeSystemService.ProjectContentWrapper dom, NSObjectTypeInfo info, ITypeDefinition type)
{
info.Actions.Clear ();
info.Outlets.Clear ();
foreach (var prop in type.Properties) {
foreach (var att in prop.Attributes) {
var attType = att.AttributeType;
bool isIBOutlet = attType.Equals (Resolve (dom, iboutletAttType));
if (!isIBOutlet) {
if (!attType.Equals (Resolve (dom, connectAttType)))
continue;
}
string name = null;
var posArgs = att.PositionalArguments;
if (posArgs.Count == 1)
name = posArgs [0].ConstantValue as string;
if (string.IsNullOrEmpty (name))
name = prop.Name;
// HACK: Work around bug #1586 in the least obtrusive way possible. Strip out any outlet
// with the name 'view' on subclasses of MonoTouch.UIKit.UIViewController to avoid
// conflicts with the view property mapped there
if (name == "view") {
if (type.GetAllBaseTypeDefinitions ().Any (p => p.ReflectionName == "MonoTouch.UIKit.UIViewController"))
continue;
}
var ol = new IBOutlet (name, prop.Name, null, prop.ReturnType.ReflectionName);
if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (prop.Region.FileName))
ol.IsDesigner = true;
info.Outlets.Add (ol);
break;
}
}
foreach (var meth in type.Methods) {
foreach (var att in meth.Attributes) {
var attType = att.AttributeType;
bool isIBAction = attType.Equals (Resolve (dom, ibactionAttType));
if (!isIBAction) {
if (!attType.Equals (Resolve (dom, exportAttType)))
continue;
}
bool isDesigner = MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (
meth.DeclaringTypeDefinition.Region.FileName);
//only support Export from old designer files, user code must be IBAction
if (!isDesigner && !isIBAction)
continue;
string[] name = null;
var posArgs = att.PositionalArguments;
if (posArgs.Count == 1 || posArgs.Count == 2) {
var n = posArgs [0].ConstantValue as string;
if (!string.IsNullOrEmpty (n))
name = n.Split (colonChar);
}
var action = new IBAction (name != null ? name [0] : meth.Name, meth.Name);
int i = 1;
foreach (var param in meth.Parameters) {
string label = name != null && i < name.Length ? name [i] : null;
if (label != null && label.Length == 0)
label = null;
action.Parameters.Add (new IBActionParameter (label, param.Name, null, param.Type.ReflectionName));
}
if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (meth.Region.FileName))
action.IsDesigner = true;
info.Actions.Add (action);
break;
}
}
}
示例8: CollectMembersToImplement
public static List<Tuple<IMember, bool>> CollectMembersToImplement(ITypeDefinition implementingType, IType interfaceType, bool explicitly, out bool interfaceMissing)
{
//var def = interfaceType.GetDefinition();
List<Tuple<IMember, bool>> toImplement = new List<Tuple<IMember, bool>>();
bool alreadyImplemented;
interfaceMissing = true;
// Stub out non-implemented events defined by @iface
foreach (var evGroup in interfaceType.GetEvents (e => !e.IsSynthetic).GroupBy (m => m.DeclaringType).Reverse ())
foreach (var ev in evGroup) {
if (ev.DeclaringType.Kind != TypeKind.Interface)
continue;
bool needsExplicitly = explicitly;
alreadyImplemented = implementingType.GetMembers().Any(m => m.ImplementedInterfaceMembers.Any(im => IsImplementation (im, ev)));
if (!alreadyImplemented) {
toImplement.Add(new Tuple<IMember, bool>(ev, needsExplicitly));
} else {
interfaceMissing = false;
}
}
// Stub out non-implemented methods defined by @iface
foreach (var methodGroup in interfaceType.GetMethods (d => !d.IsSynthetic).GroupBy (m => m.DeclaringType).Reverse ())
foreach (var method in methodGroup) {
if (method.DeclaringType.Kind != TypeKind.Interface)
continue;
bool needsExplicitly = explicitly;
alreadyImplemented = false;
foreach (var cmet in implementingType.GetMethods ()) {
alreadyImplemented |= cmet.ImplementedInterfaceMembers.Any(m => IsImplementation (m, method));
if (CompareMembers(method, cmet)) {
if (!needsExplicitly && !cmet.ReturnType.Equals(method.ReturnType))
needsExplicitly = true;
else
alreadyImplemented |= !needsExplicitly /*|| cmet.InterfaceImplementations.Any (impl => impl.InterfaceType.Equals (interfaceType))*/;
}
}
if (toImplement.Where(t => t.Item1 is IMethod).Any(t => CompareMembers(method, (IMethod)t.Item1)))
needsExplicitly = true;
if (!alreadyImplemented) {
toImplement.Add(new Tuple<IMember, bool>(method, needsExplicitly));
} else {
interfaceMissing = false;
}
}
// Stub out non-implemented properties defined by @iface
foreach (var propGroup in interfaceType.GetProperties (p => !p.IsSynthetic).GroupBy (m => m.DeclaringType).Reverse ())
foreach (var prop in propGroup) {
if (prop.DeclaringType.Kind != TypeKind.Interface)
continue;
bool needsExplicitly = explicitly;
alreadyImplemented = implementingType.GetMembers().Any(m => m.ImplementedInterfaceMembers.Any(im => IsImplementation (im, prop)));
foreach (var t in implementingType.GetAllBaseTypeDefinitions ()) {
if (t.Kind == TypeKind.Interface) {
foreach (var cprop in t.Properties) {
if (cprop.Name == prop.Name && cprop.IsShadowing) {
if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType))
needsExplicitly = true;
}
}
continue;
}
foreach (var cprop in t.Properties) {
if (cprop.Name == prop.Name) {
if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType))
needsExplicitly = true;
else
alreadyImplemented |= !needsExplicitly/* || cprop.InterfaceImplementations.Any (impl => impl.InterfaceType.Resolve (ctx).Equals (interfaceType))*/;
}
}
}
if (!alreadyImplemented) {
toImplement.Add(new Tuple<IMember, bool>(prop, needsExplicitly));
} else {
interfaceMissing = false;
}
}
return toImplement;
}
示例9: IsSerializable
public static bool IsSerializable(ITypeDefinition type, IAttributeStore attributeStore) {
return attributeStore.AttributesFor(type).HasAttribute<ScriptSerializableAttribute>() || (type.GetAllBaseTypeDefinitions().Any(td => td.FullName == "System.Record") && type.FullName != "System.Record");
}