示例#1
1
        /// <summary>
        /// Finds all properties from base types overridden or hidden by the specified property.
        /// </summary>
        /// <param name="property">The property which overrides or hides properties from base types.</param>
        /// <returns>Properties overriden or hidden by the specified property.</returns>
        public static IEnumerable<PropertyDef> FindBaseProperties(PropertyDef property)
        {
            if (property == null)
                yield break;

            var accMeth = property.GetMethod ?? property.SetMethod;
            if (accMeth != null && accMeth.HasOverrides)
                yield break;

            bool isIndexer = property.IsIndexer();

            foreach (var baseType in BaseTypes(property.DeclaringType)) {
                var baseTypeDef = baseType.Resolve();
                if (baseTypeDef == null)
                    continue;
                foreach (var baseProperty in baseTypeDef.Properties) {
                    if (MatchProperty(baseProperty, Resolve(baseProperty.PropertySig, baseType), property)
                            && IsVisibleFromDerived(baseProperty, property.DeclaringType)) {
                        if (isIndexer != baseProperty.IsIndexer())
                            continue;
                        yield return baseProperty;
                        var anyPropertyAccessor = baseProperty.GetMethod ?? baseProperty.SetMethod;
                        if (anyPropertyAccessor != null && anyPropertyAccessor.IsNewSlot == anyPropertyAccessor.IsVirtual)
                            yield break;
                    }
                }
            }
        }
        public AnalyzedPropertyOverridesTreeNode(PropertyDef analyzedProperty)
        {
            if (analyzedProperty == null)
                throw new ArgumentNullException("analyzedProperty");

            this.analyzedProperty = analyzedProperty;
        }
		public InterfacePropertyImplementedByNode(PropertyDef analyzedProperty) {
			if (analyzedProperty == null)
				throw new ArgumentNullException(nameof(analyzedProperty));

			this.analyzedProperty = analyzedProperty;
			analyzedMethod = this.analyzedProperty.GetMethod ?? this.analyzedProperty.SetMethod;
		}
		public AnalyzedInterfacePropertyImplementedByTreeNode(PropertyDef analyzedProperty) {
			if (analyzedProperty == null)
				throw new ArgumentNullException("analyzedProperty");

			this.analyzedProperty = analyzedProperty;
			this.analyzedMethod = this.analyzedProperty.GetMethod ?? this.analyzedProperty.SetMethod;
		}
示例#5
0
		public PropertyNode(PropertyDef analyzedProperty, bool hidesParent = false) {
			if (analyzedProperty == null)
				throw new ArgumentNullException(nameof(analyzedProperty));
			isIndexer = analyzedProperty.IsIndexer();
			this.analyzedProperty = analyzedProperty;
			this.hidesParent = hidesParent;
		}
		public DeletedPropertyUpdater(ModuleDocumentNode modNode, PropertyDef originalProperty) {
			ownerNode = modNode.Context.DocumentTreeView.FindNode(originalProperty);
			if (ownerNode == null)
				throw new InvalidOperationException();
			parentNode = ownerNode.TreeNode.Parent.Data;
			ownerType = originalProperty.DeclaringType;
			property = originalProperty;
		}
		public AnalyzedPropertyTreeNode(PropertyDef analyzedProperty, bool hidesParent = false) {
			if (analyzedProperty == null)
				throw new ArgumentNullException("analyzedProperty");
			this.isIndexer = analyzedProperty.IsIndexer();
			this.analyzedProperty = analyzedProperty;
			this.hidesParent = hidesParent;
			this.LazyLoading = true;
		}
		public EditedPropertyUpdater(ModuleDocumentNode modNode, PropertyDef originalProperty, PropertyDefOptions propertyDefOptions) {
			ownerNode = modNode.Context.DocumentTreeView.FindNode(originalProperty);
			if (ownerNode == null)
				throw new InvalidOperationException();
			property = originalProperty;
			originalPropertyDefOptions = new PropertyDefOptions(originalProperty);
			newPropertyDefOptions = propertyDefOptions;
		}
 public AnalyzedPropertyTreeNode(PropertyDef analyzedProperty, string prefix = "")
 {
     if (analyzedProperty == null)
         throw new ArgumentNullException("analyzedProperty");
     this.isIndexer = analyzedProperty.IsIndexer();
     this.analyzedProperty = analyzedProperty;
     this.prefix = prefix;
     this.LazyLoading = true;
 }
