當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。