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


C# INameService.AddReference方法代码示例

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


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

示例1: Analyze

        // i.e. Inter-Assembly References, e.g. InternalVisibleToAttributes
        public void Analyze(ConfuserContext context, INameService service, IDnlibDef def)
        {
            var module = def as ModuleDefMD;
            if (module == null) return;

            MDTable table;
            uint len;

            // MemberRef
            table = module.TablesStream.Get(Table.MemberRef);
            len = table.Rows;
            for (uint i = 1; i <= len; i++) {
                MemberRef memberRef = module.ResolveMemberRef(i);

                TypeDef declType = memberRef.DeclaringType.ResolveTypeDefThrow();
                if (declType.Module != module && context.Modules.Contains((ModuleDefMD)declType.Module)) {
                    var memberDef = (IDnlibDef)declType.ResolveThrow(memberRef);
                    service.AddReference(memberDef, new MemberRefReference(memberRef, memberDef));
                }
            }

            // TypeRef
            table = module.TablesStream.Get(Table.TypeRef);
            len = table.Rows;
            for (uint i = 1; i <= len; i++) {
                TypeRef typeRef = module.ResolveTypeRef(i);

                TypeDef typeDef = typeRef.ResolveTypeDefThrow();
                if (typeDef.Module != module && context.Modules.Contains((ModuleDefMD)typeDef.Module)) {
                    service.AddReference(typeDef, new TypeRefReference(typeRef, typeDef));
                }
            }
        }
开发者ID:GavinHwa,项目名称:ConfuserEx,代码行数:34,代码来源:InterReferenceAnalyzer.cs

示例2: Analyze

        public void Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
        {
            var module = def as ModuleDef;
            if (module == null) return;

            string asmName = module.Assembly.Name.String;
            if (!string.IsNullOrEmpty(module.Assembly.Culture) &&
                asmName.EndsWith(".resources")) {
                // Satellite assembly
                var satellitePattern = new Regex(string.Format("^(.*)\\.{0}\\.resources$", module.Assembly.Culture));
                string nameAsmName = asmName.Substring(0, asmName.Length - ".resources".Length);
                ModuleDef mainModule = context.Modules.SingleOrDefault(mod => mod.Assembly.Name == nameAsmName);
                if (mainModule == null) {
                    context.Logger.ErrorFormat("Could not find main assembly of satellite assembly '{0}'.", module.Assembly.FullName);
                    throw new ConfuserException(null);
                }

                string format = "{0}." + module.Assembly.Culture + ".resources";
                foreach (Resource res in module.Resources) {
                    Match match = satellitePattern.Match(res.Name);
                    if (!match.Success)
                        continue;
                    string typeName = match.Groups[1].Value;
                    TypeDef type = mainModule.FindReflectionThrow(typeName);
                    if (type == null) {
                        context.Logger.WarnFormat("Could not find resource type '{0}'.", typeName);
                        continue;
                    }
                    service.ReduceRenameMode(type, RenameMode.ASCII);
                    service.AddReference(type, new ResourceReference(res, type, format));
                }
            }
            else {
                string format = "{0}.resources";
                foreach (Resource res in module.Resources) {
                    Match match = ResourceNamePattern.Match(res.Name);
                    if (!match.Success)
                        continue;
                    string typeName = match.Groups[1].Value;

                    if (typeName.EndsWith(".g")) // WPF resources, ignore
                        continue;

                    TypeDef type = module.FindReflection(typeName);
                    if (type == null) {
                        context.Logger.WarnFormat("Could not find resource type '{0}'.", typeName);
                        continue;
                    }
                    service.ReduceRenameMode(type, RenameMode.ASCII);
                    service.AddReference(type, new ResourceReference(res, type, format));
                }
            }
        }
开发者ID:MulleDK19,项目名称:ConfuserEx,代码行数:53,代码来源:ResourceAnalyzer.cs

