本文整理汇总了C#中DomMethod类的典型用法代码示例。如果您正苦于以下问题:C# DomMethod类的具体用法?C# DomMethod怎么用?C# DomMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DomMethod类属于命名空间,在下文中一共展示了DomMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstantiatedMethodByParameterTest
public void InstantiatedMethodByParameterTest ()
{
// build "T MyMethod<T> (T[] a)"
DomMethod method = new DomMethod ();
method.Name = "MyMethod";
method.ReturnType = new DomReturnType ("T");
method.AddTypeParameter (new TypeParameter ("T"));
DomReturnType returnType = new DomReturnType ("T");
returnType.ArrayDimensions = 1;
method.Add (new DomParameter (method, "a", returnType));
// give int[] as param type.
List<IReturnType> genArgs = new List<IReturnType> ();
List<IReturnType> args = new List<IReturnType> ();
returnType = new DomReturnType (DomReturnType.Int32.FullName);
returnType.ArrayDimensions = 1;
args.Add (returnType);
IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod (method, genArgs, args);
// check (note that return type should be int and not int[])
Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.ReturnType.FullName);
Assert.AreEqual (0, instMethod.ReturnType.ArrayDimensions);
Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.Parameters[0].ReturnType.FullName);
}
示例2: InstantiatedMethodByArgumentTest
public void InstantiatedMethodByArgumentTest ()
{
// build "T MyMethod<T> (T a)"
DomMethod method = new DomMethod ();
method.Name = "MyMethod";
method.ReturnType = new DomReturnType ("T");
method.AddTypeParameter (new TypeParameter ("T"));
method.Add (new DomParameter (method, "a", new DomReturnType ("T")));
// give int as param type
List<IReturnType> genArgs = new List<IReturnType> ();
List<IReturnType> args = new List<IReturnType> ();
args.Add (DomReturnType.Int32);
IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod (method, genArgs, args);
// check
Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.ReturnType.FullName);
Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.Parameters[0].ReturnType.FullName);
}
示例3: PopulateMethods
/// <summary>
/// Populate a DomType with methods
/// </summary>
void PopulateMethods(DomType parent)
{
List<int> removal = new List<int> ();
Match match;
DomMethod m;
foreach (KeyValuePair<int,RubyDeclaration> mpair in methods) {
if (mpair.Key > parent.Location.Line && mpair.Key < parent.BodyRegion.End.Line) {
parent.Add (m = new DomMethod (mpair.Value.name, Modifiers.None, MethodModifier.None, new DomLocation (mpair.Value.beginLine, 1),
new DomRegion (mpair.Value.beginLine, mpair.Value.beginColumn+1,
mpair.Value.endLine, int.MaxValue), new DomReturnType (string.Empty)));
match = methodDefinition.Match (mpair.Value.declaration);
if (match.Groups["params"].Success) {
foreach (string param in match.Groups["params"].Value.Split (new char[]{',',' ','\t'}, StringSplitOptions.RemoveEmptyEntries)) {
m.Add (new DomParameter (m, param, new DomReturnType (param)));
}
}
removal.Add (mpair.Key);
}// Add methods that are declared within the parent's scope
}// Check detected methods
// Remove used methods from map
foreach (int key in removal){ methods.Remove (key); }
}
示例4: Visit
public override void Visit (Operator o)
{
DomMethod method = new DomMethod ();
method.Name = ConvertQuoted (o.MemberName.Name);
method.Documentation = RetrieveDocumentation (o.Location.Row);
method.Location = Convert (o.MemberName.Location);
method.Modifiers = ConvertModifiers (o.ModFlags);
if (o.Block != null) {
var location = LocationsBag.GetMemberLocation (o);
var region = ConvertRegion (location != null ? location[1] : o.Block.StartLocation, o.Block.EndLocation);
if (location != null)
region.Start = new DomLocation (region.Start.Line, region.Start.Column + 1);
method.BodyRegion = region;
}
method.Modifiers = ConvertModifiers (o.ModFlags) | MonoDevelop.Projects.Dom.Modifiers.SpecialName;
method.ReturnType = ConvertReturnType (o.TypeName);
AddAttributes (method, o.OptAttributes, o);
AddParameter (method, o.ParameterInfo);
AddExplicitInterfaces (method, o);
method.DeclaringType = typeStack.Peek ();
typeStack.Peek ().Add (method);
}
示例5: Visit
public override void Visit (Method m)
{
DomMethod method = new DomMethod ();
method.Name = m.MemberName.Name;
method.Documentation = RetrieveDocumentation (m.Location.Row);
method.Location = Convert (m.MemberName.Location);
method.Modifiers = ConvertModifiers (m.ModFlags);
if (m.Block != null) {
var location = LocationsBag.GetMemberLocation (m);
var region = ConvertRegion (location != null ? location[1] : m.Block.StartLocation, m.Block.EndLocation);
if (location != null)
region.Start = new DomLocation (region.Start.Line, region.Start.Column + 1);
method.BodyRegion = region;
}
method.ReturnType = ConvertReturnType (m.TypeName);
AddAttributes (method, m.OptAttributes, m);
AddParameter (method, m.ParameterInfo);
AddExplicitInterfaces (method, m);
method.Modifiers = ConvertModifiers (m.ModFlags);
if (method.IsStatic && method.Parameters.Count > 0 && method.Parameters[0].ParameterModifiers == ParameterModifiers.This)
method.MethodModifier |= MethodModifier.IsExtension;
if (m.GenericMethod != null)
AddTypeParameter (method, m.GenericMethod);
method.DeclaringType = typeStack.Peek ();
typeStack.Peek ().Add (method);
// Hack: Fixes Bug 650840 - Missing completion for locals
// Take out, when the parser has improved error recovery for this case.
if (m.Block == null && typeStack.Peek ().ClassType != ClassType.Interface) {
method.BodyRegion = new DomRegion (new DomLocation (m.Location.Row, m.Location.Column), typeStack.Peek ().BodyRegion.End);
}
}
示例6: ConstructMethodFromDelegate
IMethod ConstructMethodFromDelegate (RefactoringOptions options)
{
DomMethod result = new DomMethod (methodName, modifiers, MethodModifier.None, DomLocation.Empty, DomRegion.Empty, returnType);
result.DeclaringType = new DomType ("GeneratedType") { ClassType = declaringType.ClassType };
IMethod invocation = (IMethod)delegateType.SearchMember ("Invoke", true).First ();
foreach (var arg in invocation.Parameters) {
result.Add (arg);
}
result.ReturnType = invocation.ReturnType;
return result;
}
示例7: VisitEventDeclaration
public override object VisitEventDeclaration (ICSharpCode.NRefactory.Ast.EventDeclaration eventDeclaration, object data)
{
DomEvent evt = new DomEvent ();
evt.Name = eventDeclaration.Name;
evt.Documentation = RetrieveDocumentation (eventDeclaration.StartLocation.Line);
evt.Location = ConvertLocation (eventDeclaration.StartLocation);
evt.Modifiers = ConvertModifiers (eventDeclaration.Modifier);
evt.ReturnType = ConvertReturnType (eventDeclaration.TypeReference);
evt.BodyRegion = ConvertRegion (eventDeclaration.BodyStart, eventDeclaration.BodyEnd);
if (eventDeclaration.AddRegion != null && !eventDeclaration.AddRegion.IsNull) {
DomMethod addMethod = new DomMethod ();
addMethod.Name = "add";
addMethod.BodyRegion = ConvertRegion (eventDeclaration.AddRegion.StartLocation, eventDeclaration.AddRegion.EndLocation);
evt.AddMethod = addMethod;
}
if (eventDeclaration.RemoveRegion != null && !eventDeclaration.RemoveRegion.IsNull) {
DomMethod removeMethod = new DomMethod ();
removeMethod.Name = "remove";
removeMethod.BodyRegion = ConvertRegion (eventDeclaration.RemoveRegion.StartLocation, eventDeclaration.RemoveRegion.EndLocation);
evt.RemoveMethod = removeMethod;
}
AddAttributes (evt, eventDeclaration.Attributes);
AddExplicitInterfaces (evt, eventDeclaration.InterfaceImplementations);
evt.DeclaringType = typeStack.Peek ();
typeStack.Peek ().Add (evt);
return null;
}
示例8: VisitDestructorDeclaration
public override object VisitDestructorDeclaration (ICSharpCode.NRefactory.Ast.DestructorDeclaration destructorDeclaration, object data)
{
DomMethod destructor = new DomMethod ();
destructor.Name = ".dtor";
destructor.Documentation = RetrieveDocumentation (destructorDeclaration.StartLocation.Line);
destructor.Location = ConvertLocation (destructorDeclaration.StartLocation);
destructor.BodyRegion = ConvertRegion (destructorDeclaration.EndLocation, destructorDeclaration.Body != null ? destructorDeclaration.Body.EndLocation : new ICSharpCode.NRefactory.Location (-1, -1));
destructor.Modifiers = ConvertModifiers (destructorDeclaration.Modifier);
AddAttributes (destructor, destructorDeclaration.Attributes);
destructor.MethodModifier |= MethodModifier.IsFinalizer;
destructor.DeclaringType = typeStack.Peek ();
typeStack.Peek ().Add (destructor);
return null;
}
示例9: VisitInvocationExpression
public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
if (invocationExpression == null)
return null;
if (invocationDictionary.ContainsKey (invocationExpression))
return invocationDictionary[invocationExpression];
// add support for undocumented __makeref and __reftype keywords
if (invocationExpression.TargetObject is IdentifierExpression) {
IdentifierExpression idExpr = invocationExpression.TargetObject as IdentifierExpression;
if (idExpr.Identifier == "__makeref")
return CreateResult ("System.TypedReference");
if (idExpr.Identifier == "__reftype")
return CreateResult ("System.Type");
}
ResolveResult targetResult = Resolve (invocationExpression.TargetObject);
if (targetResult is CombinedMethodResolveResult)
targetResult = ((CombinedMethodResolveResult)targetResult).MethodResolveResult;
targetResult.StaticResolve = false; // invocation result is never static
if (this.resolver.CallingType != null) {
if (targetResult is ThisResolveResult) {
targetResult = new MethodResolveResult (this.resolver.CallingType.Methods.Where (method => method.IsConstructor));
((MethodResolveResult)targetResult).Type = this.resolver.CallingType;
targetResult.CallingType = resolver.CallingType;
targetResult.CallingMember = resolver.CallingMember;
} else if (targetResult is BaseResolveResult) {
System.Collections.IEnumerable baseConstructors = null;
IType firstBaseType = null;
foreach (IReturnType bT in this.resolver.CallingType.BaseTypes) {
IType resolvedBaseType = resolver.SearchType (bT);
if (firstBaseType == null && resolvedBaseType.ClassType != MonoDevelop.Projects.Dom.ClassType.Interface)
firstBaseType = resolvedBaseType;
foreach (IType baseType in resolver.Dom.GetInheritanceTree (resolvedBaseType)) {
if (baseType.ClassType == MonoDevelop.Projects.Dom.ClassType.Interface)
break;
baseConstructors = baseType.Methods.Where (method => method.IsConstructor);
goto bailOut;
}
}
bailOut:
if (baseConstructors == null) {
if (firstBaseType != null) {
// if there is a real base type without a .ctor a default .ctor for this type is generated.
DomMethod constructedConstructor;
constructedConstructor = new DomMethod ();
constructedConstructor.Name = ".ctor";
constructedConstructor.MethodModifier = MethodModifier.IsConstructor;
constructedConstructor.DeclaringType = firstBaseType;
constructedConstructor.Modifiers = MonoDevelop.Projects.Dom.Modifiers.Public;
baseConstructors = new IMethod[] {
constructedConstructor
};
} else {
baseConstructors = resolver.SearchType (DomReturnType.Object).SearchMember (".ctor", true);
}
}
targetResult = new MethodResolveResult (baseConstructors);
((MethodResolveResult)targetResult).Type = this.resolver.CallingType;
targetResult.CallingType = resolver.CallingType;
targetResult.CallingMember = resolver.CallingMember;
}
}
MethodResolveResult methodResult = targetResult as MethodResolveResult;
if (methodResult != null) {
methodResult.GetsInvoked = true;
// Console.WriteLine ("--------------------");
// Console.WriteLine ("i:" + methodResult.ResolvedType);
/* foreach (var arg in methodResult.GenericArguments) {
methodResult.AddGenericArgument (arg);
}*/
foreach (Expression arg in invocationExpression.Arguments) {
var type = GetTypeSafe (arg);
methodResult.AddArgument (type);
}
//Console.WriteLine ("--------------------");
methodResult.ResolveExtensionMethods ();
// Console.WriteLine ("i2:" + methodResult.ResolvedType);
/* MemberReferenceExpression mre = invocationExpression.TargetObject as MemberReferenceExpression;
if (mre != null) {
foreach (TypeReference typeReference in mre.TypeArguments) {
methodResult.AddGenericArgument (new DomReturnType (String.IsNullOrEmpty (typeReference.SystemType) ? typeReference.Type : typeReference.SystemType));
}
}*/
// return CreateResult (methodResult.Methods [0].ReturnType);
}
invocationDictionary[invocationExpression] = targetResult;
return targetResult;
}
示例10: ExtensionMethodPreserveParameterTest
public void ExtensionMethodPreserveParameterTest ()
{
// build "T MyMethod<T, S> (T a, S b)"
DomMethod method = new DomMethod ();
method.Name = "MyMethod";
method.ReturnType = new DomReturnType ("T");
method.AddTypeParameter (new TypeParameter ("T"));
method.AddTypeParameter (new TypeParameter ("S"));
method.Add (new DomParameter (method, "a", new DomReturnType ("T")));
method.Add (new DomParameter (method, "b", new DomReturnType ("S")));
// extend method
List<IReturnType> genArgs = new List<IReturnType> ();
List<IReturnType> args = new List<IReturnType> ();
DomType extType = new DomType ("MyType");
ExtensionMethod extMethod = new ExtensionMethod (extType, method, genArgs, args);
// check for MyType MyMethod<S> (S b)
Assert.AreEqual ("MyType", extMethod.ReturnType.FullName);
Assert.AreEqual ("S", extMethod.Parameters[0].ReturnType.FullName);
Assert.AreEqual (1, extMethod.TypeParameters.Count);
Assert.AreEqual ("S", extMethod.TypeParameters[0].Name);
}
示例11: ExtensionMethodTest
public void ExtensionMethodTest ()
{
// build "T MyMethod<T, S> (this KeyValuePair<T, S> a, S b)"
DomMethod method = new DomMethod ();
method.Name = "MyMethod";
method.ReturnType = new DomReturnType ("T");
method.AddTypeParameter (new TypeParameter ("T"));
method.AddTypeParameter (new TypeParameter ("S"));
DomReturnType returnType = new DomReturnType ("KeyValuePair");
returnType.AddTypeParameter (new DomReturnType ("T"));
returnType.AddTypeParameter (new DomReturnType ("S"));
method.Add (new DomParameter (method, "a", returnType));
method.Add (new DomParameter (method, "b", new DomReturnType ("S")));
// Build extendet type KeyValuePair<int, object>
DomType type = new DomType ("KeyValuePair");
type.AddTypeParameter (new TypeParameter ("T"));
type.AddTypeParameter (new TypeParameter ("S"));
IType extType = DomType.CreateInstantiatedGenericTypeInternal (type, new IReturnType[] { DomReturnType.Int32, DomReturnType.Object });
Console.WriteLine (extType);
// extend method
List<IReturnType> genArgs = new List<IReturnType> ();
List<IReturnType> args = new List<IReturnType> ();
ExtensionMethod extMethod = new ExtensionMethod (extType, method, genArgs, args);
Console.WriteLine (extMethod);
// check
Assert.AreEqual (DomReturnType.Int32.FullName, extMethod.ReturnType.FullName);
Assert.AreEqual (DomReturnType.Object.FullName, extMethod.Parameters[0].ReturnType.FullName);
}
示例12: GenerateCU
static void GenerateCU (XmlParsedDocument doc)
{
if (doc.XDocument == null || doc.XDocument.RootElement == null) {
doc.Add (new Error (ErrorType.Error, 1, 1, "No root node found."));
return;
}
XAttribute rootClass = doc.XDocument.RootElement.Attributes [new XName ("x", "Class")];
if (rootClass == null) {
doc.Add (new Error (ErrorType.Error, 1, 1, "Root node does not contain an x:Class attribute."));
return;
}
bool isApplication = doc.XDocument.RootElement.Name.Name == "Application";
string rootNamespace, rootType, rootAssembly;
XamlG.ParseXmlns (rootClass.Value, out rootType, out rootNamespace, out rootAssembly);
CompilationUnit cu = new CompilationUnit (doc.FileName);
doc.CompilationUnit = cu;
DomRegion rootRegion = doc.XDocument.RootElement.Region;
if (doc.XDocument.RootElement.IsClosed)
rootRegion.End = doc.XDocument.RootElement.ClosingTag.Region.End;
DomType declType = new DomType (cu, ClassType.Class, Modifiers.Partial | Modifiers.Public, rootType,
doc.XDocument.RootElement.Region.Start, rootNamespace, rootRegion);
cu.Add (declType);
DomMethod initcomp = new DomMethod ();
initcomp.Name = "InitializeComponent";
initcomp.Modifiers = Modifiers.Public;
initcomp.ReturnType = DomReturnType.Void;
declType.Add (initcomp);
DomField _contentLoaded = new DomField ("_contentLoaded");
_contentLoaded.ReturnType = new DomReturnType ("System.Boolean");
if (isApplication)
return;
cu.Add (new DomUsing (DomRegion.Empty, "System"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Documents"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Input"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media.Animation"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Shapes"));
cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls.Primitives"));
// Dictionary<string,string> namespaceMap = new Dictionary<string, string> ();
// namespaceMap["x"] = "http://schemas.microsoft.com/winfx/2006/xaml";
XName nameAtt = new XName ("x", "Name");
foreach (XElement el in doc.XDocument.RootElement.AllDescendentElements) {
XAttribute name = el.Attributes [nameAtt];
if (name != null && name.IsComplete) {
string type = ResolveType (el);
if (type == null || type.Length == 0)
doc.Add (new Error (ErrorType.Error, el.Region.Start, "Could not find namespace for '" + el.Name.FullName + "'."));
else
declType.Add (new DomField (name.Value, Modifiers.Internal, el.Region.Start, new DomReturnType (type)));
}
}
}
示例13: BuildFunction
void BuildFunction (XmlElement element)
{
var compUnit = this.CompilationUnit as PythonCompilationUnit;
Console.WriteLine ("Function({0})", element.GetAttribute ("name"));
var name = element.GetAttribute ("name");
var mod = Modifiers.None;
if (name.StartsWith ("_"))
mod |= Modifiers.Private;
else
mod |= Modifiers.Public;
var start = GetDomLocation (element);
var region = GetDomRegion (element);
var func = new DomMethod (name, mod, MethodModifier.None,
start, region);
compUnit.Add (func);
}
示例14: GenerateMethodStub
static DomMethod GenerateMethodStub (RefactoringOptions options, ExtractMethodParameters param)
{
DomMethod result = new DomMethod ();
result.Name = param.Name;
result.ReturnType = param.ExpressionType ?? DomReturnType.Void;
result.Modifiers = param.Modifiers;
if (!param.ReferencesMember)
result.Modifiers |= MonoDevelop.Projects.Dom.Modifiers.Static;
if (param.Parameters == null)
return result;
foreach (var p in param.Parameters) {
if (param.OneChangedVariable && p.UsedAfterCutRegion && !p.UsedInCutRegion)
continue;
var newParameter = new DomParameter ();
newParameter.Name = p.Name;
newParameter.ReturnType = p.ReturnType;
if (!param.OneChangedVariable) {
if (!p.IsDefinedInsideCutRegion && p.IsChangedInsideCutRegion) {
newParameter.ParameterModifiers = p.UsedBeforeCutRegion ? ParameterModifiers.Ref : ParameterModifiers.Out;
}
}
result.Add (newParameter);
}
return result;
}
示例15: InstantiatedMethodByArgumentTest_Complex
public void InstantiatedMethodByArgumentTest_Complex ()
{
// build "T MyMethod<T,S> (S b, KeyValuePair<S, T> a)"
DomMethod method = new DomMethod ();
method.Name = "MyMethod";
method.ReturnType = new DomReturnType ("T");
method.AddTypeParameter (new TypeParameter ("T"));
method.AddTypeParameter (new TypeParameter ("S"));
method.Add (new DomParameter (method, "b", new DomReturnType ("S")));
DomReturnType returnType = new DomReturnType ("KeyValuePair");
returnType.AddTypeParameter (new DomReturnType ("T"));
returnType.AddTypeParameter (new DomReturnType ("S"));
method.Add (new DomParameter (method, "a", returnType));
// give int, object as param type
List<IReturnType> genArgs = new List<IReturnType> ();
List<IReturnType> args = new List<IReturnType> ();
genArgs.Add (DomReturnType.Int32);
genArgs.Add (DomReturnType.Object);
IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod (method, genArgs, args);
// check
Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.ReturnType.FullName);
Assert.AreEqual (DomReturnType.Object.FullName, instMethod.Parameters[0].ReturnType.FullName);
Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.Parameters[1].ReturnType.GenericArguments[0].FullName);
Assert.AreEqual (DomReturnType.Object.FullName, instMethod.Parameters[1].ReturnType.GenericArguments[1].FullName);
}