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


C# Cecil.TypeDefinition类代码示例

本文整理汇总了C#中Mono.Cecil.TypeDefinition的典型用法代码示例。如果您正苦于以下问题:C# TypeDefinition类的具体用法?C# TypeDefinition怎么用?C# TypeDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TypeDefinition类属于Mono.Cecil命名空间,在下文中一共展示了TypeDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SwapParameterTypes

        private static void SwapParameterTypes(MethodDefinition method,
            TypeDefinition targetDependency,
            TypeReference interfaceType,
            HashSet<MethodReference> modifiedMethods)
        {
            if (method.IsAbstract || !method.HasBody)
                return;

            bool modified = false;
            var parameters = method.Parameters.Cast<ParameterDefinition>();
            foreach (var parameter in parameters)
            {
                var parameterType = parameter.ParameterType;
                if (parameterType != targetDependency)
                    continue;

                parameter.ParameterType = interfaceType;
                modified = true;
            }

            if (!modified)
                return;

            modifiedMethods.Add(method);
        }
开发者ID:philiplaureano,项目名称:Taiji,代码行数:25,代码来源:SwapEmbeddedMethodTypeReferences.cs

示例2: IsCastTo

		private static bool IsCastTo(TypeDefinition castTarget, Instruction instruction)
		{
			if (instruction.OpCode != OpCodes.Castclass) return false;

			TypeReference typeReference = (TypeReference)instruction.Operand;
			return typeReference.Resolve() == castTarget;
		}
开发者ID:Galigator,项目名称:db4o,代码行数:7,代码来源:StackAnalyzerTestCase.Helper.cs

示例3: CreateDefaultCtor

            /// <summary>
            /// Create the Ctor
            /// </summary>
            private static void CreateDefaultCtor(ReachableContext reachableContext, TypeDefinition type)
            {
                var typeSystem = type.Module.TypeSystem;
                var ctor = new MethodDefinition(".ctor", MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, typeSystem.Void);
                ctor.DeclaringType = type;

                var body = new MethodBody(ctor);
                body.InitLocals = true;
                ctor.Body = body;

                // Prepare code
                var seq = new ILSequence();
                seq.Emit(OpCodes.Nop);
                seq.Emit(OpCodes.Ret);

                // Append ret sequence
                seq.AppendTo(body);

                // Update offsets
                body.ComputeOffsets();

                // Add ctor
                type.Methods.Add(ctor);
                ctor.SetReachable(reachableContext);
            }
开发者ID:Xtremrules,项目名称:dot42,代码行数:28,代码来源:StructDefaultCtorsAndDefaultField.cs

示例4: TypeWriterBase

 public TypeWriterBase(TypeDefinition typeDefinition, int indentCount, TypeCollection typeCollection, ConfigBase config)
 {
     this.TypeDefinition = typeDefinition;
     this.IndentCount = indentCount;
     this.TypeCollection = typeCollection;
     this.Config = config;
 }
开发者ID:sumitkm,项目名称:ToTypeScriptD,代码行数:7,代码来源:TypeWriterBase.cs

示例5: FindReferencesInType

		private IEnumerable<AnalyzerTreeNode> FindReferencesInType(TypeDefinition type)
		{
			foreach (MethodDefinition method in type.Methods) {
				bool found = false;
				if (!method.HasBody)
					continue;

				// ignore chained constructors
				// (since object is the root of everything, we can short circuit the test in this case)
				if (method.Name == ".ctor" &&
					(isSystemObject || analyzedType == type || TypesHierarchyHelpers.IsBaseType(analyzedType, type, false)))
					continue;

				foreach (Instruction instr in method.Body.Instructions) {
					MethodReference mr = instr.Operand as MethodReference;
					if (mr != null && mr.Name == ".ctor") {
						if (Helpers.IsReferencedBy(analyzedType, mr.DeclaringType)) {
							found = true;
							break;
						}
					}
				}

				method.Body = null;

				if (found) {
					var node = new AnalyzedMethodTreeNode(method);
					node.Language = this.Language;
					yield return node;
				}
			}
		}
开发者ID:FaceHunter,项目名称:ILSpy,代码行数:32,代码来源:AnalyzedTypeInstantiationsTreeNode.cs

