本文整理汇总了C#中DelegateDeclaration.AddAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# DelegateDeclaration.AddAnnotation方法的具体用法?C# DelegateDeclaration.AddAnnotation怎么用?C# DelegateDeclaration.AddAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DelegateDeclaration
的用法示例。
在下文中一共展示了DelegateDeclaration.AddAnnotation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateType
/// <summary>
/// Creates the AST for a type definition.
/// </summary>
/// <param name="typeDef"></param>
/// <returns>TypeDeclaration or DelegateDeclaration.</returns>
public AttributedNode CreateType(TypeDefinition typeDef)
{
// create CSharp code mappings - used for debugger
if (this.CodeMappings == null)
this.CodeMappings = new Tuple<string, List<MemberMapping>>(typeDef.FullName, new List<MemberMapping>());
// create type
TypeDefinition oldCurrentType = context.CurrentType;
context.CurrentType = typeDef;
TypeDeclaration astType = new TypeDeclaration();
ConvertAttributes(astType, typeDef);
astType.AddAnnotation(typeDef);
astType.Modifiers = ConvertModifiers(typeDef);
astType.Name = CleanName(typeDef.Name);
if (typeDef.IsEnum) { // NB: Enum is value type
astType.ClassType = ClassType.Enum;
astType.Modifiers &= ~Modifiers.Sealed;
} else if (typeDef.IsValueType) {
astType.ClassType = ClassType.Struct;
astType.Modifiers &= ~Modifiers.Sealed;
} else if (typeDef.IsInterface) {
astType.ClassType = ClassType.Interface;
astType.Modifiers &= ~Modifiers.Abstract;
} else {
astType.ClassType = ClassType.Class;
}
IEnumerable<GenericParameter> genericParameters = typeDef.GenericParameters;
if (typeDef.DeclaringType != null && typeDef.DeclaringType.HasGenericParameters)
genericParameters = genericParameters.Skip(typeDef.DeclaringType.GenericParameters.Count);
astType.TypeParameters.AddRange(MakeTypeParameters(genericParameters));
astType.Constraints.AddRange(MakeConstraints(genericParameters));
// Nested types
foreach (TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
if (MemberIsHidden(nestedTypeDef, context.Settings))
continue;
astType.AddChild(CreateType(nestedTypeDef), TypeDeclaration.MemberRole);
}
AttributedNode result = astType;
if (typeDef.IsEnum) {
long expectedEnumMemberValue = 0;
bool forcePrintingInitializers = IsFlagsEnum(typeDef);
foreach (FieldDefinition field in typeDef.Fields) {
if (field.IsRuntimeSpecialName) {
// the value__ field
if (field.FieldType != typeDef.Module.TypeSystem.Int32) {
astType.AddChild(ConvertType(field.FieldType), TypeDeclaration.BaseTypeRole);
}
} else {
EnumMemberDeclaration enumMember = new EnumMemberDeclaration();
enumMember.Name = CleanName(field.Name);
long memberValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.Constant, false);
if (forcePrintingInitializers || memberValue != expectedEnumMemberValue) {
enumMember.AddChild(new PrimitiveExpression(field.Constant), EnumMemberDeclaration.InitializerRole);
}
expectedEnumMemberValue = memberValue + 1;
astType.AddChild(enumMember, TypeDeclaration.MemberRole);
}
}
} else if (typeDef.BaseType != null && typeDef.BaseType.FullName == "System.MulticastDelegate") {
DelegateDeclaration dd = new DelegateDeclaration();
dd.Modifiers = astType.Modifiers & ~Modifiers.Sealed;
dd.Name = astType.Name;
dd.AddAnnotation(typeDef);
astType.Attributes.MoveTo(dd.Attributes);
astType.TypeParameters.MoveTo(dd.TypeParameters);
astType.Constraints.MoveTo(dd.Constraints);
foreach (var m in typeDef.Methods) {
if (m.Name == "Invoke") {
dd.ReturnType = ConvertType(m.ReturnType, m.MethodReturnType);
dd.Parameters.AddRange(MakeParameters(m));
ConvertAttributes(dd, m.MethodReturnType, m.Module);
}
}
result = dd;
} else {
// Base type
if (typeDef.BaseType != null && !typeDef.IsValueType && typeDef.BaseType.FullName != "System.Object") {
astType.AddChild(ConvertType(typeDef.BaseType), TypeDeclaration.BaseTypeRole);
}
foreach (var i in typeDef.Interfaces)
astType.AddChild(ConvertType(i), TypeDeclaration.BaseTypeRole);
AddTypeMembers(astType, typeDef);
if (astType.Members.OfType<IndexerDeclaration>().Any(idx => idx.PrivateImplementationType.IsNull)) {
// Remove the [DefaultMember] attribute if the class contains indexers
foreach (AttributeSection section in astType.Attributes) {
foreach (Ast.Attribute attr in section.Attributes) {
TypeReference tr = attr.Type.Annotation<TypeReference>();
if (tr != null && tr.Name == "DefaultMemberAttribute" && tr.Namespace == "System.Reflection") {
attr.Remove();
//.........这里部分代码省略.........
示例2: ConvertDelegate
DelegateDeclaration ConvertDelegate(IMethod invokeMethod, Modifiers modifiers)
{
ITypeDefinition d = invokeMethod.DeclaringTypeDefinition;
DelegateDeclaration decl = new DelegateDeclaration();
decl.Modifiers = modifiers & ~Modifiers.Sealed;
if (ShowAttributes) {
decl.Attributes.AddRange (d.Attributes.Select (a => new AttributeSection (ConvertAttribute (a))));
decl.Attributes.AddRange (invokeMethod.ReturnTypeAttributes.Select ((a) => new AttributeSection (ConvertAttribute (a)) {
AttributeTarget = "return"
}));
}
if (AddResolveResultAnnotations) {
decl.AddAnnotation(new TypeResolveResult(d));
}
decl.ReturnType = ConvertType(invokeMethod.ReturnType);
decl.Name = d.Name;
int outerTypeParameterCount = (d.DeclaringTypeDefinition == null) ? 0 : d.DeclaringTypeDefinition.TypeParameterCount;
if (this.ShowTypeParameters) {
foreach (ITypeParameter tp in d.TypeParameters.Skip(outerTypeParameterCount)) {
decl.TypeParameters.Add(ConvertTypeParameter(tp));
}
}
foreach (IParameter p in invokeMethod.Parameters) {
decl.Parameters.Add(ConvertParameter(p));
}
if (this.ShowTypeParameters && this.ShowTypeParameterConstraints) {
foreach (ITypeParameter tp in d.TypeParameters.Skip(outerTypeParameterCount)) {
var constraint = ConvertTypeParameterConstraint(tp);
if (constraint != null)
decl.Constraints.Add(constraint);
}
}
return decl;
}
示例3: CreateType
/// <summary>
/// Creates the AST for a type definition.
/// </summary>
/// <param name="typeDef"></param>
/// <returns>TypeDeclaration or DelegateDeclaration.</returns>
public AttributedNode CreateType(TypeDefinition typeDef)
{
TypeDefinition oldCurrentType = context.CurrentType;
context.CurrentType = typeDef;
TypeDeclaration astType = new TypeDeclaration();
ConvertAttributes(astType, typeDef);
astType.AddAnnotation(typeDef);
astType.Modifiers = ConvertModifiers(typeDef);
astType.Name = CleanName(typeDef.Name);
if (typeDef.IsEnum) { // NB: Enum is value type
astType.ClassType = ClassType.Enum;
astType.Modifiers &= ~Modifiers.Sealed;
} else if (typeDef.IsValueType) {
astType.ClassType = ClassType.Struct;
astType.Modifiers &= ~Modifiers.Sealed;
} else if (typeDef.IsInterface) {
astType.ClassType = ClassType.Interface;
astType.Modifiers &= ~Modifiers.Abstract;
} else {
astType.ClassType = ClassType.Class;
}
IEnumerable<GenericParameter> genericParameters = typeDef.GenericParameters;
if (typeDef.DeclaringType != null && typeDef.DeclaringType.HasGenericParameters)
genericParameters = genericParameters.Skip(typeDef.DeclaringType.GenericParameters.Count);
astType.TypeParameters.AddRange(MakeTypeParameters(genericParameters));
astType.Constraints.AddRange(MakeConstraints(genericParameters));
// Nested types
foreach (TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
if (MemberIsHidden(nestedTypeDef, context.Settings))
continue;
astType.AddChild(CreateType(nestedTypeDef), TypeDeclaration.MemberRole);
}
AttributedNode result = astType;
if (typeDef.IsEnum) {
long expectedEnumMemberValue = 0;
bool forcePrintingInitializers = IsFlagsEnum(typeDef);
foreach (FieldDefinition field in typeDef.Fields) {
if (field.IsRuntimeSpecialName) {
// the value__ field
if (field.FieldType != typeDef.Module.TypeSystem.Int32) {
astType.AddChild(ConvertType(field.FieldType), TypeDeclaration.BaseTypeRole);
}
} else {
EnumMemberDeclaration enumMember = new EnumMemberDeclaration();
enumMember.Name = CleanName(field.Name);
long memberValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.Constant, false);
if (forcePrintingInitializers || memberValue != expectedEnumMemberValue) {
enumMember.AddChild(new PrimitiveExpression(field.Constant), EnumMemberDeclaration.InitializerRole);
}
expectedEnumMemberValue = memberValue + 1;
astType.AddChild(enumMember, TypeDeclaration.MemberRole);
}
}
} else if (typeDef.BaseType != null && typeDef.BaseType.FullName == "System.MulticastDelegate") {
DelegateDeclaration dd = new DelegateDeclaration();
dd.Modifiers = astType.Modifiers & ~Modifiers.Sealed;
dd.Name = astType.Name;
dd.AddAnnotation(typeDef);
astType.Attributes.MoveTo(dd.Attributes);
astType.TypeParameters.MoveTo(dd.TypeParameters);
astType.Constraints.MoveTo(dd.Constraints);
foreach (var m in typeDef.Methods) {
if (m.Name == "Invoke") {
dd.ReturnType = ConvertType(m.ReturnType, m.MethodReturnType);
dd.Parameters.AddRange(MakeParameters(m.Parameters));
}
}
result = dd;
} else {
// Base type
if (typeDef.BaseType != null && !typeDef.IsValueType && typeDef.BaseType.FullName != "System.Object") {
astType.AddChild(ConvertType(typeDef.BaseType), TypeDeclaration.BaseTypeRole);
}
foreach (var i in typeDef.Interfaces)
astType.AddChild(ConvertType(i), TypeDeclaration.BaseTypeRole);
AddTypeMembers(astType, typeDef);
}
context.CurrentType = oldCurrentType;
return result;
}