Exemple #1
0
            IEvent ReadEvent()
            {
                DefaultEvent p = new DefaultEvent(currentClass, ReadString());

                ReadMember(p);
                return(p);
            }
		public override IMember Clone()
		{
			DefaultEvent de = new DefaultEvent(Name, ReturnType, Modifiers, Region, BodyRegion, DeclaringType);
			foreach (ExplicitInterfaceImplementation eii in InterfaceImplementations) {
				de.InterfaceImplementations.Add(eii.Clone());
			}
			return de;
		}
Exemple #3
0
        public override IMember Clone()
        {
            DefaultEvent de = new DefaultEvent(Name, ReturnType, Modifiers, Region, BodyRegion, DeclaringType);

            foreach (ExplicitInterfaceImplementation eii in InterfaceImplementations)
            {
                de.InterfaceImplementations.Add(eii.Clone());
            }
            return(de);
        }
		public override IMember Clone()
		{
			DefaultEvent de = new DefaultEvent(Name, ReturnType, Modifiers, Region, BodyRegion, DeclaringType);
			de.CopyDocumentationFrom(this);
			foreach (ExplicitInterfaceImplementation eii in InterfaceImplementations) {
				de.InterfaceImplementations.Add(eii.Clone());
			}
			if (addMethod != null)
				de.addMethod = (IMethod)addMethod.Clone();
			if (removeMethod != null)
				de.removeMethod = (IMethod)removeMethod.Clone();
			if (raiseMethod != null)
				de.raiseMethod = (IMethod)raiseMethod.Clone();
			return de;
		}
Exemple #5
0
        public override IMember Clone()
        {
            DefaultEvent de = new DefaultEvent(Name, ReturnType, Modifiers, Region, BodyRegion, DeclaringType);

            de.CopyDocumentationFrom(this);
            foreach (ExplicitInterfaceImplementation eii in InterfaceImplementations)
            {
                de.InterfaceImplementations.Add(eii.Clone());
            }
            if (addMethod != null)
            {
                de.addMethod = (IMethod)addMethod.Clone();
            }
            if (removeMethod != null)
            {
                de.removeMethod = (IMethod)removeMethod.Clone();
            }
            if (raiseMethod != null)
            {
                de.raiseMethod = (IMethod)raiseMethod.Clone();
            }
            return(de);
        }
Exemple #6
0
            void InitMembers(TypeDefinition type)
            {
                string defaultMemberName = null;
                foreach (CustomAttribute att in type.CustomAttributes) {
                    if (att.Constructor.DeclaringType.FullName == "System.Reflection.DefaultMemberAttribute"
                        && att.Constructor.Parameters.Count == 1)
                    {
                        defaultMemberName = att.Constructor.Parameters[0].Name;
                    }
                }

                foreach (TypeDefinition nestedType in type.NestedTypes) {
                    TypeAttributes visibility = nestedType.Attributes & TypeAttributes.VisibilityMask;
                    if (visibility == TypeAttributes.NestedPublic || visibility == TypeAttributes.NestedFamily
                        || visibility == TypeAttributes.NestedFamORAssem)
                    {
                        string name = nestedType.Name;
                        int pos = name.LastIndexOf('/');
                        if (pos > 0)
                            name = name.Substring(pos + 1);
                        if (name.Length == 0 || name[0] == '<')
                            continue;
                        name = ReflectionClass.SplitTypeParameterCountFromReflectionName(name);
                        name = this.FullyQualifiedName + "." + name;
                        InnerClasses.Add(new CecilClass(this.CompilationUnit, this, nestedType, name));
                    }
                }

                foreach (FieldDefinition field in type.Fields) {
                    if (IsVisible(field.Attributes) && !field.IsSpecialName) {
                        DefaultField f = new DefaultField(this, field.Name);
                        f.Modifiers = TranslateModifiers(field);
                        f.ReturnType = CreateType(this.ProjectContent, this, field.FieldType);
                        AddAttributes(CompilationUnit.ProjectContent, f.Attributes, field.CustomAttributes);
                        Fields.Add(f);
                    }
                }

                foreach (PropertyDefinition property in type.Properties)
                {
                    AddProperty(defaultMemberName, property);
                }

                foreach (EventDefinition eventDef in type.Events)
                {
                    if (eventDef.AddMethod != null && IsVisible(eventDef.AddMethod.Attributes)) {
                        DefaultEvent e = new DefaultEvent(this, eventDef.Name);
                        if (this.ClassType == ClassType.Interface) {
                            e.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
                        } else {
                            e.Modifiers = TranslateModifiers(eventDef);
                        }
                        e.ReturnType = CreateType(this.ProjectContent, this, eventDef.EventType);
                        AddAttributes(CompilationUnit.ProjectContent, e.Attributes, eventDef.CustomAttributes);
                        Events.Add(e);
                    }
                }

                this.AddDefaultConstructorIfRequired = (this.ClassType == ClassType.Struct || this.ClassType == ClassType.Enum);
                foreach (MethodDefinition method in type.Methods)
                {
                    if (!method.IsSpecialName)
                    {
                        AddMethod(method);
                    }
                }
            }
