本文整理汇总了C#中ICSharpCode.NRefactory.Ast.TypeDeclaration类的典型用法代码示例。如果您正苦于以下问题:C# TypeDeclaration类的具体用法?C# TypeDeclaration怎么用?C# TypeDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeDeclaration类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了TypeDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TrackedVisitTypeDeclaration
public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
if (IsDerivedFrom(typeDeclaration, "Comparator"))
{
IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
MethodDeclaration equalsMethod = new MethodDeclaration("equals",
Modifiers.Public, AstUtil.GetTypeReference("bool", typeDeclaration), new List<ParameterDeclarationExpression>(), null);
equalsMethod.Parent = typeDeclaration;
TypeReference argTypeReference = AstUtil.GetTypeReference("java.lang.Object", equalsMethod);
argTypeReference.RankSpecifier = new int[] {};
equalsMethod.Parameters.Add(new ParameterDeclarationExpression(argTypeReference, "obj"));
if (Contains(methods, equalsMethod))
{
int index = IndexOf(methods, equalsMethod);
MethodDeclaration method = (MethodDeclaration) methods[index];
AstUtil.RemoveModifierFrom(method, Modifiers.Abstract);
method.TypeReference.Type = "bool";
CreateMethodImplementation(method);
}
else
{
CreateMethodImplementation(equalsMethod);
typeDeclaration.Children.Add(equalsMethod);
equalsMethod.Parent = typeDeclaration;
}
}
return base.TrackedVisitTypeDeclaration(typeDeclaration, data);
}
示例2: GetMethodsInParents
private IList GetMethodsInParents(TypeDeclaration typeDeclaration, IList pmList, bool implemented)
{
ClassType classType;
if (implemented)
classType = ClassType.Class;
else
classType = ClassType.Interface;
if (typeDeclaration.BaseTypes.Count > 0)
{
foreach (TypeReference parentType in typeDeclaration.BaseTypes)
{
string baseType = GetFullName(parentType);
if (CodeBase.Types.Contains(baseType))
{
TypeDeclaration parentTypeDeclaration = (TypeDeclaration) CodeBase.Types[baseType];
if (parentTypeDeclaration.Type == classType)
{
pmList = GetMethods(parentTypeDeclaration, pmList);
pmList = GetMethodsInParents(parentTypeDeclaration, pmList, implemented);
}
}
}
}
return pmList;
}
示例3: VisitTypeDeclaration
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
currentClass = currentNamepace + "." + typeDeclaration.Name;
base.VisitTypeDeclaration(typeDeclaration, data);
currentClass = null;
return null;
}
示例4: TrackedVisitTypeDeclaration
public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
if (IsAbstractClass(typeDeclaration))
{
IList currentClassMethods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
currentClassMethods = GetMethodsInParents(typeDeclaration, currentClassMethods, true);
IList methodsInParents = new ArrayList();
methodsInParents = GetMethodsInParents(typeDeclaration, methodsInParents, false);
methodsInParents = FilterImplementedMethods(methodsInParents);
IList abstractMethods = GetDiffList(currentClassMethods, methodsInParents);
if (abstractMethods.Count > 0)
{
TypeDeclaration replacedTypeDeclaration = typeDeclaration;
foreach (MethodDeclaration method in abstractMethods)
{
MethodDeclaration newMethod;
newMethod = new MethodDeclaration(method.Name,
Modifiers.Public | Modifiers.Abstract,
method.TypeReference,
method.Parameters,
method.Attributes);
newMethod.Parent = replacedTypeDeclaration;
replacedTypeDeclaration.Children.Add(newMethod);
}
ReplaceCurrentNode(replacedTypeDeclaration);
}
}
return base.TrackedVisitTypeDeclaration(typeDeclaration, data);
}
示例5: GenerateText
public static string GenerateText(TypeDeclaration type, OrderedPartCollection<AbstractDynamicCompilationExtension> extensions)
{
var unit = new CompilationUnit();
var namespaces = new HashSet<string>
{
typeof (SystemTime).Namespace,
typeof (AbstractViewGenerator).Namespace,
typeof (Enumerable).Namespace,
typeof (IEnumerable<>).Namespace,
typeof (IEnumerable).Namespace,
typeof (int).Namespace,
typeof (LinqOnDynamic).Namespace,
typeof(Field).Namespace,
};
foreach (var extension in extensions)
{
foreach (var ns in extension.Value.GetNamespacesToImport())
{
namespaces.Add(ns);
}
}
foreach (var ns in namespaces)
{
unit.AddChild(new Using(ns));
}
unit.AddChild(type);
var output = new CSharpOutputVisitor();
unit.AcceptVisitor(output, null);
return output.Text;
}
示例6: VerifyMethodCondition
protected override bool VerifyMethodCondition(TypeDeclaration typeDeclaration, MethodDeclaration methodDeclaration)
{
IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
string name = methodDeclaration.Name.Substring(3);
if (Contains(methods, methodDeclaration))
{
IList innerTypes = AstUtil.GetChildrenWithType(typeDeclaration, typeof(TypeDeclaration));
foreach (TypeDeclaration innerType in innerTypes)
{
if (innerType.Name == name)
return true;
}
IList constructors = AstUtil.GetChildrenWithType(typeDeclaration, typeof(ConstructorDeclaration));
foreach (ConstructorDeclaration constructorDeclaration in constructors)
{
if (constructorDeclaration.Name == name)
return true;
}
foreach (MethodDeclaration method in methods)
{
if (method.Name == name || char.ToUpper(method.Name[0]) + method.Name.Substring(1) == name)
return true;
}
}
else
{
IList properties = AstUtil.GetChildrenWithType(typeDeclaration, typeof(PropertyDeclaration));
return Contains(properties, name);
}
return false;
}
示例7: VisitTypeDeclaration
public override object VisitTypeDeclaration (TypeDeclaration node, object data)
{
if (CurrentType != null) {
Console.WriteLine ("Nested types are not supported");
//throw CreateException (node, "Nested types are not supported");
}
if (IsHiddenClass (node))
return null;
if ((node.Modifier & Modifiers.Partial) > 0) {
Console.WriteLine ("Partial classes are not supported: " + node);
//throw CreateException (node, "Partial classes are not supported");
}
CurrentType = new JsTypeInfo { Name = GenericsHelper.GetScriptName (node), ClassType = node.Type, Namespace = Namespace, Usings = new HashSet<string> (Usings) };
Usings = new HashSet<string> ();
CurrentType.IsStatic = node.Type == ClassType.Enum || HasModifier (node.Modifier, Modifiers.Static);
if (node.Type != ClassType.Interface)
node.AcceptChildren (this, null);
if (CachedCctor != null) {
if (!ProcessCctor ())
throw CreateException (node, "Static constructor may only contain primitive or array static field initializations");
CachedCctor = null;
}
CollectedTypes.Add (CurrentType);
CurrentType = null;
return null;
}
示例8: GetConstructorInfo
public static PythonConstructorInfo GetConstructorInfo(TypeDeclaration type)
{
PythonConstructorInfo pythonConstructorInfo;
List<FieldDeclaration> fieldDeclarations = new List<FieldDeclaration>();
ConstructorDeclaration constructorDeclaration = null;
foreach (INode child in type.Children)
{
ConstructorDeclaration constructorDeclaration1 = child as ConstructorDeclaration;
FieldDeclaration fieldDeclaration = child as FieldDeclaration;
if (constructorDeclaration1 != null)
{
constructorDeclaration = constructorDeclaration1;
}
else if (fieldDeclaration != null)
{
fieldDeclarations.Add(fieldDeclaration);
}
}
if ((fieldDeclarations.Count > 0 ? false : constructorDeclaration == null))
{
pythonConstructorInfo = null;
}
else
{
pythonConstructorInfo = new PythonConstructorInfo(constructorDeclaration, fieldDeclarations);
}
return pythonConstructorInfo;
}
示例9: VisitTypeDeclaration
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
Push();
object result = base.VisitTypeDeclaration(typeDeclaration, data);
Pop();
return result;
}
示例10: Generate
internal static string Generate(ParametrizedNode methodToCall, TypeDeclaration parentType,
string returnVariableName)
{
var template = new MethodCallStub(methodToCall, parentType, returnVariableName);
var text = template.TransformText();
return text;
}
示例11: add_Type
// create
public static TypeDeclaration add_Type(this NamespaceDeclaration namespaceDeclaration, IClass iClass)
{
// move to method IClass.typeDeclaration();
var typeName = iClass.Name;
var newType = namespaceDeclaration.type(typeName); // check if already exists and if it does return it
if (newType != null)
return newType;
const Modifiers modifiers = Modifiers.None | Modifiers.Public;
newType = new TypeDeclaration(modifiers, new List<AttributeSection>());
newType.Name = typeName;
foreach (var baseType in iClass.BaseTypes)
{
if (baseType.FullyQualifiedName != "System.Object") // no need to include this one
newType.BaseTypes.Add(new TypeReference(baseType.FullyQualifiedName));
}
namespaceDeclaration.AddChild(newType);
return newType;
//return namespaceDeclaration.add_Type(iClass.Name);
}
示例12: VisitTypeDeclaration
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
if (typeDeclaration.Type == ClassType.Class && typeDeclaration.Modifier.HasFlag(Modifiers.Abstract))
UnlockWith(typeDeclaration);
return base.VisitTypeDeclaration(typeDeclaration, data);
}
示例13: CreateType
public TypeDeclaration CreateType(TypeDefinition typeDef)
{
TypeDeclaration astType = new TypeDeclaration(ConvertModifiers(typeDef), new List<AttributeSection>());
astType.Name = typeDef.Name;
if (typeDef.IsEnum) { // NB: Enum is value type
astType.Type = ClassType.Enum;
} else if (typeDef.IsValueType) {
astType.Type = ClassType.Struct;
} else if (typeDef.IsInterface) {
astType.Type = ClassType.Interface;
} else {
astType.Type = ClassType.Class;
}
// Nested types
foreach(TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
astType.Children.Add(CreateType(nestedTypeDef));
}
// Base type
if (typeDef.BaseType != null && !typeDef.IsValueType && typeDef.BaseType.FullName != Constants.Object) {
astType.BaseTypes.Add(new Ast.TypeReference(typeDef.BaseType.FullName));
}
AddTypeMembers(astType, typeDef);
return astType;
}
示例14: IsMethodInExternalTypes
protected bool IsMethodInExternalTypes(TypeDeclaration typeDeclaration, MethodDeclaration methodDeclaration)
{
bool found = false;
foreach (TypeReference baseType in typeDeclaration.BaseTypes)
{
string fullName = GetFullName(baseType);
if (!found && CodeBase.Types.Contains(fullName))
{
TypeDeclaration baseTypeDeclaration = (TypeDeclaration) CodeBase.Types[fullName];
if (IsInExternalLibraries(fullName) || fullName.StartsWith("Helpers."))
{
IList methods = AstUtil.GetChildrenWithType(baseTypeDeclaration, typeof(MethodDeclaration));
if (ContainsMethod(methods, methodDeclaration))
found = true;
else
found = IsMethodInExternalTypes(baseTypeDeclaration, methodDeclaration);
}
else
found = IsMethodInExternalTypes(baseTypeDeclaration, methodDeclaration);
if (found)
break;
}
}
return found;
}
示例15: VisitTypeDeclaration
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
if (typeDeclaration.Type == ClassType.Class || typeDeclaration.Type == ClassType.Struct)
Classes.Add(typeDeclaration.Name, typeDeclaration);
return base.VisitTypeDeclaration(typeDeclaration, data);
}