示例#10
0
		public static IEnumerable<IMemberDef> GetMethodsAndSelf(PropertyDef p) {
			yield return p;
			foreach (var m in p.GetMethods)
				yield return m;
			foreach (var m in p.SetMethods)
				yield return m;
			foreach (var m in p.OtherMethods)
				yield return m;
		}
示例#11
0
		public static ITextOutput Write(ITextOutput output, PropertyDef property, Language language, bool? isIndexer = null) {
			language.FormatPropertyName(output, property, isIndexer);
			output.WriteSpace();
			output.Write(':', TextTokenType.Operator);
			output.WriteSpace();
			language.TypeToString(output, property.PropertySig.GetRetType().ToTypeDefOrRef(), false, property);
			property.MDToken.WriteSuffixString(output);
			return output;
		}
示例#12
0
		public PropertyDefOptions(PropertyDef prop) {
			this.Attributes = prop.Attributes;
			this.Name = prop.Name;
			this.PropertySig = prop.PropertySig;
			this.Constant = prop.Constant;
			this.GetMethods.AddRange(prop.GetMethods);
			this.SetMethods.AddRange(prop.SetMethods);
			this.OtherMethods.AddRange(prop.OtherMethods);
			this.CustomAttributes.AddRange(prop.CustomAttributes);
		}
示例#13
0
		public PropertyDefOptions(PropertyDef prop) {
			Attributes = prop.Attributes;
			Name = prop.Name;
			PropertySig = prop.PropertySig;
			Constant = prop.Constant;
			GetMethods.AddRange(prop.GetMethods);
			SetMethods.AddRange(prop.SetMethods);
			OtherMethods.AddRange(prop.OtherMethods);
			CustomAttributes.AddRange(prop.CustomAttributes);
		}
示例#14
0
        private static string ResolveRawName(dnlib.DotNet.PropertyDef source)
        {
            var rawName =
                source.FullName.AsSpan(source.FullName.IndexOf(' ', StringComparison.InvariantCultureIgnoreCase) + 1);

            rawName = rawName.Slice(0, rawName.LastIndexOf("(", StringComparison.InvariantCultureIgnoreCase));

            return(rawName.ToString()
                   .Replace("::", ".", StringComparison.InvariantCultureIgnoreCase)
                   .Replace("/", ".", StringComparison.InvariantCultureIgnoreCase));
        }
示例#15
0
 private static bool ExtractIsReadOnly(dnlib.DotNet.PropertyDef source)
 {
     return((source.GetMethod?
             .CustomAttributes
             .Any(x => x.TypeFullName.Equals("System.Runtime.CompilerServices.IsReadOnlyAttribute", StringComparison.InvariantCultureIgnoreCase)) ?? false) &&
            (source.GetMethod?
             .CustomAttributes
             // ReSharper disable once ConstantNullCoalescingCondition
             .All(x => !x.TypeFullName.Equals("System.Runtime.CompilerServices.CompilerGeneratedAttribute", StringComparison.InvariantCultureIgnoreCase)) ?? false
            ));
 }
        public bool PropertyEquals(PropertyDef pd, PropertyInfo pi)
        {
            if (!MemberEquals(pd, pi) || TypeEquals(pd.PropertySig.RetType, pi.PropertyType) || (int)pd.Attributes != (int)pi.Attributes)
                return false;

            var gm = pi.GetGetMethod();
            var sm = pi.GetSetMethod();

            if (gm == null ^ pd.GetMethod == null) return false;
            if (sm == null ^ pd.SetMethod == null) return false;

            return (gm == null || MethodEquals(pd.GetMethod, gm))
                && (sm == null || MethodEquals(pd.SetMethod, sm));
        }
