本文整理汇总了C#中DomMethod.Add方法的典型用法代码示例。如果您正苦于以下问题:C# DomMethod.Add方法的具体用法?C# DomMethod.Add怎么用?C# DomMethod.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomMethod
的用法示例。
在下文中一共展示了DomMethod.Add方法的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: ConvertDParserToDomNode
public static MonoDevelop.Projects.Dom.INode ConvertDParserToDomNode(D_Parser.Dom.INode n, ParsedDocument doc)
{
//TODO: DDoc comments!
if (n is DMethod)
{
var dm = n as DMethod;
var domMethod = new DomMethod(
n.Name,
GetNodeModifiers(dm),
dm.SpecialType == DMethod.MethodType.Constructor ? MethodModifier.IsConstructor : MethodModifier.None,
FromCodeLocation(n.StartLocation),
GetBlockBodyRegion(dm),
GetReturnType(n));
foreach (var pn in dm.Parameters)
domMethod.Add(new DomParameter(domMethod, pn.Name, GetReturnType(pn)));
domMethod.AddTypeParameter(GetTypeParameters(dm));
foreach (var subNode in dm) domMethod.AddChild(ConvertDParserToDomNode(subNode, doc));
return domMethod;
}
else if (n is DEnum)
{
var de = n as DEnum;
var domType = new DomType(
doc.CompilationUnit,
ClassType.Enum,
GetNodeModifiers(de),
n.Name,
FromCodeLocation(n.StartLocation),
BuildTypeNamespace(n), GetBlockBodyRegion(de));
foreach (var subNode in de)
domType.Add(ConvertDParserToDomNode(subNode, doc) as IMember);
return domType;
}
else if (n is DClassLike)
{
var dc = n as DClassLike;
ClassType ct = ClassType.Unknown;
switch (dc.ClassType)
{
case DTokens.Template:
case DTokens.Class:
ct = ClassType.Class;
break;
case DTokens.Interface:
ct = ClassType.Interface;
break;
case DTokens.Union:
case DTokens.Struct:
ct = ClassType.Struct;
break;
}
var domType = new DomType(
doc.CompilationUnit,
ct,
GetNodeModifiers(dc),
n.Name,
FromCodeLocation(n.StartLocation),
BuildTypeNamespace(n),
GetBlockBodyRegion(dc));
domType.AddTypeParameter(GetTypeParameters(dc));
foreach (var subNode in dc)
domType.Add(ConvertDParserToDomNode(subNode, doc) as IMember);
return domType;
}
else if (n is DVariable)
{
var dv = n as DVariable;
return new DomField(n.Name, GetNodeModifiers(dv), FromCodeLocation(n.StartLocation), GetReturnType(n));
}
return null;
}
示例4: 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;
}
示例5: BuildFunctions
IEnumerable<IMethod> BuildFunctions(IEnumerable<PythonFunction> functions)
{
if (functions == null)
yield break;
foreach (PythonFunction pyFunc in functions)
{
var domFunc = new DomMethod () {
Name = pyFunc.Name,
Documentation = pyFunc.Documentation,
BodyRegion = pyFunc.Region,
Location = new DomLocation (pyFunc.Region.Start.Line - 1, 0),
ReturnType = new DomReturnType () {
Name = pyFunc.Name, // FIXME: Get inferred type
Namespace = Module.FullName,
},
};
m_AllWrapped.Add (domFunc);
foreach (PythonArgument pyArg in pyFunc.Arguments)
{
var domArg = new DomParameter () {
Name = pyArg.Name,
ReturnType = new DomReturnType () {
Name = pyArg.Name, // FIXME: Get inferred type
Namespace = Module.FullName,
},
};
m_AllWrapped.Add (domArg);
domFunc.Add (domArg);
}
yield return domFunc;
}
}
示例6: Parse
public override ParsedDocument Parse (ProjectDom dom, string fileName, string content)
{
ParsedDocument doc = new ParsedDocument (fileName);
ProjectInformation pi = ProjectInformationManager.Instance.Get ((null == dom)? null: dom.Project);
if(null == doc.CompilationUnit){ doc.CompilationUnit = new CompilationUnit (fileName); }
CompilationUnit cu = (CompilationUnit)doc.CompilationUnit;
int lastLine = 0;
ICollection<Symbol> classes = pi.GetClassesForFile (fileName);
if (null == classes || 0 == classes.Count) {
return lastGood;
}
foreach (Symbol node in classes) {
if (null == node){ continue; }
List<IMember> members = new List<IMember> ();
lastLine = node.SourceReferences[0].LastLine;
foreach (Symbol child in node.Children) {
if (1 > child.SourceReferences.Count ||
child.SourceReferences[0].File != node.SourceReferences[0].File){ continue; }
lastLine = Math.Max (lastLine, child.SourceReferences[0].LastLine+1);
switch (child.SymbolType.ToLower ()) {
case "class":
members.Add (new DomType (new CompilationUnit (fileName), ClassType.Class, child.Name, new DomLocation (child.SourceReferences[0].FirstLine, 1), string.Empty, new DomRegion (child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new List<IMember> ()));
break;
case "interface":
members.Add (new DomType (new CompilationUnit (fileName), ClassType.Interface, child.Name, new DomLocation (child.SourceReferences[0].FirstLine, 1), string.Empty, new DomRegion (child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new List<IMember> ()));
break;
case "delegate":
members.Add (new DomType (new CompilationUnit (fileName), ClassType.Delegate, child.Name, new DomLocation (child.SourceReferences[0].FirstLine, 1), string.Empty, new DomRegion (child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new List<IMember> ()));
break;
case "struct":
members.Add (new DomType (new CompilationUnit (fileName), ClassType.Struct, child.Name, new DomLocation (child.SourceReferences[0].FirstLine, 1), string.Empty, new DomRegion (child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new List<IMember> ()));
break;
case "enum":
members.Add (new DomType (new CompilationUnit (fileName), ClassType.Enum, child.Name, new DomLocation (child.SourceReferences[0].FirstLine, 1), string.Empty, new DomRegion (child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new List<IMember> ()));
break;
case "method":
case "creationmethod":
case "constructor":
DomMethod method = new DomMethod (child.Name, Modifiers.None, MethodModifier.None, new DomLocation (child.SourceReferences[0].FirstLine, 1), new DomRegion (child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new DomReturnType (child.ReturnType.TypeName));
foreach (DataType param in child.Parameters) {
method.Add (new DomParameter (method, param.Name, new DomReturnType (param.TypeName)));
}
members.Add (method);
break;
case "property":
members.Add (new DomProperty (child.Name, Modifiers.None, new DomLocation (child.SourceReferences[0].FirstLine, 1), new DomRegion (child.SourceReferences[0].FirstLine, int.MaxValue, child.SourceReferences[0].LastLine, int.MaxValue), new DomReturnType ()));
break;
case "field":
case "constant":
case "errorcode":
members.Add (new DomField (child.Name, Modifiers.None, new DomLocation (child.SourceReferences[0].FirstLine, 1), new DomReturnType ()));
break;
case "signal":
members.Add (new DomEvent (child.Name, Modifiers.None, new DomLocation (child.SourceReferences[0].FirstLine, 1), new DomReturnType ()));
break;
default:
MonoDevelop.Core.LoggingService.LogDebug ("ValaDocumentParser: Unsupported member type: {0}", child.SymbolType);
break;
}// Switch on node type
}// Collect members
cu.Add (new DomType (new CompilationUnit (fileName), ClassType.Class, node.Name, new DomLocation (node.SourceReferences[0].FirstLine, 1), string.Empty, new DomRegion (node.SourceReferences[0].FirstLine, int.MaxValue, lastLine, int.MaxValue), members));
}// Add each class in file
return (lastGood = doc);
}// Parse
示例7: ReadMethod
public static DomMethod ReadMethod (BinaryReader reader, INameDecoder nameTable, IDomObjectTable objectTable)
{
DomMethod result = new DomMethod ();
ReadMemberInformation (reader, nameTable, objectTable, result);
uint explicitInterfaces = ReadUInt (reader, 500);
while (explicitInterfaces-- > 0) {
result.AddExplicitInterface (ReadReturnType (reader, nameTable, objectTable));
}
result.BodyRegion = ReadRegion (reader, nameTable);
result.ReturnType = ReadReturnType (reader, nameTable, objectTable);
result.MethodModifier = (MethodModifier)reader.ReadInt32 ();
uint arguments = ReadUInt (reader, 5000);
while (arguments-- > 0) {
result.Add (ReadParameter (reader, nameTable, objectTable));
}
arguments = ReadUInt (reader, 500);
while (arguments-- > 0) {
result.AddTypeParameter (ReadTypeParameter (reader, nameTable, objectTable));
}
return result;
}
示例8: 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); }
}
示例9: 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;
}
示例10: ReadWriteMethodTest
public void ReadWriteMethodTest ()
{
DomMethod input = new DomMethod ();
input.Name = "Test";
input.MethodModifier = MethodModifier.IsConstructor;
input.Add (new DomParameter (input, "par1", DomReturnType.Void));
input.AddTypeParameter (new TypeParameter ("T"));
MemoryStream ms = new MemoryStream ();
BinaryWriter writer = new BinaryWriter (ms);
DomPersistence.Write (writer, DefaultNameEncoder, input);
byte[] bytes = ms.ToArray ();
DomMethod result = DomPersistence.ReadMethod (CreateReader (bytes), DefaultNameDecoder);
Assert.AreEqual ("Test", result.Name);
Assert.AreEqual (true, result.IsConstructor);
Assert.AreEqual ("par1", result.Parameters [0].Name);
Assert.AreEqual ("Void", result.Parameters [0].ReturnType.Name);
Assert.AreEqual (1, result.TypeParameters.Count);
Assert.AreEqual ("T", result.TypeParameters [0].Name);
}
示例11: 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);
}
示例12: 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);
}
示例13: 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);
}
示例14: VisitConstructorDeclaration
public override object VisitConstructorDeclaration (ICSharpCode.NRefactory.Ast.ConstructorDeclaration constructorDeclaration, object data)
{
DomMethod constructor = new DomMethod ();
constructor.Documentation = RetrieveDocumentation (constructorDeclaration.StartLocation.Line);
constructor.Name = ".ctor";
constructor.MethodModifier |= MethodModifier.IsConstructor;
constructor.Location = ConvertLocation (constructorDeclaration.StartLocation);
constructor.BodyRegion = ConvertRegion (constructorDeclaration.EndLocation, constructorDeclaration.Body != null ? constructorDeclaration.Body.EndLocation : new ICSharpCode.NRefactory.Location (-1, -1));
constructor.Modifiers = ConvertModifiers (constructorDeclaration.Modifier);
AddAttributes (constructor, constructorDeclaration.Attributes);
constructor.Add (ConvertParameterList (constructor, constructorDeclaration.Parameters));
constructor.DeclaringType = typeStack.Peek ();
typeStack.Peek ().Add (constructor);
return null;
}
示例15: BindSignal
/// Adds a signal handler to the class
public void BindSignal (Stetic.Signal signal)
{
if (targetObject == null)
return;
IType cls = GetClass ();
if (cls == null)
return;
if (FindSignalHandler (cls, signal) != null)
return;
var met = new DomMethod () {
Name = signal.Handler,
Modifiers = Modifiers.Protected,
ReturnType = new DomReturnType (signal.SignalDescriptor.HandlerReturnTypeName)
};
foreach (Stetic.ParameterDescriptor pinfo in signal.SignalDescriptor.HandlerParameters)
met.Add (new DomParameter () { Name = pinfo.Name, ReturnType = new DomReturnType (pinfo.TypeName) });
CodeGenerationService.AddNewMember (cls, met);
}