本文整理汇总了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);
}
}
示例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))
//.........这里部分代码省略.........
示例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();
}