示例#17
0
        internal static PropertyDef?Initialize(Resolver resolver, dnlib.DotNet.PropertyDef source)
        {
            // Select non-private property methods
            var methods = source.SetMethods.Concat(source.GetMethods).Where(x => !x.IsPrivate).ToArray();

            // If no methods were selected..
            if (methods.Length == 0)
            {
                // then this property is invalid
                return(null);
            }
            // Otherwise initialize the property
            return(new PropertyDef(resolver, source, methods));
        }
示例#18
0
		public PropertyDef CopyTo(PropertyDef prop) {
			prop.Attributes = this.Attributes;
			prop.Name = this.Name ?? UTF8String.Empty;
			prop.PropertySig = this.PropertySig;
			prop.Constant = this.Constant;
			prop.GetMethods.Clear();
			prop.GetMethods.AddRange(this.GetMethods);
			prop.SetMethods.Clear();
			prop.SetMethods.AddRange(this.SetMethods);
			prop.OtherMethods.Clear();
			prop.OtherMethods.AddRange(this.OtherMethods);
			prop.CustomAttributes.Clear();
			prop.CustomAttributes.AddRange(CustomAttributes);
			return prop;
		}
示例#19
0
		/// <summary>
		/// Determines whether a property overrides or hides another property.
		/// </summary>
		/// <param name="parentProperty">The property declared in a base type.</param>
		/// <param name="childProperty">The property declared in a derived type.</param>
		/// <returns>true if the <paramref name="childProperty"/> hides or overrides <paramref name="parentProperty"/>,
		/// otherwise false.</returns>
		public static bool IsBaseProperty(PropertyDef parentProperty, PropertyDef childProperty) {
			if (parentProperty == null)
				return false;
			if (childProperty == null)
				return false;

			if (parentProperty.Name != childProperty.Name)
				return false;

			var parentParams = parentProperty.PropertySig.GetParamCount();
			var childParams = childProperty.PropertySig.GetParamCount();
			if (parentParams > 0 || childParams > 0)
				if (parentParams == 0 || childParams == 0 || parentParams != childParams)
					return false;

			return FindBaseProperties(childProperty).Any(m => m == parentProperty);
		}
示例#20
0
        public PropertyTreeNode(PropertyDef 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));
            }
        }
		/// <summary>
		/// Determines whether a property overrides or hides another property.
		/// </summary>
		/// <param name="parentProperty">The property declared in a base type.</param>
		/// <param name="childProperty">The property declared in a derived type.</param>
		/// <returns>true if the <paramref name="childProperty"/> hides or overrides <paramref name="parentProperty"/>,
		/// otherwise false.</returns>
		public static bool IsBaseProperty(PropertyDef parentProperty, PropertyDef childProperty)
		{
			if (parentProperty == null)
				throw new ArgumentNullException("parentProperty");
			if (childProperty == null)
				throw new ArgumentNullException("childProperty");

			if (parentProperty.Name != childProperty.Name)
				return false;

			var parentParams = parentProperty.PropertySig.GetParams();
			var childParams = childProperty.PropertySig.GetParams();
			if (parentParams.Count > 0 || childParams.Count > 0)
				if (parentParams.Count == 0 || childParams.Count == 0 || parentParams.Count != childParams.Count)
					return false;

			return FindBaseProperties(childProperty).Any(m => m == parentProperty);
		}
示例#22
0
        private static TypeSig ResolveType(dnlib.DotNet.PropertyDef source)
        {
            // If the property has a getter method..
            if (source.GetMethod != null)
            {
                // retrieve its return type
                return(source.GetMethod.ReturnType);
            }
            // If the property has a setter method..
            if (source.SetMethod != null)
            {
                // retrieve its input argument
                return(source.SetMethod.Parameters.Last().Type);
            }

            // Property type was not resolved, thus this is not a valid property
            throw new NotSupportedException(Resources.notProperty);
        }
示例#23
0
		public PropertyTreeNode(PropertyDef property, ILSpyTreeNode owner) {
			if (property == null)
				throw new ArgumentNullException("property");
			this.property = property;
			var list = GetDnSpyFileList(owner ?? this);
			using (list == null ? null : list.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));
			}

		}
