示例#1
0
        public void ReadWriteDelegateTest()
        {
            DomType input = DomType.CreateDelegate(null, "TestDelegate", new DomLocation(10, 10), DomReturnType.Void, new List <IParameter> ());

            MemoryStream ms     = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms);

            DomPersistence.Write(writer, DefaultNameEncoder, input);
            byte[] bytes = ms.ToArray();

            DomType result = DomPersistence.ReadType(CreateReader(bytes), DefaultNameDecoder, null);

            Assert.AreEqual("TestDelegate", result.Name);
            Assert.AreEqual(ClassType.Delegate, result.ClassType);
        }
			public override object VisitDelegateDeclaration (ICSharpCode.NRefactory.Ast.DelegateDeclaration delegateDeclaration, object data)
			{
				List<IParameter> parameter = ConvertParameterList (null, delegateDeclaration.Parameters);
				DomType delegateType = DomType.CreateDelegate (result.CompilationUnit, delegateDeclaration.Name, ConvertLocation (delegateDeclaration.StartLocation), ConvertReturnType (delegateDeclaration.ReturnType), parameter);
				delegateType.Documentation = RetrieveDocumentation (delegateDeclaration.StartLocation.Line);
				delegateType.Location = ConvertLocation (delegateDeclaration.StartLocation);
				delegateType.Modifiers = ConvertModifiers (delegateDeclaration.Modifier);
				AddAttributes (delegateType, delegateDeclaration.Attributes);

				foreach (DomParameter p in parameter) {
					p.DeclaringMember = delegateType;
				}
				
				if (delegateDeclaration.Templates != null && delegateDeclaration.Templates.Count > 0) {
					foreach (ICSharpCode.NRefactory.Ast.TemplateDefinition template in delegateDeclaration.Templates) {
						delegateType.AddTypeParameter (ConvertTemplateDefinition (template));
					}
				}
				AddType (delegateType);

				return null;
			}