当前位置: 首页>>代码示例>>C#>>正文


C# INameService.SetCanRename方法代码示例

本文整理汇总了C#中INameService.SetCanRename方法的典型用法代码示例。如果您正苦于以下问题:C# INameService.SetCanRename方法的具体用法?C# INameService.SetCanRename怎么用?C# INameService.SetCanRename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在INameService的用法示例。


在下文中一共展示了INameService.SetCanRename方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Analyze

		public void Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def) {
			var method = def as MethodDef;
			if (method == null || !method.HasBody)
				return;

			// When a ldtoken instruction reference a definition,
			// most likely it would be used in reflection and thus probably should not be renamed.
			// Also, when ToString is invoked on enum,
			// the enum should not be renamed.
			for (int i = 0; i < method.Body.Instructions.Count; i++) {
				Instruction instr = method.Body.Instructions[i];
				if (instr.OpCode.Code == Code.Ldtoken) {
					if (instr.Operand is MemberRef) {
						IMemberForwarded member = ((MemberRef)instr.Operand).ResolveThrow();
						if (context.Modules.Contains((ModuleDefMD)member.Module))
							service.SetCanRename(member, false);
					}
					else if (instr.Operand is IField) {
						FieldDef field = ((IField)instr.Operand).ResolveThrow();
						if (context.Modules.Contains((ModuleDefMD)field.Module))
							service.SetCanRename(field, false);
					}
					else if (instr.Operand is IMethod) {
						var im = (IMethod)instr.Operand;
						if (!im.IsArrayAccessors()) {
							MethodDef m = im.ResolveThrow();
							if (context.Modules.Contains((ModuleDefMD)m.Module))
								service.SetCanRename(method, false);
						}
					}
					else if (instr.Operand is ITypeDefOrRef) {
						if (!(instr.Operand is TypeSpec)) {
							TypeDef type = ((ITypeDefOrRef)instr.Operand).ResolveTypeDefThrow();
							if (context.Modules.Contains((ModuleDefMD)type.Module) &&
							    HandleTypeOf(context, service, method, i)) {
								var t = type;
								do {
									DisableRename(service, t, false);
									t = t.DeclaringType;
								} while (t != null);
							}
						}
					}
					else
						throw new UnreachableException();
				}
				else if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt) &&
				         ((IMethod)instr.Operand).Name == "ToString") {
					HandleEnum(context, service, method, i);
				}
				else if (instr.OpCode.Code == Code.Ldstr) {
					TypeDef typeDef = method.Module.FindReflection((string)instr.Operand);
					if (typeDef != null)
						service.AddReference(typeDef, new StringTypeReference(instr, typeDef));
				}
			}
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:57,代码来源:LdtokenEnumAnalyzer.cs

示例2: DisableRename

        void DisableRename(INameService service, TypeDef typeDef, bool memberOnly = true)
        {
            service.SetCanRename(typeDef, false);

            foreach (MethodDef m in typeDef.Methods)
                service.SetCanRename(m, false);

            foreach (FieldDef field in typeDef.Fields)
                service.SetCanRename(field, false);

            foreach (PropertyDef prop in typeDef.Properties)
                service.SetCanRename(prop, false);

            foreach (EventDef evt in typeDef.Events)
                service.SetCanRename(evt, false);

            foreach (TypeDef nested in typeDef.NestedTypes)
                DisableRename(service, nested, false);
        }
开发者ID:cybercircuits,项目名称:ConfuserEx,代码行数:19,代码来源:LdtokenEnumAnalyzer.cs