示例#24
0
        /// <summary>
        /// Default constructor
        /// </summary>
        private PropertyDef(Resolver resolver, dnlib.DotNet.PropertyDef source, dnlib.DotNet.MethodDef[] methods)
            : base(resolver, source)
        {
            var generics = source.ResolvePropertyGenerics(methods);

            Name        = source.Name;
            RawName     = ResolveRawName(source);
            IsStatic    = methods.First().IsStatic;
            Type        = Resolver.Resolve(ResolveType(source), generics, GetMetadata(source));
            Inheritance = ResolveInheritance(methods);
            Accessor    = ResolveAccessor(methods);
            GetAccessor = ResolveAccessor(source.GetMethod);
            SetAccessor = ResolveAccessor(source.SetMethod);
            if (SetAccessor != null)
            {
                var modifierSig = source.SetMethods.First().MethodSig.RetType as ModifierSig;
                IsSetInit = modifierSig?.Modifier.FullName.Equals("System.Runtime.CompilerServices.IsExternalInit") ?? false;
            }

            IsReadOnly = ExtractIsReadOnly(source);
        }
示例#25
0
        private static ParamDef?GetMetadata(dnlib.DotNet.PropertyDef source)
        {
            // If the property has a getter method..
            if (source.GetMethod != null)
            {
                // retrieve its return type
                return(source.GetMethod.ParamDefs.Count != 0
          ? source.GetMethod.ParamDefs.First()
          : null);
            }
            // If the property has a setter method..
            if (source.SetMethod != null)
            {
                // retrieve its input argument
                return(source.SetMethod.Parameters.Count > 1
          ? source.SetMethod.ParamDefs.First()
          : null);
            }

            // Property type was not resolved, thus this is not a valid property
            throw new NotSupportedException(Resources.notProperty);
        }
示例#26
0
 public override void DecompileProperty(PropertyDef property, ITextOutput output, DecompilationOptions options)
 {
     ReflectionDisassembler rd = CreateReflectionDisassembler(output, options, property);
     rd.DisassembleProperty(property);
     if (property.GetMethod != null) {
         output.WriteLine();
         rd.DisassembleMethod(property.GetMethod);
     }
     if (property.SetMethod != null) {
         output.WriteLine();
         rd.DisassembleMethod(property.SetMethod);
     }
     foreach (var m in property.OtherMethods) {
         output.WriteLine();
         rd.DisassembleMethod(m);
     }
 }
示例#27
0
 public override TreeViewNodeFilterResult GetFilterResult(PropertyDef prop)
 {
     var visibleFlags = VisibleMembersFlags.PropertyDef | VisibleMembersFlags.MethodDef |
                         VisibleMembersFlags.MethodBody | VisibleMembersFlags.ParamDefs |
                         VisibleMembersFlags.ParamDef | VisibleMembersFlags.Locals |
                         VisibleMembersFlags.Local;
     bool isMatch = (flags & VisibleMembersFlags.PropertyDef) != 0;
     if ((flags & visibleFlags) == 0)
         return new TreeViewNodeFilterResult(FilterResult.Hidden, isMatch);
     if (isMatch)
         return new TreeViewNodeFilterResult(FilterResult.Match, isMatch);	// Make sure it's not hidden
     return new TreeViewNodeFilterResult(FilterResult.Recurse, isMatch);
 }
示例#28
0
		string GetConnectionStringDesignTimeValue(PropertyDef prop) {
			if (toConnectionStringInfo == null)
				InitializeConnectionStringDesignTimeValues();
			ConnectionStringInfo info;
			if (!toConnectionStringInfo.TryGetValue(prop.Name, out info))
				return null;

			return string.Format(connectionIdStringFormat, EscapeXmlString(info.String), EscapeXmlString(info.ProviderName));
		}
示例#29
0
 static IEnumerable<MethodDef> GetMethods(PropertyDef evt)
 {
     foreach (var m in evt.GetMethods) yield return m;
     foreach (var m in evt.SetMethods) yield return m;
     foreach (var m in evt.OtherMethods) yield return m;
 }
示例#30
0
 public ModelInfo(PropertyDef evt)
 {
     this.OwnerType = evt.DeclaringType;
     this.PropertyIndex = this.OwnerType.Properties.IndexOf(evt);
     Debug.Assert(this.PropertyIndex >= 0);
     this.Methods = new HashSet<MethodDef>(GetMethods(evt)).ToArray();
     this.MethodIndexes = new int[this.Methods.Length];
 }
