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


C# GenericInstanceType.ToString方法代码示例

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


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

示例1: OnType

		public void OnType(TypeDefinition type)
		{
			if(type.IsInterface)
				return;
			foreach(var method in type.Methods) 
			{
				try 
				{
					string fieldName;
					MethodReference methodR;
					
					#region Get required info or continue
					
					if(method.Name.StartsWith("add_")) {
						fieldName = method.Name.Substring("add_".Length);
						methodR = combineR;
					} else if(method.Name.StartsWith("remove_")) {
						fieldName = method.Name.Substring("remove_".Length);
						methodR = removeR;
					} else {
						continue;
					}
					
#endregion
					
					var newI = new List<Instruction>();
					
					var processor = method.Body.GetILProcessor();
					
					bool foundCompExch = false;
					foreach(var existingInstruction in processor.Body.Instructions) {
						if(existingInstruction.OpCode == OpCodes.Call) {
							var meth = existingInstruction.Operand as MethodReference;
							if(meth != null) {
								if(meth.Name == "CompareExchange") {
									if(Verbosity > 7)
										Console.WriteLine("   Found CompareExchange");
									foundCompExch = true;
									break;
								}
							}
						}
					}
					
					if(!foundCompExch) {
						if(Verbosity >= Verbosities.SkippingVerbose) {
							Console.WriteLine(" . ignoring body with no CompareExchange: " + type.Name + "." + method.Name);
						}
						skipped++;
						continue;
					}


					FieldReference field;


					if(type.HasGenericParameters)
					{
						var giType = new GenericInstanceType(type);
//						var 
//						string x = type.FullName;
						//giType.
						field = type.Fields.Where(f => f.Name == fieldName).FirstOrDefault();


						Console.WriteLine("==== GENERICTYPE: " + type + " (" + type.GenericParameters.Count + ") " + giType.ToString() + ", Field: " + field.FullName);
						foreach(var genPar in type.GenericParameters)
						{
							Console.WriteLine(" ==> " + genPar.FullName);
						}
					}
					else
					{
						field = type.Fields.Where(f => f.Name == fieldName).FirstOrDefault();
					}

					if(field == null)
						throw new Exception("Could not find field: " + fieldName + " in type " + type.FullName);

					if (method.IsStatic) {
						//	IL_0000:  ldfld class MyNamespace.ActionBool MyNamespace.EnableableBase::myHandler
						newI.Add(processor.Create(OpCodes.Ldsfld, field));

						//	IL_0005:  ldarg.0 
						newI.Add(processor.Create(OpCodes.Ldarg_0));

						//	IL_0006:  call class [mscorlib]System.Delegate class [mscorlib]System.Delegate::Combine(class [mscorlib]System.Delegate, class [mscorlib]System.Delegate)
						newI.Add(processor.Create(OpCodes.Call, methodR));

						//	IL_000b:  castclass MyNamespace.ActionBool
						newI.Add(processor.Create(OpCodes.Castclass, field.FieldType));

						//	IL_0010:  stfld class MyNamespace.ActionBool MyNamespace.EnableableBase::myHandler
						newI.Add(processor.Create(OpCodes.Stsfld, field));

						//	IL_0015:  ret 
						newI.Add(processor.Create(OpCodes.Ret));
					} else {
						//	IL_0000:  ldarg.0 
						newI.Add(processor.Create(OpCodes.Ldarg_0));
//.........这里部分代码省略.........
开发者ID:Pitimoi,项目名称:AOT-Compatlyzer,代码行数:101,代码来源:ReplaceCompareExchange.cs


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