本文整理汇总了C#中TypeNode.GetMethod方法的典型用法代码示例。如果您正苦于以下问题:C# TypeNode.GetMethod方法的具体用法?C# TypeNode.GetMethod怎么用?C# TypeNode.GetMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeNode
的用法示例。
在下文中一共展示了TypeNode.GetMethod方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMethod
private Method GetMethod(TypeNode type, string name, params TypeNode[] argTypes)
{
var res = type.GetMethod(Identifier.For(name), argTypes);
if (res == null)
{
Log(new InvalidInteropMessage(null, "can't load required method: " + name));
throw new ExitException();
}
return res;
}
示例2: ImplicitCoercion
//.........这里部分代码省略.........
if (uex.Operand == null) return null;
uex.Type = uex.Operand.Type;
return uex;
}
bool targetIsNonNullType = this.IsNonNullType(targetType);
targetType = TypeNode.StripModifier(targetType, SystemTypes.NonNullType);
targetType = TypeNode.StripModifier(targetType, SystemTypes.NullableType);
//TODO: handle SkipCheck and EnforceCheck
//Special case for closure expressions
if (source.NodeType == NodeType.AnonymousNestedFunction)
return this.CoerceAnonymousNestedFunction((AnonymousNestedFunction)source, targetType, false, typeViewer);
TypeNode sourceType = source.Type;
if (sourceType == null) sourceType = SystemTypes.Object;
bool sourceIsNonNullType = this.IsNonNullType(source.Type);
sourceType = TypeNode.StripModifier(sourceType, SystemTypes.NonNullType);
sourceType = TypeNode.StripModifier(sourceType, SystemTypes.NullableType);
if (sourceType == SystemTypes.String && !sourceIsNonNullType && source is Literal)
sourceIsNonNullType = ((Literal)source).Value != null;
if (this.currentParameter != null && targetType is Reference){
UnaryExpression uex = source as UnaryExpression;
if (uex != null){
if (sourceIsNonNullType && !targetIsNonNullType){
string ttypeName = this.GetTypeName(targetType);
string stypeName = this.GetTypeName(source.Type);
this.HandleError(source, Error.NoImplicitCoercion, stypeName, ttypeName);
return null;
}
if (!sourceIsNonNullType && targetIsNonNullType){
string ttypeName = this.GetTypeName(targetType);
string stypeName = this.GetTypeName(source.Type);
this.HandleError(source, Error.NoImplicitCoercion, stypeName, ttypeName);
return null;
}
if (uex.NodeType == NodeType.OutAddress){
if ((this.currentParameter.Flags & ParameterFlags.Out) == 0){
this.currentParameter.Flags |= ParameterFlags.Out;
string stypeName = this.GetTypeName(sourceType);
this.currentParameter.Flags &= ~ParameterFlags.Out;
this.HandleError(source, Error.NoImplicitCoercion, stypeName, this.GetTypeName(targetType));
return null;
}
}else if (uex.NodeType == NodeType.RefAddress){
if ((this.currentParameter.Flags & ParameterFlags.Out) != 0){
this.currentParameter.Flags &= ~ParameterFlags.Out;
string stypeName = this.GetTypeName(sourceType);
this.currentParameter.Flags |= ParameterFlags.Out;
this.HandleError(source, Error.NoImplicitCoercion, stypeName, this.GetTypeName(targetType));
return null;
}
}
}
}
Expression result = this.StandardImplicitCoercion(source, sourceIsNonNullType, sourceType, targetIsNonNullType, targetType, originalTargetType, typeViewer);
if (result != null) return result;
Method coercion = this.UserDefinedImplicitCoercionMethod(source, sourceType, targetType, true, typeViewer);
if (coercion != null){
if (this.IsNullableType(targetType) && this.IsNullableType(sourceType) && !this.IsNullableType(coercion.Parameters[0].Type))
return this.CoerceWithLiftedCoercion(source, sourceType, targetType, coercion, false, typeViewer);
ExpressionList args = new ExpressionList(1);
args.Add(this.ImplicitCoercion(source, coercion.Parameters[0].Type, typeViewer));
return this.ImplicitCoercion(new MethodCall(new MemberBinding(null, coercion), args, NodeType.Call, coercion.ReturnType, source.SourceContext), targetType, typeViewer);
}
if (sourceType == SystemTypes.Type && source is Literal)
this.HandleError(source, Error.TypeInVariableContext, this.GetTypeName((TypeNode)((Literal)source).Value), "class", "variable");
else if (this.IsNullableType(sourceType) && this.IsNullableType(targetType) && this.ImplicitCoercionFromTo(this.RemoveNullableWrapper(sourceType), this.RemoveNullableWrapper(targetType))) {
TypeNode usType = this.RemoveNullableWrapper(sourceType);
TypeNode utType = this.RemoveNullableWrapper(targetType);
Local tempSrc = new Local(sourceType);
Local tempTar = new Local(targetType);
StatementList statements = new StatementList();
BlockExpression result1 = new BlockExpression(new Block(statements));
statements.Add(new AssignmentStatement(tempSrc, source));
Method hasValue = sourceType.GetMethod(StandardIds.getHasValue);
Method getValueOrDefault = sourceType.GetMethod(StandardIds.GetValueOrDefault);
Method ctor = targetType.GetMethod(StandardIds.Ctor, utType);
Block pushValue = new Block();
Block done = new Block();
Expression tempHasValue = new MethodCall(new MemberBinding(new UnaryExpression(tempSrc, NodeType.AddressOf), hasValue), null);
tempHasValue.Type = SystemTypes.Boolean;
statements.Add(new Branch(tempHasValue, pushValue));
statements.Add(new AssignmentStatement(new AddressDereference(new UnaryExpression(tempTar, NodeType.AddressOf), targetType), new Literal(null, CoreSystemTypes.Object)));
statements.Add(new Branch(null, done));
statements.Add(pushValue);
Expression value = new MethodCall(new MemberBinding(new UnaryExpression(tempSrc, NodeType.AddressOf), getValueOrDefault), null);
value.Type = usType;
value = this.ImplicitCoercion(value, utType);
Construct cons = new Construct(new MemberBinding(null, ctor), new ExpressionList(value));
result1.Type = ctor.DeclaringType;
statements.Add(new AssignmentStatement(tempTar, cons));
statements.Add(done);
statements.Add(new ExpressionStatement(tempTar));
return result1;
}else
this.HandleError(source, Error.NoImplicitCoercion, this.GetTypeName(sourceType), this.GetTypeName(originalTargetType));
return null;
}