示例3: Analyze

		public void Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def) {
			var type = def as TypeDef;
			if (type == null || type.DeclaringType != null)
				return;
			if (type.Name.Contains("ViewModel")) {
				string viewNs = type.Namespace.Replace("ViewModels", "Views");
				string viewName = type.Name.Replace("PageViewModel", "Page").Replace("ViewModel", "View");
				TypeDef view = type.Module.Find(viewNs + "." + viewName, true);
				if (view != null) {
					service.SetCanRename(type, false);
					service.SetCanRename(view, false);
				}

				// Test for Multi-view
				string multiViewNs = type.Namespace + "." + type.Name.Replace("ViewModel", "");
				foreach (var t in type.Module.Types)
					if (t.Namespace == multiViewNs) {
						service.SetCanRename(type, false);
						service.SetCanRename(t, false);
					}
			}
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:22,代码来源:CaliburnAnalyzer.cs

示例4: Analyze

 void Analyze(ConfuserContext context, INameService service, FieldDef field, ProtectionParameters parameters)
 {
     if (ShouldExclude(field.DeclaringType, field)) {
         service.SetCanRename(field, false);
     }
 }
开发者ID:RSchwoerer,项目名称:ConfuserEx,代码行数:6,代码来源:JsonAnalyzer.cs

示例5: AnalyzeMethod

        void AnalyzeMethod(ConfuserContext context, INameService service, MethodDef method)
        {
            var dpRegInstrs = new List<Tuple<bool, Instruction>>();
            var routedEvtRegInstrs = new List<Instruction>();
            for (int i = 0; i < method.Body.Instructions.Count; i++) {
                Instruction instr = method.Body.Instructions[i];
                if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt)) {
                    var regMethod = (IMethod)instr.Operand;

                    if (regMethod.DeclaringType.FullName == "System.Windows.DependencyProperty" &&
                        regMethod.Name.String.StartsWith("Register")) {
                        dpRegInstrs.Add(Tuple.Create(regMethod.Name.String.StartsWith("RegisterAttached"), instr));
                    }
                    else if (regMethod.DeclaringType.FullName == "System.Windows.EventManager" &&
                             regMethod.Name.String == "RegisterRoutedEvent") {
                        routedEvtRegInstrs.Add(instr);
                    }
                }
                else if (instr.OpCode.Code == Code.Newobj) {
                    var methodRef = (IMethod)instr.Operand;

                    if (methodRef.DeclaringType.FullName == "System.Windows.Data.PropertyGroupDescription" &&
                        methodRef.Name == ".ctor" && i - 1 >= 0 && method.Body.Instructions[i - 1].OpCode.Code == Code.Ldstr) {
                        foreach (var property in analyzer.LookupProperty((string)method.Body.Instructions[i - 1].Operand))
                            service.SetCanRename(property, false);
                    }
                }
                else if (instr.OpCode == OpCodes.Ldstr) {
                    var operand = ((string)instr.Operand).ToUpperInvariant();
                    if (operand.EndsWith(".BAML") || operand.EndsWith(".XAML")) {
                        var match = UriPattern.Match(operand);
                        if (match.Success)
                            operand = match.Groups[1].Value;
                        else if (operand.Contains("/"))
                            context.Logger.WarnFormat("Fail to extract XAML name from '{0}'.", instr.Operand);

                        var reference = new BAMLStringReference(instr);
                        operand = operand.TrimStart('/');
                        var baml = operand.Substring(0, operand.Length - 5) + ".BAML";
                        var xaml = operand.Substring(0, operand.Length - 5) + ".XAML";
                        bamlRefs.AddListEntry(baml, reference);
                        bamlRefs.AddListEntry(xaml, reference);
                    }
                }
            }

            if (dpRegInstrs.Count == 0)
                return;

            var traceSrv = context.Registry.GetService<ITraceService>();
            MethodTrace trace = traceSrv.Trace(method);

            bool erred = false;
            foreach (var instrInfo in dpRegInstrs) {
                int[] args = trace.TraceArguments(instrInfo.Item2);
                if (args == null) {
                    if (!erred)
                        context.Logger.WarnFormat("Failed to extract dependency property name in '{0}'.", method.FullName);
                    erred = true;
                    continue;
                }
                Instruction ldstr = method.Body.Instructions[args[0]];
                if (ldstr.OpCode.Code != Code.Ldstr) {
                    if (!erred)
                        context.Logger.WarnFormat("Failed to extract dependency property name in '{0}'.", method.FullName);
                    erred = true;
                    continue;
                }

                var name = (string)ldstr.Operand;
                TypeDef declType = method.DeclaringType;
                bool found = false;
                if (instrInfo.Item1) // Attached DP
                {
                    MethodDef accessor;
                    if ((accessor = declType.FindMethod("Get" + name)) != null && accessor.IsStatic) {
                        service.SetCanRename(accessor, false);
                        found = true;
                    }
                    if ((accessor = declType.FindMethod("Set" + name)) != null && accessor.IsStatic) {
                        service.SetCanRename(accessor, false);
                        found = true;
                    }
                }

                // Normal DP
                // Find CLR property for attached DP as well, because it seems attached DP can be use as normal DP as well.
                PropertyDef property = null;
                if ((property = declType.FindProperty(name)) != null) {
                    service.SetCanRename(property, false);

                    found = true;
                    if (property.GetMethod != null)
                        service.SetCanRename(property.GetMethod, false);

                    if (property.SetMethod != null)
                        service.SetCanRename(property.SetMethod, false);

                    if (property.HasOtherMethods) {
                        foreach (MethodDef accessor in property.OtherMethods)
//.........这里部分代码省略.........
开发者ID:RSchwoerer,项目名称:ConfuserEx,代码行数:101,代码来源:WPFAnalyzer.cs

示例6: AnalyzeMethod

        private void AnalyzeMethod(ConfuserContext context, INameService service, MethodDef method)
        {
            var dpRegInstrs = new List<Tuple<bool, Instruction>>();
            var routedEvtRegInstrs = new List<Instruction>();
            foreach (Instruction instr in method.Body.Instructions) {
                if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt)) {
                    var regMethod = (IMethod)instr.Operand;

                    if (regMethod.DeclaringType.FullName == "System.Windows.DependencyProperty" &&
                        regMethod.Name.String.StartsWith("Register")) {
                        dpRegInstrs.Add(Tuple.Create(regMethod.Name.String.StartsWith("RegisterAttached"), instr));
                    }
                    else if (regMethod.DeclaringType.FullName == "System.Windows.EventManager" &&
                             regMethod.Name.String == "RegisterRoutedEvent") {
                        routedEvtRegInstrs.Add(instr);
                    }
                }
            }

            if (dpRegInstrs.Count == 0)
                return;

            var traceSrv = context.Registry.GetService<ITraceService>();
            MethodTrace trace = traceSrv.Trace(method);

            bool erred = false;
            foreach (var instrInfo in dpRegInstrs) {
                int[] args = trace.TraceArguments(instrInfo.Item2);
                if (args == null) {
                    if (!erred)
                        context.Logger.WarnFormat("Failed to extract dependency property name in '{0}'.", method.FullName);
                    erred = true;
                    continue;
                }
                Instruction ldstr = method.Body.Instructions[args[0]];
                if (ldstr.OpCode.Code != Code.Ldstr) {
                    if (!erred)
                        context.Logger.WarnFormat("Failed to extract dependency property name in '{0}'.", method.FullName);
                    erred = true;
                    continue;
                }

                var name = (string)ldstr.Operand;
                TypeDef declType = method.DeclaringType;
                bool found = false;
                if (instrInfo.Item1) // Attached DP
                {
                    MethodDef accessor;
                    if ((accessor = declType.FindMethod("Get" + name)) != null && accessor.IsStatic) {
                        service.SetCanRename(accessor, false);
                        found = true;
                    }
                    if ((accessor = declType.FindMethod("Set" + name)) != null && accessor.IsStatic) {
                        service.SetCanRename(accessor, false);
                        found = true;
                    }
                }

                // Normal DP
                // Find CLR property for attached DP as well, because it seems attached DP can be use as normal DP as well.
                PropertyDef property = null;
                if ((property = declType.FindProperty(name)) != null) {
                    found = true;
                    if (property.GetMethod != null)
                        service.SetCanRename(property.GetMethod, false);

                    if (property.SetMethod != null)
                        service.SetCanRename(property.SetMethod, false);

                    if (property.HasOtherMethods) {
                        foreach (MethodDef accessor in property.OtherMethods)
                            service.SetCanRename(accessor, false);
                    }
                }
                if (!found) {
                    if (instrInfo.Item1)
                        context.Logger.WarnFormat("Failed to find the accessors of attached dependency property '{0}' in type '{1}'.",
                                                  name, declType.FullName);
                    else
                        context.Logger.WarnFormat("Failed to find the CLR property of normal dependency property '{0}' in type '{1}'.",
                                                  name, declType.FullName);
                }
            }

            erred = false;
            foreach (Instruction instr in routedEvtRegInstrs) {
                int[] args = trace.TraceArguments(instr);
                if (args == null) {
                    if (!erred)
                        context.Logger.WarnFormat("Failed to extract routed event name in '{0}'.", method.FullName);
                    erred = true;
                    continue;
                }
                Instruction ldstr = method.Body.Instructions[args[0]];
                if (ldstr.OpCode.Code != Code.Ldstr) {
                    if (!erred)
                        context.Logger.WarnFormat("Failed to extract routed event name in '{0}'.", method.FullName);
                    erred = true;
                    continue;
                }
//.........这里部分代码省略.........
开发者ID:GavinHwa,项目名称:ConfuserEx,代码行数:101,代码来源:WPFAnalyzer.cs

示例7: AnalyzeMethod

		void AnalyzeMethod(ConfuserContext context, INameService service, MethodDef method) {
			var binding = new List<Tuple<bool, Instruction>>();
			foreach (Instruction instr in method.Body.Instructions) {
				if ((instr.OpCode.Code == Code.Call || instr.OpCode.Code == Code.Callvirt)) {
					var target = (IMethod)instr.Operand;

					if ((target.DeclaringType.FullName == "System.Windows.Forms.ControlBindingsCollection" ||
					     target.DeclaringType.FullName == "System.Windows.Forms.BindingsCollection") &&
					    target.Name == "Add" && target.MethodSig.Params.Count != 1) {
						binding.Add(Tuple.Create(true, instr));
					}
					else if (target.DeclaringType.FullName == "System.Windows.Forms.Binding" &&
					         target.Name.String == ".ctor") {
						binding.Add(Tuple.Create(false, instr));
					}
				}
			}

			if (binding.Count == 0)
				return;

			var traceSrv = context.Registry.GetService<ITraceService>();
			MethodTrace trace = traceSrv.Trace(method);

			bool erred = false;
			foreach (var instrInfo in binding) {
				int[] args = trace.TraceArguments(instrInfo.Item2);
				if (args == null) {
					if (!erred)
						context.Logger.WarnFormat("Failed to extract binding property name in '{0}'.", method.FullName);
					erred = true;
					continue;
				}

				Instruction propertyName = method.Body.Instructions[args[0 + (instrInfo.Item1 ? 1 : 0)]];
				if (propertyName.OpCode.Code != Code.Ldstr) {
					if (!erred)
						context.Logger.WarnFormat("Failed to extract binding property name in '{0}'.", method.FullName);
					erred = true;
				}
				else {
					List<PropertyDef> props;
					if (!properties.TryGetValue((string)propertyName.Operand, out props)) {
						if (!erred)
							context.Logger.WarnFormat("Failed to extract target property in '{0}'.", method.FullName);
						erred = true;
					}
					else {
						foreach (var property in props)
							service.SetCanRename(property, false);
					}
				}

				Instruction dataMember = method.Body.Instructions[args[2 + (instrInfo.Item1 ? 1 : 0)]];
				if (dataMember.OpCode.Code != Code.Ldstr) {
					if (!erred)
						context.Logger.WarnFormat("Failed to extract binding property name in '{0}'.", method.FullName);
					erred = true;
				}
				else {
					List<PropertyDef> props;
					if (!properties.TryGetValue((string)dataMember.Operand, out props)) {
						if (!erred)
							context.Logger.WarnFormat("Failed to extract target property in '{0}'.", method.FullName);
						erred = true;
					}
					else {
						foreach (var property in props)
							service.SetCanRename(property, false);
					}
				}
			}
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:73,代码来源:WinFormsAnalyzer.cs


注:本文中的INameService.SetCanRename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。