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


C# GenericInstanceType.AddGenericArgument方法代码示例

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


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

示例1: WriteConstructorInvocation

		private void WriteConstructorInvocation(ObjectCreationExpression node)
		{
			if (node.Constructor.DeclaringType is TypeSpecification)
			{
				GenericInstanceType generic = node.Constructor.DeclaringType as GenericInstanceType;
				if (generic != null)
				{
					if (SupportsSpecialNullable && (generic.GetFriendlyFullName(Language).IndexOf("System.Nullable<") == 0) &&
						generic.GenericArguments[0].IsValueType)
					{
						TypeReference toWrite = generic.GenericArguments[0];
						if (generic.PostionToArgument.ContainsKey(0))
						{
							toWrite = generic.PostionToArgument[0];
						}
						WriteReferenceAndNamespaceIfInCollision(toWrite);
						WriteToken("?");
						return;
					}
				}
			}

			if (node.Constructor.DeclaringType.Namespace == "System")
			{
				WriteReferenceAndNamespaceIfInCollision(node.Constructor.DeclaringType);
				return;
			}

			if (node.Constructor.DeclaringType.DeclaringType != null)
			{
				TypeReference declaringType = node.Constructor.DeclaringType.DeclaringType;
				if (node.Constructor.DeclaringType.IsGenericInstance)
				{
					GenericInstanceType referenceGeneric = node.Constructor.DeclaringType as GenericInstanceType;
					if (declaringType.HasGenericParameters)
					{
						/// Transfer the parameters from reference up to the declaring type.
						/// Bare in mind, that the declaring type might have less generic parameters.
						/// Transfer just the first X that match.
						/// This is needed, because VB and C# don't allow other language syntax

						GenericInstanceType declaringTypeInstance = new GenericInstanceType(declaringType);

						Collection<TypeReference> nestedTypeBackup = new Collection<TypeReference>(referenceGeneric.GenericArguments);
						Collection<TypeReference> declaringBackup = new Collection<TypeReference>(declaringTypeInstance.GenericArguments);
						int parametersToMoveUp = declaringType.GenericParameters.Count;
						for (int i = 0; i < parametersToMoveUp; i++)
						{
							/// check if it moves the parameters forward or not
							declaringTypeInstance.AddGenericArgument(referenceGeneric.GenericArguments[i]);
							declaringTypeInstance.GenericArguments.Add(referenceGeneric.GenericArguments[i]);
						}
						WriteReferenceAndNamespaceIfInCollision(declaringTypeInstance);
						Write(".");
						if (referenceGeneric.GenericArguments.Count - parametersToMoveUp > 0)
						{
							WriteConstructorNameAndGenericArguments(node, true, parametersToMoveUp);
						}
						else
						{
							WriteConstructorNameAndGenericArguments(node, false);
						}
						referenceGeneric.GenericArguments.Clear();
						referenceGeneric.GenericArguments.AddRange(nestedTypeBackup);

						declaringTypeInstance.GenericArguments.Clear();
						declaringTypeInstance.GenericArguments.AddRange(declaringBackup);
						return;
					}
				}

				WriteReferenceAndNamespaceIfInCollision(declaringType);
				Write(".");
				WriteConstructorNameAndGenericArguments(node);
			}
			else
			{
				bool isTypeNameInCollision = IsTypeNameInCollision(node.Constructor.DeclaringType.Name);
				WriteNamespace(node.Constructor.DeclaringType.GetElementType(), isTypeNameInCollision);
				WriteConstructorNameAndGenericArguments(node);
			}
		}
开发者ID:GiGatR00n,项目名称:JustDecompileEngine,代码行数:82,代码来源:BaseImperativeLanguageWriter.cs

