本文整理汇总了C#中Mono.CSharp.MethodGroupExpr类的典型用法代码示例。如果您正苦于以下问题:C# MethodGroupExpr类的具体用法?C# MethodGroupExpr怎么用?C# MethodGroupExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodGroupExpr类属于Mono.CSharp命名空间,在下文中一共展示了MethodGroupExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UserOperatorCall
public UserOperatorCall (MethodGroupExpr mg, Arguments args, ExpressionTreeExpression expr_tree, Location loc)
{
this.mg = mg;
this.arguments = args;
this.expr_tree = expr_tree;
type = TypeManager.TypeToCoreType (((MethodInfo) mg).ReturnType);
eclass = ExprClass.Value;
this.loc = loc;
}
示例2: MakeSimpleCall
static public Expression MakeSimpleCall (EmitContext ec, MethodGroupExpr mg,
Expression e, Location loc)
{
ArrayList args;
MethodBase method;
args = new ArrayList (1);
args.Add (new Argument (e, Argument.AType.Expression));
method = Invocation.OverloadResolve (ec, (MethodGroupExpr) mg, args, loc);
if (method == null)
return null;
return new StaticCallExpr ((MethodInfo) method, args, loc);
}
示例3: MakeUnionSet
public static MethodGroupExpr MakeUnionSet (Expression mg1, Expression mg2, Location loc)
{
MemberInfo [] miset;
MethodGroupExpr union;
if (mg1 == null){
if (mg2 == null)
return null;
return (MethodGroupExpr) mg2;
} else {
if (mg2 == null)
return (MethodGroupExpr) mg1;
}
MethodGroupExpr left_set = null, right_set = null;
int length1 = 0, length2 = 0;
left_set = (MethodGroupExpr) mg1;
length1 = left_set.Methods.Length;
right_set = (MethodGroupExpr) mg2;
length2 = right_set.Methods.Length;
ArrayList common = new ArrayList ();
foreach (MethodBase l in left_set.Methods){
foreach (MethodBase r in right_set.Methods){
if (l != r)
continue;
common.Add (r);
break;
}
}
miset = new MemberInfo [length1 + length2 - common.Count];
left_set.Methods.CopyTo (miset, 0);
int k = length1;
foreach (MemberInfo mi in right_set.Methods){
if (!common.Contains (mi))
miset [k++] = mi;
}
union = new MethodGroupExpr (miset, loc);
return union;
}
示例4: ImplicitDelegateCreation
public ImplicitDelegateCreation (TypeSpec delegateType, MethodGroupExpr mg, Location loc)
{
type = delegateType;
this.method_group = mg;
this.loc = loc;
}
示例5: DoResolve
protected override Expression DoResolve (ResolveContext ec)
{
constructor_method = Delegate.GetConstructor (type);
var invoke_method = Delegate.GetInvokeMethod (type);
if (!ec.HasSet (ResolveContext.Options.ConditionalAccessReceiver)) {
if (method_group.HasConditionalAccess ()) {
conditional_access_receiver = true;
ec.Set (ResolveContext.Options.ConditionalAccessReceiver);
}
}
Arguments arguments = CreateDelegateMethodArguments (ec, invoke_method.Parameters, invoke_method.Parameters.Types, loc);
method_group = method_group.OverloadResolve (ec, ref arguments, this, OverloadResolver.Restrictions.CovariantDelegate);
if (conditional_access_receiver)
ec.With (ResolveContext.Options.ConditionalAccessReceiver, false);
if (method_group == null)
return null;
var delegate_method = method_group.BestCandidate;
if (delegate_method.DeclaringType.IsNullableType) {
ec.Report.Error (1728, loc, "Cannot create delegate from method `{0}' because it is a member of System.Nullable<T> type",
delegate_method.GetSignatureForError ());
return null;
}
if (!AllowSpecialMethodsInvocation)
Invocation.IsSpecialMethodInvocation (ec, delegate_method, loc);
ExtensionMethodGroupExpr emg = method_group as ExtensionMethodGroupExpr;
if (emg != null) {
method_group.InstanceExpression = emg.ExtensionExpression;
TypeSpec e_type = emg.ExtensionExpression.Type;
if (TypeSpec.IsValueType (e_type)) {
ec.Report.Error (1113, loc, "Extension method `{0}' of value type `{1}' cannot be used to create delegates",
delegate_method.GetSignatureForError (), e_type.GetSignatureForError ());
}
}
TypeSpec rt = method_group.BestCandidateReturnType;
if (rt.BuiltinType == BuiltinTypeSpec.Type.Dynamic)
rt = ec.BuiltinTypes.Object;
if (!Delegate.IsTypeCovariant (ec, rt, invoke_method.ReturnType)) {
Expression ret_expr = new TypeExpression (delegate_method.ReturnType, loc);
Error_ConversionFailed (ec, delegate_method, ret_expr);
}
if (method_group.IsConditionallyExcluded) {
ec.Report.SymbolRelatedToPreviousError (delegate_method);
MethodOrOperator m = delegate_method.MemberDefinition as MethodOrOperator;
if (m != null && m.IsPartialDefinition) {
ec.Report.Error (762, loc, "Cannot create delegate from partial method declaration `{0}'",
delegate_method.GetSignatureForError ());
} else {
ec.Report.Error (1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute",
TypeManager.CSharpSignature (delegate_method));
}
}
var expr = method_group.InstanceExpression;
if (expr != null && (expr.Type.IsGenericParameter || !TypeSpec.IsReferenceType (expr.Type)))
method_group.InstanceExpression = new BoxedCast (expr, ec.BuiltinTypes.Object);
eclass = ExprClass.Value;
return this;
}
示例6: ImplicitDelegateCreation
ImplicitDelegateCreation (TypeSpec t, MethodGroupExpr mg, Location l)
{
type = t;
this.method_group = mg;
loc = l;
}
示例7: MakeUnionSet
public static MethodGroupExpr MakeUnionSet(MethodGroupExpr mg1, MethodGroupExpr mg2, Location loc)
{
if (mg1 == null) {
if (mg2 == null)
return null;
return mg2;
}
if (mg2 == null)
return mg1;
var all = new List<MemberSpec> (mg1.Methods);
foreach (MethodSpec m in mg2.Methods){
if (!TypeManager.ArrayContainsMethod (all, m, false))
all.Add (m);
}
return new MethodGroupExpr (all, null, loc);
}
示例8: DoResolve
//.........这里部分代码省略.........
return null;
}
if (Arguments == null) {
Constant c = Constantify (type);
if (c != null)
return ReducedExpression.Create (c, this);
}
if (TypeManager.IsDelegateType (type)) {
return (new NewDelegate (type, Arguments, loc)).Resolve (ec);
}
if (TypeManager.IsGenericParameter (type)) {
GenericConstraints gc = TypeManager.GetTypeParameterConstraints (type);
if ((gc == null) || (!gc.HasConstructorConstraint && !gc.IsValueType)) {
ec.Report.Error (304, loc,
"Cannot create an instance of the variable type '{0}' because it doesn't have the new() constraint",
TypeManager.CSharpName (type));
return null;
}
if ((Arguments != null) && (Arguments.Count != 0)) {
ec.Report.Error (417, loc,
"`{0}': cannot provide arguments when creating an instance of a variable type",
TypeManager.CSharpName (type));
return null;
}
if (TypeManager.activator_create_instance == null) {
Type activator_type = TypeManager.CoreLookupType (ec.Compiler, "System", "Activator", Kind.Class, true);
if (activator_type != null) {
TypeManager.activator_create_instance = TypeManager.GetPredefinedMethod (
activator_type, "CreateInstance", loc, Type.EmptyTypes);
}
}
is_type_parameter = true;
eclass = ExprClass.Value;
return this;
}
if (type.IsAbstract && type.IsSealed) {
ec.Report.SymbolRelatedToPreviousError (type);
ec.Report.Error (712, loc, "Cannot create an instance of the static class `{0}'", TypeManager.CSharpName (type));
return null;
}
if (type.IsInterface || type.IsAbstract){
if (!TypeManager.IsGenericType (type)) {
RequestedType = CheckComImport (ec);
if (RequestedType != null)
return RequestedType;
}
ec.Report.SymbolRelatedToPreviousError (type);
ec.Report.Error (144, loc, "Cannot create an instance of the abstract class or interface `{0}'", TypeManager.CSharpName (type));
return null;
}
bool is_struct = TypeManager.IsStruct (type);
eclass = ExprClass.Value;
//
// SRE returns a match for .ctor () on structs (the object constructor),
// so we have to manually ignore it.
//
if (is_struct && Arguments == null)
return this;
// For member-lookup, treat 'new Foo (bar)' as call to 'foo.ctor (bar)', where 'foo' is of type 'Foo'.
Expression ml = MemberLookupFinal (ec, type, type, ConstructorInfo.ConstructorName,
MemberTypes.Constructor, AllBindingFlags | BindingFlags.DeclaredOnly, loc);
if (Arguments != null) {
bool dynamic;
Arguments.Resolve (ec, out dynamic);
if (dynamic) {
Arguments.Insert (0, new Argument (new TypeOf (texpr, loc).Resolve (ec)));
return new DynamicInvocation (new SimpleName (ConstructorInfo.ConstructorName, loc), Arguments, type, loc).Resolve (ec);
}
}
if (ml == null)
return null;
method = ml as MethodGroupExpr;
if (method == null) {
ml.Error_UnexpectedKind (ec, ResolveFlags.MethodGroup, loc);
return null;
}
method = method.OverloadResolve (ec, ref Arguments, false, loc);
if (method == null)
return null;
return this;
}
示例9: ConditionalLogicalOperator
public ConditionalLogicalOperator (MethodGroupExpr oper_method, Arguments arguments,
ExpressionTreeExpression expr_tree, bool is_and, Location loc)
: base (oper_method, arguments, expr_tree, loc)
{
this.is_and = is_and;
}
示例10: ImplicitStandardConversionExists
public static bool ImplicitStandardConversionExists (ResolveContext ec, MethodGroupExpr mg, Type target_type)
{
if (target_type == TypeManager.delegate_type || target_type == TypeManager.multicast_delegate_type)
return false;
mg.DelegateType = target_type;
MethodInfo invoke = Delegate.GetInvokeMethod (ec.Compiler, null, target_type);
Arguments arguments = CreateDelegateMethodArguments (TypeManager.GetParameterData (invoke), mg.Location);
return mg.OverloadResolve (ec, ref arguments, true, mg.Location) != null;
}
示例11: DoResolve
public override Expression DoResolve (ResolveContext ec)
{
constructor_method = Delegate.GetConstructor (ec.Compiler, ec.CurrentType, type);
MethodInfo invoke_method = Delegate.GetInvokeMethod (ec.Compiler, ec.CurrentType, type);
method_group.DelegateType = type;
method_group.CustomErrorHandler = this;
Arguments arguments = CreateDelegateMethodArguments (TypeManager.GetParameterData (invoke_method), loc);
method_group = method_group.OverloadResolve (ec, ref arguments, false, loc);
if (method_group == null)
return null;
delegate_method = (MethodInfo) method_group;
if (TypeManager.IsNullableType (delegate_method.DeclaringType)) {
ec.Report.Error (1728, loc, "Cannot create delegate from method `{0}' because it is a member of System.Nullable<T> type",
TypeManager.GetFullNameSignature (delegate_method));
return null;
}
Invocation.IsSpecialMethodInvocation (ec, delegate_method, loc);
ExtensionMethodGroupExpr emg = method_group as ExtensionMethodGroupExpr;
if (emg != null) {
delegate_instance_expression = emg.ExtensionExpression;
Type e_type = delegate_instance_expression.Type;
if (TypeManager.IsValueType (e_type)) {
ec.Report.Error (1113, loc, "Extension method `{0}' of value type `{1}' cannot be used to create delegates",
TypeManager.CSharpSignature (delegate_method), TypeManager.CSharpName (e_type));
}
}
Type rt = TypeManager.TypeToCoreType (delegate_method.ReturnType);
Expression ret_expr = new TypeExpression (rt, loc);
if (!Delegate.IsTypeCovariant (ret_expr, (TypeManager.TypeToCoreType (invoke_method.ReturnType)))) {
Error_ConversionFailed (ec, delegate_method, ret_expr);
}
if (Invocation.IsMethodExcluded (delegate_method, loc)) {
ec.Report.SymbolRelatedToPreviousError (delegate_method);
MethodOrOperator m = TypeManager.GetMethod (delegate_method) as MethodOrOperator;
if (m != null && m.IsPartialDefinition) {
ec.Report.Error (762, loc, "Cannot create delegate from partial method declaration `{0}'",
TypeManager.CSharpSignature (delegate_method));
} else {
ec.Report.Error (1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute",
TypeManager.CSharpSignature (delegate_method));
}
}
DoResolveInstanceExpression (ec);
eclass = ExprClass.Value;
return this;
}
示例12: VerifyApplicability
// <summary>
// Verifies whether the invocation arguments are compatible with the
// delegate's target method
// </summary>
public static bool VerifyApplicability (ResolveContext ec, Type delegate_type, ref Arguments args, Location loc)
{
int arg_count;
if (args == null)
arg_count = 0;
else
arg_count = args.Count;
MethodBase mb = GetInvokeMethod (ec.Compiler, ec.CurrentType, delegate_type);
MethodGroupExpr me = new MethodGroupExpr (new MemberInfo [] { mb }, delegate_type, loc);
AParametersCollection pd = TypeManager.GetParameterData (mb);
int pd_count = pd.Count;
bool params_method = pd.HasParams;
bool is_params_applicable = false;
bool is_applicable = me.IsApplicable (ec, ref args, arg_count, ref mb, ref is_params_applicable) == 0;
if (args != null)
arg_count = args.Count;
if (!is_applicable && !params_method && arg_count != pd_count) {
ec.Report.Error (1593, loc, "Delegate `{0}' does not take `{1}' arguments",
TypeManager.CSharpName (delegate_type), arg_count.ToString ());
return false;
}
return me.VerifyArgumentsCompat (
ec, ref args, arg_count, mb,
is_params_applicable || (!is_applicable && params_method),
false, loc);
}
示例13: DoResolve
protected override Expression DoResolve(ResolveContext ec)
{
if (InstanceExpr is EventExpr) {
((EventExpr) InstanceExpr).Error_CannotAssign (ec);
return null;
}
TypeSpec del_type = InstanceExpr.Type;
if (del_type == null)
return null;
method = Delegate.GetInvokeMethod (ec.Compiler, del_type);
var mb = method;
var me = new MethodGroupExpr (mb, del_type, loc);
me.InstanceExpression = InstanceExpr;
AParametersCollection pd = mb.Parameters;
int pd_count = pd.Count;
int arg_count = arguments == null ? 0 : arguments.Count;
bool params_method = pd.HasParams;
bool is_params_applicable = false;
bool is_applicable = me.IsApplicable (ec, ref arguments, arg_count, ref mb, ref is_params_applicable) == 0;
if (arguments != null)
arg_count = arguments.Count;
if (!is_applicable && !params_method && arg_count != pd_count) {
ec.Report.Error (1593, loc, "Delegate `{0}' does not take `{1}' arguments",
TypeManager.CSharpName (del_type), arg_count.ToString ());
} else if (arguments == null || !arguments.HasDynamic) {
me.VerifyArgumentsCompat (ec, ref arguments, arg_count, mb,
is_params_applicable || (!is_applicable && params_method), false, loc);
}
type = method.ReturnType;
eclass = ExprClass.Value;
return this;
}
示例14: DoResolve
public override Expression DoResolve (ResolveContext ec)
{
eclass = ExprClass.Value;
// TODO: ec.GetSignatureForError ()
ConstructorBuilder caller_builder = ((Constructor) ec.MemberContext).ConstructorBuilder;
if (argument_list != null) {
bool dynamic;
//
// Spec mandates that constructor initializer will not have `this' access
//
using (ec.Set (ResolveContext.Options.BaseInitializer)) {
argument_list.Resolve (ec, out dynamic);
}
if (dynamic) {
SimpleName ctor = new SimpleName (ConstructorBuilder.ConstructorName, loc);
return new DynamicInvocation (ctor, argument_list, loc).Resolve (ec) as ExpressionStatement;
}
}
type = ec.CurrentType;
if (this is ConstructorBaseInitializer) {
if (ec.CurrentType.BaseType == null)
return this;
type = ec.CurrentType.BaseType;
if (TypeManager.IsStruct (ec.CurrentType)) {
ec.Report.Error (522, loc,
"`{0}': Struct constructors cannot call base constructors", TypeManager.CSharpSignature (caller_builder));
return this;
}
} else {
//
// It is legal to have "this" initializers that take no arguments
// in structs, they are just no-ops.
//
// struct D { public D (int a) : this () {}
//
if (TypeManager.IsStruct (ec.CurrentType) && argument_list == null)
return this;
}
base_constructor_group = MemberLookupFinal (
ec, null, type, ConstructorBuilder.ConstructorName, MemberTypes.Constructor,
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
loc) as MethodGroupExpr;
if (base_constructor_group == null)
return this;
base_constructor_group = base_constructor_group.OverloadResolve (
ec, ref argument_list, false, loc);
if (base_constructor_group == null)
return this;
if (!ec.IsStatic)
base_constructor_group.InstanceExpression = ec.GetThis (loc);
ConstructorInfo base_ctor = (ConstructorInfo)base_constructor_group;
if (base_ctor == caller_builder){
ec.Report.Error (516, loc, "Constructor `{0}' cannot call itself", TypeManager.CSharpSignature (caller_builder));
}
return this;
}
示例15: OverloadResolve
/// <summary>
/// Find the Applicable Function Members (7.4.2.1)
///
/// me: Method Group expression with the members to select.
/// it might contain constructors or methods (or anything
/// that maps to a method).
///
/// Arguments: ArrayList containing resolved Argument objects.
///
/// loc: The location if we want an error to be reported, or a Null
/// location for "probing" purposes.
///
/// Returns: The MethodBase (either a ConstructorInfo or a MethodInfo)
/// that is the best match of me on Arguments.
///
/// </summary>
public static MethodBase OverloadResolve (EmitContext ec, MethodGroupExpr me,
ArrayList Arguments, Location loc)
{
MethodBase method = null;
Type current_type = null;
int argument_count;
ArrayList candidates = new ArrayList ();
foreach (MethodBase candidate in me.Methods){
int x;
// If we're going one level higher in the class hierarchy, abort if
// we already found an applicable method.
if (candidate.DeclaringType != current_type) {
current_type = candidate.DeclaringType;
if (method != null)
break;
}
// Check if candidate is applicable (section 14.4.2.1)
if (!IsApplicable (ec, Arguments, candidate))
continue;
candidates.Add (candidate);
x = BetterFunction (ec, Arguments, candidate, method, false, loc);
if (x == 0)
continue;
method = candidate;
}
if (Arguments == null)
argument_count = 0;
else
argument_count = Arguments.Count;
//
// Now we see if we can find params functions, applicable in their expanded form
// since if they were applicable in their normal form, they would have been selected
// above anyways
//
bool chose_params_expanded = false;
if (method == null) {
candidates = new ArrayList ();
foreach (MethodBase candidate in me.Methods){
if (!IsParamsMethodApplicable (ec, Arguments, candidate))
continue;
candidates.Add (candidate);
int x = BetterFunction (ec, Arguments, candidate, method, true, loc);
if (x == 0)
continue;
method = candidate;
chose_params_expanded = true;
}
}
if (method == null) {
//
// Okay so we have failed to find anything so we
// return by providing info about the closest match
//
for (int i = 0; i < me.Methods.Length; ++i) {
MethodBase c = (MethodBase) me.Methods [i];
ParameterData pd = GetParameterData (c);
if (pd.Count != argument_count)
continue;
VerifyArgumentsCompat (ec, Arguments, argument_count, c, false,
null, loc);
}
return null;
}
//
// Now check that there are no ambiguities i.e the selected method
//.........这里部分代码省略.........