Exemplo n.º 1
0
		public AnalyzedPropertyTreeNode(PropertyDefinition analyzedProperty, string prefix = "")
		{
			if (analyzedProperty == null)
				throw new ArgumentNullException("analyzedProperty");
			this.isIndexer = analyzedProperty.IsIndexer();
			this.analyzedProperty = analyzedProperty;
			this.prefix = prefix;
			this.LazyLoading = true;
		}
Exemplo n.º 2
0
        public PropertyTreeNode(PropertyDefinition property)
        {
            if (property == null)
                throw new ArgumentNullException("property");
            this.property = property;
            using (LoadedAssembly.DisableAssemblyLoad()) {
                this.isIndexer = property.IsIndexer();
            }

            if (property.GetMethod != null)
                this.Children.Add(new MethodTreeNode(property.GetMethod));
            if (property.SetMethod != null)
                this.Children.Add(new MethodTreeNode(property.SetMethod));
            if (property.HasOtherMethods) {
                foreach (var m in property.OtherMethods)
                    this.Children.Add(new MethodTreeNode(m));
            }
        }
		protected override void WritePropertyDeclaration(PropertyDefinition property)
		{
			MethodDefinition moreVisibleMethod = property.GetMethod.GetMoreVisibleMethod(property.SetMethod);
			if (property.IsIndexer())
			{
				WriteIndexerKeywords();
			}

			if (this.ModuleContext.RenamedMembers.Contains(property.MetadataToken.ToUInt32()))
			{
				WriteComment(property.Name);
				WriteLine();
			}

			if (!property.IsExplicitImplementation())
			{
				WriteMethodVisibilityAndSpace(moreVisibleMethod);
			}

			if (!(property.IsVirtual() && !property.IsNewSlot()))
			{
				bool isIndexerProperty = property.IsIndexer();

				if ((isIndexerProperty && IsIndexerPropertyHiding(property)) || (!isIndexerProperty && IsPropertyHiding(property)))
				{
					WriteKeyword(KeyWordWriter.Hiding);
					WriteSpace();
				}
			}

			if (property.IsVirtual() && !property.DeclaringType.IsInterface)
			{
				if (WritePropertyKeywords(property))
				{
					WriteSpace();
				}
			}

			//covers the case of properties with only one of the get/set methods in VB
			WriteReadOnlyWriteOnlyProperty(property);

			if (property.IsStatic())
			{
				WriteKeyword(KeyWordWriter.Static);
				WriteSpace();
			}

			if (KeyWordWriter.Property != null)
			{
				WriteKeyword(KeyWordWriter.Property);
				WriteSpace();
			}

			if (property.IsIndexer())
			{
				if (WritePropertyAsIndexer(property))
				{
					return;
				}
			}

			WritePropertyTypeAndNameWithArguments(property);

			WritePropertyInterfaceImplementations(property);
		}
Exemplo n.º 4
0
		public override string FormatPropertyName(PropertyDefinition property, bool? isIndexer)
		{
			if (property == null)
				throw new ArgumentNullException("property");

			if (!isIndexer.HasValue) {
				isIndexer = property.IsIndexer();
			}
			if (isIndexer.Value) {
				var buffer = new System.Text.StringBuilder();
				var accessor = property.GetMethod ?? property.SetMethod;
				if (accessor.HasOverrides) {
					var declaringType = accessor.Overrides.First().DeclaringType;
					buffer.Append(TypeToString(declaringType, includeNamespace: true));
					buffer.Append(@".");
				}
				buffer.Append(@"this[");
				bool addSeparator = false;
				foreach (var p in property.Parameters) {
					if (addSeparator)
						buffer.Append(@", ");
					else
						addSeparator = true;
					buffer.Append(TypeToString(p.ParameterType, includeNamespace: true));
				}
				buffer.Append(@"]");
				return buffer.ToString();
			} else
				return property.Name;
		}
Exemplo n.º 5
0
		ImageSource GetOverlayedImage(PropertyDefinition propDef, MemberIcon icon)
		{
			bool isStatic = false;
			AccessOverlayIcon overlayIcon = AccessOverlayIcon.Public;
			
			return Images.GetIcon(propDef.IsIndexer() ? MemberIcon.Indexer : icon, overlayIcon, isStatic);
		}
Exemplo n.º 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;
		}