PropertyDeclaration ConvertProperty(IProperty property)
 {
     PropertyDeclaration decl = new PropertyDeclaration();
     decl.Modifiers = GetMemberModifiers(property);
     if (ShowAttributes) {
         decl.Attributes.AddRange (property.Attributes.Select ((a) => new AttributeSection (ConvertAttribute (a))));
     }
     if (AddResolveResultAnnotations) {
         decl.AddAnnotation(new MemberResolveResult(null, property));
     }
     decl.ReturnType = ConvertType(property.ReturnType);
     decl.Name = property.Name;
     decl.Getter = ConvertAccessor(property.Getter, property.Accessibility, false);
     decl.Setter = ConvertAccessor(property.Setter, property.Accessibility, true);
     decl.PrivateImplementationType = GetExplicitInterfaceType (property);
     return decl;
 }
Example #2
0
		PropertyDeclaration CreateProperty(PropertyDefinition propDef)
		{
			PropertyDeclaration astProp = new PropertyDeclaration();
			astProp.AddAnnotation(propDef);
			var accessor = propDef.GetMethod ?? propDef.SetMethod;
			Modifiers getterModifiers = Modifiers.None;
			Modifiers setterModifiers = Modifiers.None;
			if (!propDef.DeclaringType.IsInterface && !accessor.HasOverrides) {
				getterModifiers = ConvertModifiers(propDef.GetMethod);
				setterModifiers = ConvertModifiers(propDef.SetMethod);
				astProp.Modifiers = FixUpVisibility(getterModifiers | setterModifiers);
			} else if (accessor.HasOverrides) {
				astProp.PrivateImplementationType = ConvertType(accessor.Overrides.First().DeclaringType);
			}
			astProp.Name = CleanName(propDef.Name);
			astProp.ReturnType = ConvertType(propDef.PropertyType, propDef);
			if (propDef.GetMethod != null) {
				astProp.Getter = new Accessor();
				astProp.Getter.Body = AstMethodBodyBuilder.CreateMethodBody(propDef.GetMethod, context);
				astProp.AddAnnotation(propDef.GetMethod);
				ConvertAttributes(astProp.Getter, propDef.GetMethod);
				
				if ((getterModifiers & Modifiers.VisibilityMask) != (astProp.Modifiers & Modifiers.VisibilityMask))
					astProp.Getter.Modifiers = getterModifiers & Modifiers.VisibilityMask;
			}
			if (propDef.SetMethod != null) {
				astProp.Setter = new Accessor();
				astProp.Setter.Body = AstMethodBodyBuilder.CreateMethodBody(propDef.SetMethod, context);
				astProp.Setter.AddAnnotation(propDef.SetMethod);
				ConvertAttributes(astProp.Setter, propDef.SetMethod);
				ConvertCustomAttributes(astProp.Setter, propDef.SetMethod.Parameters.Last(), AttributeTarget.Param);
				
				if ((setterModifiers & Modifiers.VisibilityMask) != (astProp.Modifiers & Modifiers.VisibilityMask))
					astProp.Setter.Modifiers = setterModifiers & Modifiers.VisibilityMask;
			}
			ConvertCustomAttributes(astProp, propDef);
			return astProp;
		}
 PropertyDeclaration ConvertProperty(IProperty property)
 {
     PropertyDeclaration decl = new PropertyDeclaration();
     decl.Modifiers = GetMemberModifiers(property);
     if (ShowAttributes) {
         decl.Attributes.AddRange (property.Attributes.Select ((a) => new AttributeSection (ConvertAttribute (a))));
     }
     if (AddResolveResultAnnotations) {
         decl.AddAnnotation(new MemberResolveResult(null, property));
     }
     decl.ReturnType = ConvertType(property.ReturnType);
     decl.Name = property.Name;
     decl.Getter = ConvertAccessor(property.Getter, property.Accessibility, false);
     decl.Setter = ConvertAccessor(property.Setter, property.Accessibility, true);
     decl.PrivateImplementationType = GetExplicitInterfaceType (property);
     return decl;
 }
Example #4
0
 PropertyDeclaration CreateProperty(PropertyDefinition propDef)
 {
     PropertyDeclaration astProp = new PropertyDeclaration();
     astProp.AddAnnotation(propDef);
     astProp.Modifiers = ConvertModifiers(propDef.GetMethod ?? propDef.SetMethod);
     astProp.Name = propDef.Name;
     astProp.ReturnType = ConvertType(propDef.PropertyType, propDef);
     if (propDef.GetMethod != null) {
         astProp.Getter = new Accessor {
             Body = AstMethodBodyBuilder.CreateMethodBody(propDef.GetMethod, context)
         }.WithAnnotation(propDef.GetMethod);
     }
     if (propDef.SetMethod != null) {
         astProp.Setter = new Accessor {
             Body = AstMethodBodyBuilder.CreateMethodBody(propDef.SetMethod, context)
         }.WithAnnotation(propDef.SetMethod);
     }
     return astProp;
 }