Exemple #7
0
            void InitMembers(TypeDefinition type)
            {
                string defaultMemberName = null;

                foreach (CustomAttribute att in type.CustomAttributes)
                {
                    if (att.Constructor.DeclaringType.FullName == "System.Reflection.DefaultMemberAttribute" &&
                        att.ConstructorParameters.Count == 1)
                    {
                        defaultMemberName = att.ConstructorParameters[0] as string;
                    }
                }

                foreach (TypeDefinition nestedType in type.NestedTypes)
                {
                    TypeAttributes visibility = nestedType.Attributes & TypeAttributes.VisibilityMask;
                    if (visibility == TypeAttributes.NestedPublic || visibility == TypeAttributes.NestedFamily ||
                        visibility == TypeAttributes.NestedFamORAssem)
                    {
                        string name = nestedType.Name;
                        int    pos  = name.LastIndexOf('/');
                        if (pos > 0)
                        {
                            name = name.Substring(pos + 1);
                        }
                        if (name.Length == 0 || name[0] == '<')
                        {
                            continue;
                        }
                        if (name.Length > 2 && name[name.Length - 2] == '`')
                        {
                            name = name.Substring(0, name.Length - 2);
                        }
                        name = this.FullyQualifiedName + "." + name;
                        InnerClasses.Add(new CecilClass(this.CompilationUnit, this, nestedType, name));
                    }
                }

                foreach (FieldDefinition field in type.Fields)
                {
                    if (IsVisible(field.Attributes) && !field.IsSpecialName)
                    {
                        DefaultField f = new DefaultField(this, field.Name);
                        f.Modifiers  = TranslateModifiers(field);
                        f.ReturnType = CreateType(this.ProjectContent, this, field.FieldType);
                        Fields.Add(f);
                    }
                }

                foreach (PropertyDefinition property in type.Properties)
                {
                    if ((property.GetMethod != null && IsVisible(property.GetMethod.Attributes)) ||
                        (property.SetMethod != null && IsVisible(property.SetMethod.Attributes)))
                    {
                        DefaultProperty p = new DefaultProperty(this, property.Name);
                        if (this.ClassType == ClassType.Interface)
                        {
                            p.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
                        }
                        else
                        {
                            p.Modifiers = TranslateModifiers(property);
                        }
                        p.ReturnType = CreateType(this.ProjectContent, this, property.PropertyType);
                        p.CanGet     = property.GetMethod != null;
                        p.CanSet     = property.SetMethod != null;
                        if (p.Name == defaultMemberName)
                        {
                            p.IsIndexer = true;
                        }
                        AddParameters(p, property.Parameters);
                        Properties.Add(p);
                    }
                }

                foreach (EventDefinition eventDef in type.Events)
                {
                    if (eventDef.AddMethod != null && IsVisible(eventDef.AddMethod.Attributes))
                    {
                        DefaultEvent e = new DefaultEvent(this, eventDef.Name);
                        if (this.ClassType == ClassType.Interface)
                        {
                            e.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
                        }
                        else
                        {
                            e.Modifiers = TranslateModifiers(eventDef);
                        }
                        e.ReturnType = CreateType(this.ProjectContent, this, eventDef.EventType);
                        Events.Add(e);
                    }
                }

                foreach (MethodDefinition method in type.Constructors)
                {
                    AddMethod(method);
                }
                foreach (MethodDefinition method in type.Methods)
                {
                    if (!method.IsSpecialName)
                    {
                        AddMethod(method);
                    }
                }
            }
		public override object VisitEventDeclaration(NRefactoryAST.EventDeclaration eventDeclaration, object data)
		{
			DomRegion region     = GetRegion(eventDeclaration.StartLocation, eventDeclaration.EndLocation);
			DomRegion bodyRegion = GetRegion(eventDeclaration.BodyStart,     eventDeclaration.BodyEnd);
			DefaultClass c = GetCurrentClass();
			
			IReturnType type;
			if (eventDeclaration.TypeReference.IsNull) {
				DefaultClass del = new DefaultClass(cu, ClassType.Delegate,
				                                    ConvertModifier(eventDeclaration.Modifier),
				                                    region, c);
				del.Modifiers |= ModifierEnum.Synthetic;
				CreateDelegate(del, eventDeclaration.Name + "EventHandler",
				               new NRefactoryAST.TypeReference("System.Void", true),
				               new NRefactoryAST.TemplateDefinition[0],
				               eventDeclaration.Parameters);
				type = del.DefaultReturnType;
			} else {
				type = CreateReturnType(eventDeclaration.TypeReference);
			}
			DefaultEvent e = new DefaultEvent(eventDeclaration.Name, type, ConvertModifier(eventDeclaration.Modifier), region, bodyRegion, c);
			ConvertAttributes(eventDeclaration, e);
			c.Events.Add(e);
			
			e.Documentation = GetDocumentation(region.BeginLine, eventDeclaration.Attributes);
			if (eventDeclaration.HasAddRegion) {
				e.AddMethod = new DefaultMethod(e.DeclaringType, "add_" + e.Name) {
					Parameters = { new DefaultParameter("value", e.ReturnType, DomRegion.Empty) },
					Region = GetRegion(eventDeclaration.AddRegion.StartLocation, eventDeclaration.AddRegion.EndLocation),
					BodyRegion = GetRegion(eventDeclaration.AddRegion.Block.StartLocation, eventDeclaration.AddRegion.Block.EndLocation)
				};
			}
			if (eventDeclaration.HasRemoveRegion) {
				e.RemoveMethod = new DefaultMethod(e.DeclaringType, "remove_" + e.Name) {
					Parameters = { new DefaultParameter("value", e.ReturnType, DomRegion.Empty) },
					Region = GetRegion(eventDeclaration.RemoveRegion.StartLocation, eventDeclaration.RemoveRegion.EndLocation),
					BodyRegion = GetRegion(eventDeclaration.RemoveRegion.Block.StartLocation, eventDeclaration.RemoveRegion.Block.EndLocation)
				};
			}
			return null;
		}
			IEvent ReadEvent()
			{
				DefaultEvent p = new DefaultEvent(currentClass, ReadString());
				ReadMember(p);
				return p;
			}
			void InitMembers(TypeDefinition type)
			{
				string defaultMemberName = null;
				foreach (CustomAttribute att in type.CustomAttributes) {
					if (att.Constructor.DeclaringType.FullName == "System.Reflection.DefaultMemberAttribute"
					    && att.ConstructorParameters.Count == 1)
					{
						defaultMemberName = att.ConstructorParameters[0] as string;
					}
				}
				
				foreach (TypeDefinition nestedType in type.NestedTypes) {
					TypeAttributes visibility = nestedType.Attributes & TypeAttributes.VisibilityMask;
					if (visibility == TypeAttributes.NestedPublic || visibility == TypeAttributes.NestedFamily
					    || visibility == TypeAttributes.NestedFamORAssem)
					{
						string name = nestedType.Name;
						int pos = name.LastIndexOf('/');
						if (pos > 0)
							name = name.Substring(pos + 1);
						if (name.Length == 0 || name[0] == '<')
							continue;
						if (name.Length > 2 && name[name.Length - 2] == '`')
							name = name.Substring(0, name.Length - 2);
						name = this.FullyQualifiedName + "." + name;
						InnerClasses.Add(new CecilClass(this.CompilationUnit, this, nestedType, name));
					}
				}
				
				foreach (FieldDefinition field in type.Fields) {
					if (IsVisible(field.Attributes) && !field.IsSpecialName) {
						DefaultField f = new DefaultField(this, field.Name);
						f.Modifiers = TranslateModifiers(field);
						f.ReturnType = CreateType(this.ProjectContent, this, field.FieldType);
						Fields.Add(f);
					}
				}
				
				foreach (PropertyDefinition property in type.Properties) {
					if ((property.GetMethod != null && IsVisible(property.GetMethod.Attributes))
					    || (property.SetMethod != null && IsVisible(property.SetMethod.Attributes)))
					{
						DefaultProperty p = new DefaultProperty(this, property.Name);
						if (this.ClassType == ClassType.Interface) {
							p.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
						} else {
							p.Modifiers = TranslateModifiers(property);
						}
						p.ReturnType = CreateType(this.ProjectContent, this, property.PropertyType);
						p.CanGet = property.GetMethod != null;
						p.CanSet = property.SetMethod != null;
						if (p.Name == defaultMemberName) {
							p.IsIndexer = true;
						}
						AddParameters(p, property.Parameters);
						Properties.Add(p);
					}
				}
				
				foreach (EventDefinition eventDef in type.Events) {
					if (eventDef.AddMethod != null && IsVisible(eventDef.AddMethod.Attributes)) {
						DefaultEvent e = new DefaultEvent(this, eventDef.Name);
						if (this.ClassType == ClassType.Interface) {
							e.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
						} else {
							e.Modifiers = TranslateModifiers(eventDef);
						}
						e.ReturnType = CreateType(this.ProjectContent, this, eventDef.EventType);
						Events.Add(e);
					}
				}
				
				foreach (MethodDefinition method in type.Constructors) {
					AddMethod(method);
				}
				foreach (MethodDefinition method in type.Methods) {
					if (!method.IsSpecialName) {
						AddMethod(method);
					}
				}
			}