示例3: Analyze

        // i.e. Inter-Assembly References, e.g. InternalVisibleToAttributes
        public void Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
        {
            var module = def as ModuleDefMD;
            if (module == null) return;

            // MemberRef/MethodSpec
            var methods = module.GetTypes().SelectMany(type => type.Methods);
            foreach(var methodDef in methods) {
                foreach (var ov in methodDef.Overrides) {
                    ProcessMemberRef(context, service, module, ov.MethodBody);
                    ProcessMemberRef(context, service, module, ov.MethodDeclaration);
                }

                if (!methodDef.HasBody)
                    continue;
                foreach (var instr in methodDef.Body.Instructions) {
                    if (instr.Operand is MemberRef || instr.Operand is MethodSpec)
                        ProcessMemberRef(context, service, module, (IMemberRef)instr.Operand);
                }
            }

            // TypeRef
            var table = module.TablesStream.Get(Table.TypeRef);
            uint len = table.Rows;
            for (uint i = 1; i <= len; i++) {
                TypeRef typeRef = module.ResolveTypeRef(i);

                TypeDef typeDef = typeRef.ResolveTypeDefThrow();
                if (typeDef.Module != module && context.Modules.Contains((ModuleDefMD)typeDef.Module)) {
                    service.AddReference(typeDef, new TypeRefReference(typeRef, typeDef));
                }
            }
        }
开发者ID:ReyAleman,项目名称:ConfuserEx,代码行数:34,代码来源:InterReferenceAnalyzer.cs

示例4: 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

示例5: ProcessMemberRef

		void ProcessMemberRef(ConfuserContext context, INameService service, ModuleDefMD module, IMemberRef r) {
			var memberRef = r as MemberRef;
			if (r is MethodSpec)
				memberRef = ((MethodSpec)r).Method as MemberRef;

			if (memberRef != null) {
				if (memberRef.DeclaringType.TryGetArraySig() != null)
					return;

				TypeDef declType = memberRef.DeclaringType.ResolveTypeDefThrow();
				if (declType.Module != module && context.Modules.Contains((ModuleDefMD)declType.Module)) {
					var memberDef = (IDnlibDef)declType.ResolveThrow(memberRef);
					service.AddReference(memberDef, new MemberRefReference(memberRef, memberDef));
				}
			}
		}
开发者ID:EmilZhou,项目名称:ConfuserEx,代码行数:16,代码来源:InterReferenceAnalyzer.cs

示例6: Analyze

        public void Analyze(ConfuserContext context, INameService service, IDnlibDef def)
        {
            var module = def as ModuleDefMD;
            if (module == null) return;

            MDTable table;
            uint len;

            // MemberRef
            table = module.TablesStream.Get(Table.Method);
            len = table.Rows;
            IEnumerable<MethodDef> methods = Enumerable.Range(1, (int)len)
                                                       .Select(rid => module.ResolveMethod((uint)rid));
            foreach (MethodDef method in methods) {
                foreach (MethodOverride methodImpl in method.Overrides) {
                    if (methodImpl.MethodBody is MemberRef)
                        AnalyzeMemberRef(context, service, (MemberRef)methodImpl.MethodBody);
                    if (methodImpl.MethodDeclaration is MemberRef)
                        AnalyzeMemberRef(context, service, (MemberRef)methodImpl.MethodDeclaration);
                }
                if (!method.HasBody)
                    continue;
                foreach (Instruction instr in method.Body.Instructions) {
                    if (instr.Operand is MemberRef)
                        AnalyzeMemberRef(context, service, (MemberRef)instr.Operand);
                    else if (instr.Operand is MethodSpec) {
                        var spec = (MethodSpec)instr.Operand;
                        if (spec.Method is MemberRef)
                            AnalyzeMemberRef(context, service, (MemberRef)spec.Method);
                    }
                }
            }

            // CustomAttribute
            table = module.TablesStream.Get(Table.CustomAttribute);
            len = table.Rows;
            IEnumerable<CustomAttribute> attrs = Enumerable.Range(1, (int)len)
                                                           .Select(rid => module.ResolveHasCustomAttribute(module.TablesStream.ReadCustomAttributeRow((uint)rid).Parent))
                                                           .Distinct()
                                                           .SelectMany(owner => owner.CustomAttributes);
            foreach (CustomAttribute attr in attrs) {
                if (attr.Constructor is MemberRef)
                    AnalyzeMemberRef(context, service, (MemberRef)attr.Constructor);

                foreach (CAArgument arg in attr.ConstructorArguments)
                    AnalyzeCAArgument(context, service, arg);

                foreach (CANamedArgument arg in attr.Fields)
                    AnalyzeCAArgument(context, service, arg.Argument);

                foreach (CANamedArgument arg in attr.Properties)
                    AnalyzeCAArgument(context, service, arg.Argument);

                TypeDef attrType = attr.AttributeType.ResolveTypeDefThrow();
                if (!context.Modules.Contains((ModuleDefMD)attrType.Module))
                    continue;

                foreach (CANamedArgument fieldArg in attr.Fields) {
                    FieldDef field = attrType.FindField(fieldArg.Name, new FieldSig(fieldArg.Type));
                    if (field == null)
                        context.Logger.WarnFormat("Failed to resolve CA field '{0}::{1} : {2}'.", attrType, fieldArg.Name, fieldArg.Type);
                    else
                        service.AddReference(field, new CAMemberReference(fieldArg, field));
                }
                foreach (CANamedArgument propertyArg in attr.Properties) {
                    PropertyDef property = attrType.FindProperty(propertyArg.Name, new PropertySig(true, propertyArg.Type));
                    if (property == null)
                        context.Logger.WarnFormat("Failed to resolve CA property '{0}::{1} : {2}'.", attrType, propertyArg.Name, propertyArg.Type);
                    else
                        service.AddReference(property, new CAMemberReference(propertyArg, property));
                }
            }
        }