示例2: WriteReference

		private void WriteReference(TypeReference reference)
		{
			if (reference.DeclaringType != null)
			{
				TypeReference declaringType = reference.DeclaringType;
				if (reference.IsGenericInstance)
				{
					GenericInstanceType referenceGeneric = reference as GenericInstanceType;
					if (declaringType.HasGenericParameters)
					{
						/// Transfer the parameters from reference up to the declaring type.
						/// Bare in mind, that the declaring type might have less generic parameters.
						/// Transfer just the first X that match.
						/// This is needed, because VB and C# don't allow other language syntax

						GenericInstanceType declaringTypeInstance = new GenericInstanceType(declaringType);

						Collection<TypeReference> nestedTypeBackup = new Collection<TypeReference>(referenceGeneric.GenericArguments);
						Collection<TypeReference> declaringBackup = new Collection<TypeReference>(declaringTypeInstance.GenericArguments);
						int parametersToMoveUp = declaringType.GenericParameters.Count;
						for (int i = 0; i < parametersToMoveUp; i++)
						{
							/// check if it moves the parameters forward or not
							declaringTypeInstance.AddGenericArgument(referenceGeneric.GenericArguments[i]);
							declaringTypeInstance.GenericArguments.Add(referenceGeneric.GenericArguments[i]);
						}
						WriteReference(declaringTypeInstance);
						Write(".");
						if (referenceGeneric.GenericArguments.Count - parametersToMoveUp > 0)
						{
							WriteTypeSpecification(referenceGeneric, parametersToMoveUp);
						}
						else
						{
							string typeName = GetTypeName(reference);
							WriteReference(typeName, reference);
						}
						referenceGeneric.GenericArguments.Clear();
						referenceGeneric.GenericArguments.AddRange(nestedTypeBackup);

						declaringTypeInstance.GenericArguments.Clear();
						declaringTypeInstance.GenericArguments.AddRange(declaringBackup);
						return;
					}
					else
					{
						WriteReference(declaringType);
						Write(".");
					}
				}
				else
				{
					WriteReference(declaringType);
					Write(".");
				}
			}

			if (reference is TypeSpecification)
			{
				WriteTypeSpecification(reference as TypeSpecification);
				return;
			}

			string typeString;
			if (reference.Namespace != "System")
			{
				typeString = GetTypeName(reference);
			}
			else
			{
				typeString = ToTypeString(reference);

				if (reference.Scope.Name != "mscorlib" && reference.Scope.Name != "CommonLanguageRuntimeLibrary")
				{
					typeString = Utilities.EscapeTypeName(typeString, this.Language);
				}
			}

			if (reference.HasGenericParameters || (!Language.IsEscapedWord(typeString) && !Language.IsValidIdentifier(typeString)))
			{
				if (reference is TypeDefinition && reference.HasGenericParameters)
				{
					typeString = GetTypeName(reference);

					int genericParametersStartIndex = 0;
					if (reference.DeclaringType != null && reference.DeclaringType.HasGenericParameters)
					{
						genericParametersStartIndex = reference.DeclaringType.GenericParameters.Count;
					}

					if (genericParametersStartIndex < reference.GenericParameters.Count)
					{
						typeString += GenericLeftBracket;
						for (int i = genericParametersStartIndex; i < reference.GenericParameters.Count; i++)
						{
							if (i > genericParametersStartIndex)
							{
								typeString += ", ";
							}
							if (!Language.IsValidIdentifier(reference.GenericParameters[i].Name))
//.........这里部分代码省略.........
开发者ID:GiGatR00n,项目名称:JustDecompileEngine,代码行数:101,代码来源:BaseImperativeLanguageWriter.cs

示例3: HandleNestedGenericTypes

		private string HandleNestedGenericTypes(TypeReference parameterType)
		{
			/// Transfer the parameters from reference up to the declaring type.
			/// Bare in mind, that the declaring type might have less generic parameters.
			/// Transfer just the first X that match.
			/// This is needed, because VB and C# don't allow other language syntax
			StringBuilder result = new StringBuilder();
			TypeReference declaringType = parameterType.DeclaringType;
			GenericInstanceType referenceGeneric = parameterType as GenericInstanceType;

			GenericInstanceType declaringTypeInstance = new GenericInstanceType(declaringType);

			Collection<TypeReference> nestedTypeBackup = new Collection<TypeReference>(referenceGeneric.GenericArguments);
			Collection<TypeReference> declaringBackup = new Collection<TypeReference>(declaringTypeInstance.GenericArguments);
			int parametersToMoveUp = declaringType.GenericParameters.Count;
			for (int i = 0; i < parametersToMoveUp; i++)
			{
				declaringTypeInstance.AddGenericArgument(referenceGeneric.GenericArguments[i]);
				declaringTypeInstance.GenericArguments.Add(referenceGeneric.GenericArguments[i]);
			}
			result.Append(GetParameterTypeRepresentation(declaringTypeInstance));
			result.Append('.');
			if (referenceGeneric.GenericArguments.Count - parametersToMoveUp > 0)
			{
				result.Append(AppendGenericArguments(referenceGeneric, parametersToMoveUp));
			}
			else
			{
				string ptName = GenericHelper.GetNonGenericName(parameterType.Name);
				result.Append(ptName);
			}
			referenceGeneric.GenericArguments.Clear();
			referenceGeneric.GenericArguments.AddRange(nestedTypeBackup);

			declaringTypeInstance.GenericArguments.Clear();
			declaringTypeInstance.GenericArguments.AddRange(declaringBackup);
			return result.ToString();
		}
开发者ID:juancarlosbaezpozos,项目名称:JustDecompileEngine,代码行数:38,代码来源:DocumentationCache.cs


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