Example #5
0
		PropertyDeclaration CreateProperty(PropertyDefinition propDef)
		{
			PropertyDeclaration astProp = new PropertyDeclaration();
			astProp.AddAnnotation(propDef);
			astProp.Modifiers = ConvertModifiers(propDef.GetMethod ?? propDef.SetMethod);
			astProp.Name = CleanName(propDef.Name);
			astProp.ReturnType = ConvertType(propDef.PropertyType, propDef);
			if (propDef.GetMethod != null) {
				astProp.Getter = new Accessor {
					Body = AstMethodBodyBuilder.CreateMethodBody(propDef.GetMethod, context)
				}.WithAnnotation(propDef.GetMethod);
				ConvertCustomAttributes(astProp.Getter, propDef.GetMethod);
				ConvertCustomAttributes(astProp.Getter, propDef.GetMethod.MethodReturnType, AttributeTarget.Return);
			}
			if (propDef.SetMethod != null) {
				astProp.Setter = new Accessor {
					Body = AstMethodBodyBuilder.CreateMethodBody(propDef.SetMethod, context)
				}.WithAnnotation(propDef.SetMethod);
				ConvertCustomAttributes(astProp.Setter, propDef.SetMethod);
				ConvertCustomAttributes(astProp.Setter, propDef.SetMethod.MethodReturnType, AttributeTarget.Return);
				ConvertCustomAttributes(astProp.Setter, propDef.SetMethod.Parameters.Last(), AttributeTarget.Param);
			}
			ConvertCustomAttributes(astProp, propDef);
			return astProp;
		}
Example #6
0
		MemberDeclaration CreateProperty(PropertyDefinition propDef)
		{
			PropertyDeclaration astProp = new PropertyDeclaration();
			astProp.AddAnnotation(propDef);
			var accessor = propDef.GetMethod ?? propDef.SetMethod;
			Modifiers getterModifiers = Modifiers.None;
			Modifiers setterModifiers = Modifiers.None;
			if (accessor.HasOverrides) {
				astProp.PrivateImplementationType = ConvertType(accessor.Overrides.First().DeclaringType);
			} else if (!propDef.DeclaringType.IsInterface) {
				getterModifiers = ConvertModifiers(propDef.GetMethod);
				setterModifiers = ConvertModifiers(propDef.SetMethod);
				astProp.Modifiers = FixUpVisibility(getterModifiers | setterModifiers);
				try {
					if (accessor.IsVirtual && !accessor.IsNewSlot && (propDef.GetMethod == null || propDef.SetMethod == null)) {
						foreach (var basePropDef in TypesHierarchyHelpers.FindBaseProperties(propDef)) {
							if (basePropDef.GetMethod != null && basePropDef.SetMethod != null) {
								var propVisibilityModifiers = ConvertModifiers(basePropDef.GetMethod) | ConvertModifiers(basePropDef.SetMethod);
								astProp.Modifiers = FixUpVisibility((astProp.Modifiers & ~Modifiers.VisibilityMask) | (propVisibilityModifiers & Modifiers.VisibilityMask));
								break;
							} else if ((basePropDef.GetMethod ?? basePropDef.SetMethod).IsNewSlot) {
								break;
							}
						}
					}
					if (accessor.IsVirtual ^ !accessor.IsNewSlot) {
						if (TypesHierarchyHelpers.FindBaseProperties(propDef).Any())
							astProp.Modifiers |= Modifiers.New;
					}
				} catch (ReferenceResolvingException) {
					// TODO: add some kind of notification (a comment?) about possible problems with decompiled code due to unresolved references.
				}
			}
			astProp.Name = CleanName(propDef.Name);
			astProp.ReturnType = ConvertType(propDef.PropertyType, propDef);
			if (propDef.GetMethod != null) {
				// Create mapping - used in debugger
				MemberMapping methodMapping = propDef.GetMethod.CreateCodeMapping(this.CodeMappings);
				
				astProp.Getter = new Accessor();
				astProp.Getter.Body = CreateMethodBody(propDef.GetMethod);
				astProp.AddAnnotation(propDef.GetMethod);
				ConvertAttributes(astProp.Getter, propDef.GetMethod);
				
				if ((getterModifiers & Modifiers.VisibilityMask) != (astProp.Modifiers & Modifiers.VisibilityMask))
					astProp.Getter.Modifiers = getterModifiers & Modifiers.VisibilityMask;
				
				astProp.Getter.WithAnnotation(methodMapping);
			}
			if (propDef.SetMethod != null) {
				// Create mapping - used in debugger
				MemberMapping methodMapping = propDef.SetMethod.CreateCodeMapping(this.CodeMappings);
				
				astProp.Setter = new Accessor();
				astProp.Setter.Body = CreateMethodBody(propDef.SetMethod);
				astProp.Setter.AddAnnotation(propDef.SetMethod);
				ConvertAttributes(astProp.Setter, propDef.SetMethod);
				ConvertCustomAttributes(astProp.Setter, propDef.SetMethod.Parameters.Last(), "param");
				
				if ((setterModifiers & Modifiers.VisibilityMask) != (astProp.Modifiers & Modifiers.VisibilityMask))
					astProp.Setter.Modifiers = setterModifiers & Modifiers.VisibilityMask;
				
				astProp.Setter.WithAnnotation(methodMapping);
			}
			ConvertCustomAttributes(astProp, propDef);
			
			if(propDef.IsIndexer())
				return ConvertPropertyToIndexer(astProp, propDef);
			else
				return astProp;
		}