开发者ID:MetSystem,项目名称:ConfuserEx,代码行数:73,代码来源:TypeBlobAnalyzer.cs

示例7: AnalyzeMemberRef

        void AnalyzeMemberRef(ConfuserContext context, INameService service, MemberRef memberRef)
        {
            ITypeDefOrRef declType = memberRef.DeclaringType;
            var typeSpec = declType as TypeSpec;
            if (typeSpec == null)
                return;

            TypeSig sig = typeSpec.TypeSig;
            while (sig.Next != null)
                sig = sig.Next;

            Debug.Assert(sig is TypeDefOrRefSig || sig is GenericInstSig || sig is GenericSig);
            if (sig is GenericInstSig) {
                var inst = (GenericInstSig)sig;
                Debug.Assert(!(inst.GenericType.TypeDefOrRef is TypeSpec));
                TypeDef openType = inst.GenericType.TypeDefOrRef.ResolveTypeDefThrow();
                if (!context.Modules.Contains((ModuleDefMD)openType.Module) ||
                    memberRef.IsArrayAccessors())
                    return;

                IDnlibDef member;
                if (memberRef.IsFieldRef) member = memberRef.ResolveFieldThrow();
                else if (memberRef.IsMethodRef) member = memberRef.ResolveMethodThrow();
                else throw new UnreachableException();

                service.AddReference(member, new MemberRefReference(memberRef, member));
            }
        }
开发者ID:MetSystem,项目名称:ConfuserEx,代码行数:28,代码来源:TypeBlobAnalyzer.cs

示例8: AnalyzeCAArgument

 void AnalyzeCAArgument(ConfuserContext context, INameService service, CAArgument arg)
 {
     if (arg.Type.DefinitionAssembly.IsCorLib() && arg.Type.FullName == "System.Type") {
         var typeSig = (TypeSig)arg.Value;
         foreach (ITypeDefOrRef typeRef in typeSig.FindTypeRefs()) {
             TypeDef typeDef = typeRef.ResolveTypeDefThrow();
             if (context.Modules.Contains((ModuleDefMD)typeDef.Module)) {
                 if (typeRef is TypeRef)
                     service.AddReference(typeDef, new TypeRefReference((TypeRef)typeRef, typeDef));
                 service.ReduceRenameMode(typeDef, RenameMode.ASCII);
             }
         }
     }
     else if (arg.Value is CAArgument[]) {
         foreach (CAArgument elem in (CAArgument[])arg.Value)
             AnalyzeCAArgument(context, service, elem);
     }
 }
开发者ID:MetSystem,项目名称:ConfuserEx,代码行数:18,代码来源:TypeBlobAnalyzer.cs


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