当前位置: 首页>>代码示例>>C#>>正文


C# DomMethod.AddTypeParameter方法代码示例

本文整理汇总了C#中DomMethod.AddTypeParameter方法的典型用法代码示例。如果您正苦于以下问题:C# DomMethod.AddTypeParameter方法的具体用法?C# DomMethod.AddTypeParameter怎么用?C# DomMethod.AddTypeParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DomMethod的用法示例。


在下文中一共展示了DomMethod.AddTypeParameter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:25,代码来源:DomTests.cs

示例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);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:19,代码来源:DomTests.cs

示例3: VisitOperatorDeclaration

			public override object VisitOperatorDeclaration (ICSharpCode.NRefactory.Ast.OperatorDeclaration operatorDeclaration, object data)
			{
				DomMethod method = new DomMethod ();
				method.Name = GetOperatorName (operatorDeclaration);
				method.Documentation = RetrieveDocumentation (operatorDeclaration.StartLocation.Line);
				method.Location = ConvertLocation (operatorDeclaration.StartLocation);
				method.BodyRegion = ConvertRegion (operatorDeclaration.EndLocation, operatorDeclaration.Body != null ? operatorDeclaration.Body.EndLocation : new ICSharpCode.NRefactory.Location (-1, -1));
				method.Modifiers = ConvertModifiers (operatorDeclaration.Modifier) | Modifiers.SpecialName;
				if (operatorDeclaration.IsExtensionMethod)
					method.MethodModifier |= MethodModifier.IsExtension;
				method.ReturnType = ConvertReturnType (operatorDeclaration.TypeReference);
				AddAttributes (method, operatorDeclaration.Attributes);
				method.Add (ConvertParameterList (method, operatorDeclaration.Parameters));
				AddExplicitInterfaces (method, operatorDeclaration.InterfaceImplementations);

				if (operatorDeclaration.Templates != null && operatorDeclaration.Templates.Count > 0) {
					foreach (ICSharpCode.NRefactory.Ast.TemplateDefinition td in operatorDeclaration.Templates) {
						method.AddTypeParameter (ConvertTemplateDefinition (td));
					}
				}
				method.DeclaringType = typeStack.Peek ();
				typeStack.Peek ().Add (method);

				return null;
			}
开发者ID:Tak,项目名称:monodevelop-novell,代码行数:25,代码来源:NRefactoryParser.cs

示例4: 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;
        }
开发者ID:nazriel,项目名称:Mono-D,代码行数:83,代码来源:ParsedDModule.cs

示例5: 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;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:23,代码来源:DomPersistence.cs

示例6: 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);
		}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:20,代码来源:DomPersistenceTests.cs

示例7: 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);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:30,代码来源:DomTests.cs

示例8: 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);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:25,代码来源:DomTests.cs

示例9: 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);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:33,代码来源:DomTests.cs


注:本文中的DomMethod.AddTypeParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。