本文整理汇总了C#中DomReturnType.AddTypeParameter方法的典型用法代码示例。如果您正苦于以下问题:C# DomReturnType.AddTypeParameter方法的具体用法?C# DomReturnType.AddTypeParameter怎么用?C# DomReturnType.AddTypeParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DomReturnType
的用法示例。
在下文中一共展示了DomReturnType.AddTypeParameter方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTypeSafe
public IReturnType GetTypeSafe (Expression expression)
{
ResolveResult result = Resolve (expression);
if (expression is LambdaExpression) {
var lambda = (LambdaExpression)expression;
var bodyType = GetTypeSafe (lambda.ExpressionBody);
DomReturnType constructedLambdaType = new DomReturnType (bodyType.FullName == DomReturnType.Void.FullName ? "System.Action" : "System.Func");
foreach (var param in lambda.Parameters) {
var typeParam = GetTypeSafe (param);
// add void place holder for types that can't be resolved.
if (typeParam == null || string.IsNullOrEmpty (typeParam.FullName))
typeParam = DomReturnType.Void;
constructedLambdaType.AddTypeParameter (typeParam);
}
if (bodyType.FullName != DomReturnType.Void.FullName)
constructedLambdaType.AddTypeParameter (bodyType ?? result.ResolvedType);
return constructedLambdaType;
}
return result.ResolvedType ?? DomReturnType.Void;
}
示例2: AddTypeArguments
void AddTypeArguments (ATypeNameExpression texpr, DomReturnType result)
{
if (!texpr.HasTypeArguments)
return;
foreach (var arg in texpr.TypeArguments.Args) {
result.AddTypeParameter (ConvertReturnType (arg));
}
}
示例3: ExtensionMethod
public ExtensionMethod (IType extensionType, IMethod originalMethod, IList<IReturnType> genericArguments, IEnumerable<IReturnType> methodArguments)
{
if (extensionType == null)
throw new ArgumentNullException ("extensionType");
if (originalMethod == null)
throw new ArgumentNullException ("originalMethod");
this.DeclaringType = extensionType;
List<IReturnType> args = new List<IReturnType> ();
if (extensionType.FullName.EndsWith ("[]")) {
foreach (IReturnType returnType in extensionType.BaseTypes) {
if (returnType.FullName == "System.Collections.Generic.IList" && returnType.GenericArguments.Count > 0) {
args.Add (returnType.GenericArguments[0]);
break;
}
}
if (args.Count == 0)
args.Add (new DomReturnType (extensionType));
} else if (extensionType is InstantiatedType) {
InstantiatedType instType = (InstantiatedType)extensionType;
DomReturnType uninstantiatedReturnType = new DomReturnType (instType.UninstantiatedType.FullName);
foreach (IReturnType genArg in instType.GenericParameters) {
uninstantiatedReturnType.AddTypeParameter (genArg);
}
args.Add (uninstantiatedReturnType);
} else {
args.Add (new DomReturnType (extensionType));
}
if (methodArguments != null)
args.AddRange (methodArguments);
// Console.WriteLine ("Create Extension method from:");
// Console.WriteLine ("ext type:" + args[0]);
// Console.WriteLine (originalMethod);
this.method = DomMethod.CreateInstantiatedGenericMethod (originalMethod, genericArguments, args);
// skip first parameter.
for (int i = 1; i < method.Parameters.Count; i++) {
Add (method.Parameters[i]);
}
foreach (ITypeParameter par in method.TypeParameters) {
AddTypeParameter (par);
}
this.ExtensionType = extensionType;
this.OriginalMethod = originalMethod;
//Console.WriteLine (this);
//Console.WriteLine ("oOoOoOoOoOoOoOoOoOoOoOoOoOoO");
}
示例4: VisitMemberReferenceExpression
public override object VisitMemberReferenceExpression (MemberReferenceExpression memberReferenceExpression, object data)
{
if (memberReferenceExpression == null) {
return null;
}
ResolveResult result;
if (String.IsNullOrEmpty (memberReferenceExpression.MemberName)) {
if (memberReferenceExpression.TargetObject is TypeReferenceExpression) {
result = CreateResult (((TypeReferenceExpression)memberReferenceExpression.TargetObject).TypeReference);
result.StaticResolve = true;
return result;
}
// if (memberReferenceExpression.TargetObject is ThisReferenceExpression) {
// result = CreateResult (((TypeReferenceExpression)memberReferenceExpression.TargetObject).TypeReference);
// result.StaticResolve = true;
// return result;
// }
// return memberReferenceExpression.TargetObject.AcceptVisitor(this, data);
}
result = memberReferenceExpression.TargetObject.AcceptVisitor (this, data) as ResolveResult;
NamespaceResolveResult namespaceResult = result as NamespaceResolveResult;
if (namespaceResult != null) {
if (String.IsNullOrEmpty (memberReferenceExpression.MemberName))
return namespaceResult;
string fullName = namespaceResult.Namespace + "." + memberReferenceExpression.MemberName;
if (resolver.Dom.NamespaceExists (fullName, true))
return new NamespaceResolveResult (fullName);
DomReturnType searchType = new DomReturnType (fullName);
if (memberReferenceExpression.TypeArguments != null) {
foreach (TypeReference typeRef in memberReferenceExpression.TypeArguments) {
searchType.AddTypeParameter (NRefactoryResolver.ConvertTypeReference (typeRef));
}
}
IType type = resolver.Dom.GetType (searchType);
if (type != null) {
result = CreateResult (this.resolver.Unit, new DomReturnType (type));
result.StaticResolve = true;
return result;
}
return null;
}
if (result != null && result.ResolvedType != null) {
foreach (ResolveResult innerResult in result.ResolveResults) {
ResolveResult resolvedResult = ResolveMemberReference (innerResult, memberReferenceExpression);
if (resolvedResult != null)
return resolvedResult;
}
} else {
if (result != null)
MonoDevelop.Core.LoggingService.LogWarning ("Couldn't resolve type " + result.ResolvedType);
}
return null;
}
示例5: ConvertToReturnType
public static DomReturnType ConvertToReturnType (this AstType typeRef)
{
if (typeRef == null)
return null;
DomReturnType result;
if (typeRef is SimpleType) {
var st = (SimpleType)typeRef;
result = new DomReturnType (st.Identifier);
foreach (var arg in st.TypeArguments){
result.AddTypeParameter (ConvertToReturnType (arg));
}
} else if (typeRef is ICSharpCode.NRefactory.CSharp.MemberType) {
var mt = (ICSharpCode.NRefactory.CSharp.MemberType)typeRef;
result = ConvertToReturnType (mt.Target);
result.Parts.Add (new ReturnTypePart (mt.MemberName));
foreach (var arg in mt.TypeArguments){
result.AddTypeParameter (ConvertToReturnType (arg));
}
} else if (typeRef is ComposedType) {
var ct = (ComposedType)typeRef;
result = ConvertToReturnType (ct.BaseType);
result.PointerNestingLevel = ct.PointerRank;
result.IsNullable = ct.HasNullableSpecifier;
int arraySpecifiers = ct.ArraySpecifiers.Count;
if (arraySpecifiers> 0) {
result.ArrayDimensions = arraySpecifiers;
int i = 0;
foreach (var spec in ct.ArraySpecifiers) {
result.SetDimension (i, spec.Dimensions);
i++;
}
}
} else if (typeRef is PrimitiveType) {
var pt = (PrimitiveType)typeRef;
result = new DomReturnType (pt.Keyword);
} else if (typeRef.IsNull) {
return null;
} else {
throw new InvalidOperationException ("unknown AstType:" + typeRef);
}
return result;
}
示例6: ReadWriteReturnTypeTest
public void ReadWriteReturnTypeTest ()
{
DomReturnType input = new DomReturnType ();
input.Name = "Test";
input.Namespace = "Namespace";
input.ArrayDimensions = 5;
input.IsByRef = true;
input.IsNullable = true;
input.PointerNestingLevel = 666;
input.AddTypeParameter (new DomReturnType ("System.String"));
input.AddTypeParameter (new DomReturnType ("System.Int32"));
MemoryStream ms = new MemoryStream ();
BinaryWriter writer = new BinaryWriter (ms);
DomPersistence.Write (writer, DefaultNameEncoder, input);
byte[] bytes = ms.ToArray ();
IReturnType result = DomPersistence.ReadReturnType (CreateReader (bytes), DefaultNameDecoder);
Assert.AreEqual ("Test", result.Name);
Assert.AreEqual ("Namespace", result.Namespace);
Assert.AreEqual ("Namespace.Test", result.FullName);
Assert.AreEqual (5, result.ArrayDimensions);
Assert.AreEqual (true, result.IsByRef);
Assert.AreEqual (true, result.IsNullable);
Assert.AreEqual ("System.String", result.GenericArguments[0].FullName);
Assert.AreEqual ("System.Int32", result.GenericArguments[1].FullName);
}
示例7: ConvertTypeReference
static IReturnType ConvertTypeReference (TypeReference typeRef)
{
if (typeRef == null)
return null;
DomReturnType result = new DomReturnType (typeRef.Type);
foreach (TypeReference genericArgument in typeRef.GenericTypes) {
result.AddTypeParameter (ConvertTypeReference (genericArgument));
}
result.PointerNestingLevel = typeRef.PointerNestingLevel;
if (typeRef.IsArrayType) {
result.ArrayDimensions = typeRef.RankSpecifier.Length;
for (int i = 0; i < typeRef.RankSpecifier.Length; i++) {
result.SetDimension (i, typeRef.RankSpecifier[i]);
}
}
return result;
}
示例8: InstantiatedMethodByArgumentTest_Complex
public void InstantiatedMethodByArgumentTest_Complex ()
{
// build "T MyMethod<T,S> (S b, KeyValuePair<S, T> a)"
DomMethod method = new DomMethod ();
method.Name = "MyMethod";
method.ReturnType = new DomReturnType ("T");
method.AddTypeParameter (new TypeParameter ("T"));
method.AddTypeParameter (new TypeParameter ("S"));
method.Add (new DomParameter (method, "b", new DomReturnType ("S")));
DomReturnType returnType = new DomReturnType ("KeyValuePair");
returnType.AddTypeParameter (new DomReturnType ("T"));
returnType.AddTypeParameter (new DomReturnType ("S"));
method.Add (new DomParameter (method, "a", returnType));
// give int, object as param type
List<IReturnType> genArgs = new List<IReturnType> ();
List<IReturnType> args = new List<IReturnType> ();
genArgs.Add (DomReturnType.Int32);
genArgs.Add (DomReturnType.Object);
IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod (method, genArgs, args);
// check
Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.ReturnType.FullName);
Assert.AreEqual (DomReturnType.Object.FullName, instMethod.Parameters[0].ReturnType.FullName);
Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.Parameters[1].ReturnType.GenericArguments[0].FullName);
Assert.AreEqual (DomReturnType.Object.FullName, instMethod.Parameters[1].ReturnType.GenericArguments[1].FullName);
}
示例9: InstantiatedMethodByArgumentTestComplex2
public void InstantiatedMethodByArgumentTestComplex2 ()
{
// build "T MyMethod<T> (MyType<T> a)"
DomMethod method = new DomMethod ();
method.Name = "MyMethod";
method.ReturnType = new DomReturnType ("T");
method.AddTypeParameter (new TypeParameter ("T"));
DomReturnType returnType = new DomReturnType ("MyType");
returnType.AddTypeParameter (new DomReturnType ("T"));
method.Add (new DomParameter (method, "a", returnType));
// give int as param type
List<IReturnType> genArgs = new List<IReturnType> ();
List<IReturnType> args = new List<IReturnType> ();
returnType = new DomReturnType ("MyType");
returnType.AddTypeParameter (DomReturnType.Int32);
args.Add (returnType);
IMethod instMethod = DomMethod.CreateInstantiatedGenericMethod (method, genArgs, args);
// check
Assert.AreEqual (DomReturnType.Int32.FullName, instMethod.ReturnType.FullName);
}
示例10: ExtensionMethodTest
public void ExtensionMethodTest ()
{
// build "T MyMethod<T, S> (this KeyValuePair<T, S> a, S b)"
DomMethod method = new DomMethod ();
method.Name = "MyMethod";
method.ReturnType = new DomReturnType ("T");
method.AddTypeParameter (new TypeParameter ("T"));
method.AddTypeParameter (new TypeParameter ("S"));
DomReturnType returnType = new DomReturnType ("KeyValuePair");
returnType.AddTypeParameter (new DomReturnType ("T"));
returnType.AddTypeParameter (new DomReturnType ("S"));
method.Add (new DomParameter (method, "a", returnType));
method.Add (new DomParameter (method, "b", new DomReturnType ("S")));
// Build extendet type KeyValuePair<int, object>
DomType type = new DomType ("KeyValuePair");
type.AddTypeParameter (new TypeParameter ("T"));
type.AddTypeParameter (new TypeParameter ("S"));
IType extType = DomType.CreateInstantiatedGenericTypeInternal (type, new IReturnType[] { DomReturnType.Int32, DomReturnType.Object });
Console.WriteLine (extType);
// extend method
List<IReturnType> genArgs = new List<IReturnType> ();
List<IReturnType> args = new List<IReturnType> ();
ExtensionMethod extMethod = new ExtensionMethod (extType, method, genArgs, args);
Console.WriteLine (extMethod);
// check
Assert.AreEqual (DomReturnType.Int32.FullName, extMethod.ReturnType.FullName);
Assert.AreEqual (DomReturnType.Object.FullName, extMethod.Parameters[0].ReturnType.FullName);
}