Exemple #11
0
            void InitMembers(TypeDefinition type)
            {
                string defaultMemberName = null;

                foreach (CustomAttribute att in type.CustomAttributes)
                {
                    if (att.Constructor.DeclaringType.FullName == "System.Reflection.DefaultMemberAttribute" &&
                        att.ConstructorArguments.Count == 1)
                    {
                        defaultMemberName = att.ConstructorArguments[0].Value as string;
                    }
                }

                foreach (TypeDefinition nestedType in type.NestedTypes)
                {
                    TypeAttributes visibility = nestedType.Attributes & TypeAttributes.VisibilityMask;
                    if (visibility == TypeAttributes.NestedPublic || visibility == TypeAttributes.NestedFamily ||
                        visibility == TypeAttributes.NestedFamORAssem)
                    {
                        string name = nestedType.Name;
                        int    pos  = name.LastIndexOf('/');
                        if (pos > 0)
                        {
                            name = name.Substring(pos + 1);
                        }
                        if (name.Length == 0 || name[0] == '<')
                        {
                            continue;
                        }
                        name = ReflectionClass.SplitTypeParameterCountFromReflectionName(name);
                        name = this.FullyQualifiedName + "." + name;
                        InnerClasses.Add(new CecilClass(this.CompilationUnit, this, nestedType, name));
                    }
                }

                foreach (FieldDefinition field in type.Fields)
                {
                    if (IsVisible(field.Attributes) && !field.IsSpecialName)
                    {
                        DefaultField f = new DefaultField(this, field.Name);
                        f.Modifiers  = TranslateModifiers(field);
                        f.ReturnType = CreateType(this.ProjectContent, this, field.FieldType, field);
                        AddAttributes(CompilationUnit.ProjectContent, f, f.Attributes, field);
                        Fields.Add(f);
                    }
                }

                foreach (PropertyDefinition property in type.Properties)
                {
                    AddProperty(defaultMemberName, property);
                }

                foreach (EventDefinition eventDef in type.Events)
                {
                    if (eventDef.AddMethod != null && IsVisible(eventDef.AddMethod.Attributes))
                    {
                        DefaultEvent e = new DefaultEvent(this, eventDef.Name);
                        if (this.ClassType == ClassType.Interface)
                        {
                            e.Modifiers = ModifierEnum.Public | ModifierEnum.Abstract;
                        }
                        else
                        {
                            e.Modifiers = TranslateModifiers(eventDef);
                        }
                        e.ReturnType = CreateType(this.ProjectContent, this, eventDef.EventType, eventDef);
                        AddAttributes(CompilationUnit.ProjectContent, e, e.Attributes, eventDef);
                        Events.Add(e);
                    }
                }

                this.AddDefaultConstructorIfRequired = (this.ClassType == ClassType.Struct || this.ClassType == ClassType.Enum);
                foreach (MethodDefinition method in type.Methods)
                {
                    if (method.IsConstructor || !method.IsSpecialName)
                    {
                        AddMethod(method);
                    }
                }
            }
		public override void OnEvent(AST.Event node)
		{
			DomRegion region = GetRegion(node);
			DefaultEvent e = new DefaultEvent(node.Name, CreateReturnType(node.Type), GetModifier(node), region, region, OuterClass);
			ConvertAttributes(node, e);
			OuterClass.Events.Add(e);
		}