示例#31
0
        public TreeNode NewProperty(PropertyDef property)
        {
            TreeNode node = NewNode(String.Format(property.Name));

            node.Tag = property;
            node.ImageIndex = node.SelectedImageIndex = 43;

            if (property.GetMethod != null)
            {
                string type = property.GetMethod.ReturnType.GetExtendedName();

                node.Nodes.Add(NewMethod(property.GetMethod));
                node.Text = String.Format("{0}: {1}", property.Name, type);
            }

            if (property.SetMethod != null)
            {
                node.Nodes.Add(NewMethod(property.SetMethod));
            }

            foreach (MethodDef method in property.OtherMethods)
            {
                node.Nodes.Add(NewMethod(method));
            }

            return node;
        }
示例#32
0
        void Search(IDnSpyFile ownerModule, TypeDef type, PropertyDef prop)
        {
            var res = options.Filter.GetResult(prop);
            if (res.FilterType == FilterType.Hide)
                return;
            CheckCustomAttributes(ownerModule, prop, type);

            if (res.IsMatch && IsMatch(prop.Name, prop)) {
                options.OnMatch(new SearchResult {
                    Context = options.Context,
                    Object = prop,
                    NameObject = prop,
                    ObjectImageReference = options.DotNetImageManager.GetImageReference(prop),
                    LocationObject = type,
                    LocationImageReference = options.DotNetImageManager.GetImageReference(type),
                    DnSpyFile = ownerModule,
                });
            }
        }
示例#33
0
        static IEnumerable<Parameter> GetParameters(PropertyDef property)
        {
            if (property == null)
                yield break;
            if (property.GetMethod != null) {
                foreach (var param in property.GetMethod.Parameters)
                    yield return param;
                yield break;
            }
            if (property.SetMethod != null) {
                int last = property.SetMethod.Parameters.Count - 1;
                foreach (var param in property.SetMethod.Parameters) {
                    if (param.Index != last)
                        yield return param;
                }
                yield break;
            }

            int i = 0;
            foreach (var param in property.PropertySig.GetParams()) {
                yield return new Parameter(i, i, param);
                i++;
            }
        }
示例#34
0
		public override void DecompileProperty(PropertyDef property, ITextOutput output, DecompilationOptions options)
		{
			StartKeywordBlock(output, ".property", property);

			foreach (var getter in property.GetMethods) {
				StartKeywordBlock(output, ".get", getter);
				EndKeywordBlock(output);
			}

			foreach (var setter in property.SetMethods) {
				StartKeywordBlock(output, ".set", setter);
				EndKeywordBlock(output);
			}

			foreach (var other in property.OtherMethods) {
				StartKeywordBlock(output, ".other", other);
				EndKeywordBlock(output);
			}

			EndKeywordBlock(output);
		}
示例#35
0
        void Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, PropertyDef property)
        {
            if (property.DeclaringType.IsVisibleOutside() &&
                !IsVisibleOutside(context, parameters, property))
                service.SetCanRename(property, false);

            else if (property.IsRuntimeSpecialName)
                service.SetCanRename(property, false);

            else if (parameters.GetParameter(context, property, "forceRen", false))
                return;

            else if (property.DeclaringType.Implements("System.ComponentModel.INotifyPropertyChanged"))
                service.SetCanRename(property, false);

            else if (property.DeclaringType.Name.String.Contains("AnonymousType"))
                service.SetCanRename(property, false);
        }
示例#36
0
 /// <summary>
 /// Looks up the property node corresponding to the property definition.
 /// Returns null if no matching node is found.
 /// </summary>
 public PropertyTreeNode FindPropertyNode(PropertyDef def)
 {
     if (def == null)
         return null;
     TypeTreeNode typeNode = FindTypeNode(def.DeclaringType);
     if (typeNode == null)
         return null;
     typeNode.EnsureChildrenFiltered();
     return typeNode.Children.OfType<PropertyTreeNode>().FirstOrDefault(m => m.PropertyDefinition == def);
 }