示例6: GetValues

		private void GetValues (TypeDefinition type)
		{
			values.Clear ();
			
			Type ftype = null;
			foreach (FieldDefinition field in type.Fields) {
				if (field.IsStatic) {
					if (ftype == null)
						ftype = field.Constant.GetType ();
						
					ulong value;
					if (ftype == typeof (ulong)) {
						value = (ulong) field.Constant;

						if (value != 0 && !values.Contains (value))
							values.Add (value);

					} else {
						long v = Convert.ToInt64 (field.Constant);

						if (v > 0) {
							value = (ulong) v;
							if (!values.Contains (value))
								values.Add (value);
						} else if (v < 0) {
							values.Clear ();
							break;
						}
					}
				}
			}
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:32,代码来源:UseFlagsAttributeRule.cs

示例7: ProcessType

        private void ProcessType(bool? assemblyConfigureAwaitValue, TypeDefinition type)
        {
            if (type.IsCompilerGenerated() && type.IsIAsyncStateMachine())
            {
                return;
            }

            var configureAwaitValue = (bool?)type.GetConfigureAwaitAttribute()?.ConstructorArguments[0].Value;
            configureAwaitValue = configureAwaitValue ?? assemblyConfigureAwaitValue;

            foreach (var method in type.Methods)
            {
                var localConfigureAwaitValue = (bool?)method.GetConfigureAwaitAttribute()?.ConstructorArguments[0].Value;
                var localConfigWasSet = localConfigureAwaitValue.HasValue;
                localConfigureAwaitValue = localConfigureAwaitValue ?? configureAwaitValue;
                if (localConfigureAwaitValue == null)
                    continue;

                var asyncStateMachineType = method.GetAsyncStateMachineType();
                if (asyncStateMachineType != null)
                {
                    AddAwaitConfigToAsyncMethod(asyncStateMachineType, localConfigureAwaitValue.Value);
                }
                else if (localConfigWasSet)
                {
                    LogWarning($"ConfigureAwaitAttribue applied to non-async method '{method.FullName}'.");
                    continue;
                }
            }
        }
开发者ID:caesay,项目名称:ConfigureAwait,代码行数:30,代码来源:ModuleWeaver.cs

示例8: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule applies only to types, interfaces and structures (value types)
			if (type.IsEnum || type.IsDelegate () || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			// rule onyly applies to type that implements IDisposable
			if (!type.Implements ("System.IDisposable"))
				return RuleResult.DoesNotApply;

			// no problem is a finalizer is found
			if (type.HasMethod (MethodSignatures.Finalize))
				return RuleResult.Success;

			// otherwise check for native types
			foreach (FieldDefinition field in type.Fields) {
				// we can't dispose static fields in IDisposable
				if (field.IsStatic)
					continue;
				if (!field.FieldType.GetElementType ().IsNative ())
					continue;
				Runner.Report (field, Severity.High, Confidence.High);
			}

			// special case: a struct cannot define a finalizer so it's a
			// bad candidate to hold references to unmanaged resources
			if (type.IsValueType && (Runner.CurrentRuleResult == RuleResult.Failure))
				Runner.Report (type, Severity.High, Confidence.High, Struct);

			return Runner.CurrentRuleResult;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:31,代码来源:DisposableTypesShouldHaveFinalizerRule.cs

示例9: VisitType

		public void VisitType(TypeDefinition type)
		{		
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "{0}", type);
			
			string names = string.Empty;
			foreach (PropertyDefinition prop in type.Properties)
			{
				string name = prop.Name;
				
				MethodDefinition[] methods1 = type.Methods.GetMethod("Get" + name);
				MethodDefinition[] methods2 = type.Methods.GetMethod("Set" + name);
				
				if (methods1.Length > 0 && methods1[0].IsPublic)
					names += name + " ";
				else if (methods2.Length > 0 && methods2[0].IsPublic)
					names += name + " ";
			}
			
			if (names.Length > 0)
			{
				Log.DebugLine(this, "names: {0}", names);
				Reporter.TypeFailed(type, CheckID, "Properties: " + names);
			}
		}
开发者ID:dbremner,项目名称:smokey,代码行数:25,代码来源:PropertyMatchesAccessorRule.cs

示例10: CheckType

		public MessageCollection CheckType(TypeDefinition type, Runner runner)
		{
			MessageCollection messageCollection = new MessageCollection();

			foreach (MethodDefinition method in type.Methods)
			{
				if (!method.IsStatic)
				{
					return null;
				}
			}

			foreach (FieldDefinition field in type.Fields)
			{
				if (!field.IsStatic)
				{
					return null;
				}
			}
			
			foreach (MethodDefinition ctor in type.Constructors)
			{
				if (!ctor.IsStatic && (ctor.Attributes & MethodAttributes.Public) == MethodAttributes.Public)
				{
					Location location = new Location(type.Name, ctor.Name, 0);
					Message message = new Message(MessageString, location, MessageType.Error);
					messageCollection.Add(message);
				}
			}

			return messageCollection.Count > 0 ? messageCollection : null;
			
		}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:33,代码来源:AvoidConstructorsInStaticTypesRule.cs

示例11: OfType

        public IEnumerable<TypeReference> OfType(TypeDefinition definition)
        {
            if (definition == null)
                throw new ArgumentNullException("definition");

            return definition.Methods.SelectMany(m => OfMethod(m));
        }
开发者ID:scaredfinger,项目名称:SharpDependencies,代码行数:7,代码来源:FindTypeReferencesInMethods.cs

示例12: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			//type does not apply if not an interface or is an empty interface
			if (!type.IsInterface || !type.HasMethods)
				return RuleResult.DoesNotApply;

			//TODO: take into account [InternalsVisibleTo] on iface's assembly
			AssemblyDefinition current_assembly = type.Module.Assembly;
			if (type.IsVisible ()) {
				// We should not, by default, promote the implementation of interfaces in assemblies that
				// do not, already, refer to the current one because:
				// (a) we could be suggesting circular references (solvable, or not, by refactoring)
				// (b) it has a very HIGH performance cost, with verry LITTLE value (in # of defects)
				string current_assembly_name = current_assembly.Name.Name;
				foreach (AssemblyDefinition assembly in Runner.Assemblies) {
					// by default only process assemblies (from the set) that refers to the current one
					// or the current one itself
					if (!ReferencesOnly || (current_assembly_name == assembly.Name.Name) ||
						assembly.References (current_assembly_name)) {
						CheckAssemblyTypes (assembly, type);
					}
				}
			} else {
				// if the interface is not visible then we only check this assembly
				CheckAssemblyTypes (current_assembly, type);
			}

			return Runner.CurrentRuleResult;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:29,代码来源:ConsiderAddingInterfaceRule.cs

示例13: addMainMethod

 public MethodDefinition addMainMethod(TypeDefinition tdTargetType)
 {
     MethodDefinition mainMethod = createMethod_StaticVoid("Main");
     tdTargetType.Methods.Add(mainMethod);
     assemblyDefinition.EntryPoint = mainMethod;
     return mainMethod;
 }
开发者ID:o2platform,项目名称:O2.Platform.Projects.Misc_and_Legacy,代码行数:7,代码来源:CecilAssemblyBuilder.cs

示例14: addType

 public TypeDefinition addType(String sTypeNameSpace, String sTypeName, TypeAttributes taTypeAttributes,
                               TypeReference trTypeReference)
 {
     var tdNewType = new TypeDefinition(sTypeName, sTypeNameSpace, taTypeAttributes, trTypeReference);
     mainModule.Types.Add(tdNewType);
     return tdNewType;
 }
开发者ID:o2platform,项目名称:O2.Platform.Projects.Misc_and_Legacy,代码行数:7,代码来源:CecilAssemblyBuilder.cs

示例15: GetInjecteeCecilType

        internal virtual TypeDefinition GetInjecteeCecilType(ModuleDefinition module)
        {
            if (_injecteeCecilDef == null)
                _injecteeCecilDef = module.FindMatchingType(InjecteeType, true);

            return _injecteeCecilDef;
        }
开发者ID:MarkusSintonen,项目名称:MNetInjector,代码行数:7,代码来源:TypeInjecteeBase.cs


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