Exemple #13
0
		public DefaultEvent AddEvent(string name)
		{
			DefaultEvent classEvent = new DefaultEvent(this, name);
			Events.Add(classEvent);
			return classEvent;
		}
Exemple #14
0
        /// <summary>
        /// Makes a copy of <c>oldClass</c>.
        /// </summary>
        /// <param name="oldClass">Class to be copied.</param>
        /// <returns>Copy of the class.</returns>
        private IClass copyClass(IClass oldClass)
        {
            DefaultClass newClass = new DefaultClass(oldClass.CompilationUnit,oldClass.FullyQualifiedName);
            newClass.Modifiers = oldClass.Modifiers;
            foreach (ITypeParameter element in oldClass.TypeParameters) {
                newClass.TypeParameters.Add(element);
            }
            // Recursively copy inner classes.
            foreach(IClass element in oldClass.InnerClasses){
                newClass.InnerClasses.Add(copyClass(element));
            }

            // Copy events.
            foreach(IEvent element in oldClass.Events){
                DefaultEvent newEvent = new DefaultEvent(element.Name,element.ReturnType,element.Modifiers,
                                                        element.Region,element.BodyRegion,newClass);
                newClass.Events.Add(newEvent);
            }

            //Copy properties
            foreach(IProperty element in oldClass.Properties){
                DefaultProperty newProperty = new DefaultProperty(element.Name,element.ReturnType,
                                                          element.Modifiers,element.Region,element.BodyRegion,newClass);
                newClass.Properties.Add(newProperty);
            }

            //Copy methods.

            copyMethods(oldClass,newClass);
            copyFields(oldClass,newClass);

            return newClass;
        }
		MemberResolveResult ResolvePropertyName(IReturnType resolvedType, string propertyName, bool allowAttached)
		{
			IMember member = resolvedType.GetProperties().Find(delegate(IProperty p) { return p.Name == propertyName; });
			if (member == null) {
				member = resolvedType.GetEvents().Find(delegate(IEvent p) { return p.Name == propertyName; });
			}
			if (member == null && allowAttached) {
				IMethod method = resolvedType.GetMethods().Find(
					delegate(IMethod p) {
						return p.IsStatic && p.Parameters.Count == 1 && p.Name == "Get" + propertyName;
					});
				member = method;
				if (member != null) {
					member = new DefaultProperty(resolvedType.GetUnderlyingClass(), propertyName) { ReturnType = method.ReturnType };
				} else {
					IMethod m = resolvedType.GetMethods().Find(
						delegate(IMethod p) {
							return p.IsPublic && p.IsStatic && p.Parameters.Count == 2 && (p.Name == "Add" + propertyName + "Handler" || p.Name == "Remove" + propertyName + "Handler");
						});
					member = m;
					if (member != null)
						member = new DefaultEvent(resolvedType.GetUnderlyingClass(), propertyName) { ReturnType = m.Parameters[1].ReturnType };
				}
			}
			if (member != null)
				return new MemberResolveResult(callingClass, null, member);
			return null;
		}