本文整理汇总了C#中Mono.CSharp.Method类的典型用法代码示例。如果您正苦于以下问题:C# Method类的具体用法?C# Method怎么用?C# Method使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Method类属于Mono.CSharp命名空间,在下文中一共展示了Method类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: case_166
void case_166()
#line 1283 "cs-parser.jay"
{
lexer.ConstraintsParsing = false;
valid_param_mod = 0;
MemberName name = (MemberName) yyVals[-6+yyTop];
current_local_parameters = (ParametersCompiled) yyVals[-3+yyTop];
GenericMethod generic = null;
if (name.TypeArguments != null) {
generic = new GenericMethod (current_namespace, current_class, name,
(FullNamedExpression) yyVals[-7+yyTop], current_local_parameters);
generic.SetParameterInfo ((List<Constraints>) yyVals[0+yyTop]);
} else if (yyVals[0+yyTop] != null) {
Report.Error (80, GetLocation (yyVals[0+yyTop]),
"Constraints are not allowed on non-generic declarations");
}
Method method = new Method (current_class, generic, (FullNamedExpression) yyVals[-7+yyTop], (Modifiers) yyVals[-8+yyTop],
name, current_local_parameters, (Attributes) yyVals[-9+yyTop]);
if (yyVals[0+yyTop] != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) {
Report.Error (460, method.Location,
"`{0}': Cannot specify constraints for overrides and explicit interface implementation methods",
method.GetSignatureForError ());
}
if (RootContext.Documentation != null)
method.DocComment = Lexer.consume_doc_comment ();
lbag.AddMember (method, GetModifierLocations (), GetLocation (yyVals[-5+yyTop]), GetLocation (yyVals[-2+yyTop]));
yyVal = method;
}
示例2: Create
public static Method Create (TypeDefinition parent, FullNamedExpression returnType, Modifiers mod,
MemberName name, ParametersCompiled parameters, Attributes attrs)
{
var m = new Method (parent, returnType, mod, name, parameters, attrs);
if ((mod & Modifiers.PARTIAL) != 0) {
const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN |
Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
if ((mod & invalid_partial_mod) != 0) {
m.Report.Error (750, m.Location,
"A partial method cannot define access modifier or any of abstract, extern, new, override, sealed, or virtual modifiers");
mod &= ~invalid_partial_mod;
}
if ((parent.ModFlags & Modifiers.PARTIAL) == 0) {
m.Report.Error (751, m.Location,
"A partial method must be declared within a partial class or partial struct");
}
}
if ((mod & Modifiers.STATIC) == 0 && parameters.HasExtensionMethodType) {
m.Report.Error (1105, m.Location, "`{0}': Extension methods must be declared static",
m.GetSignatureForError ());
}
return m;
}
示例3: CreateHoistedBaseCallProxy
//
// Creates a proxy base method call inside this container for hoisted base member calls
//
public MethodSpec CreateHoistedBaseCallProxy (ResolveContext rc, MethodSpec method)
{
Method proxy_method;
//
// One proxy per base method is enough
//
if (hoisted_base_call_proxies == null) {
hoisted_base_call_proxies = new Dictionary<MethodSpec, Method> ();
proxy_method = null;
} else {
hoisted_base_call_proxies.TryGetValue (method, out proxy_method);
}
if (proxy_method == null) {
string name = CompilerGeneratedContainer.MakeName (method.Name, null, "BaseCallProxy", hoisted_base_call_proxies.Count);
MemberName member_name;
TypeArguments targs = null;
TypeSpec return_type = method.ReturnType;
var local_param_types = method.Parameters.Types;
if (method.IsGeneric) {
//
// Copy all base generic method type parameters info
//
var hoisted_tparams = method.GenericDefinition.TypeParameters;
var tparams = new TypeParameters ();
targs = new TypeArguments ();
targs.Arguments = new TypeSpec[hoisted_tparams.Length];
for (int i = 0; i < hoisted_tparams.Length; ++i) {
var tp = hoisted_tparams[i];
var local_tp = new TypeParameter (tp, null, new MemberName (tp.Name, Location), null);
tparams.Add (local_tp);
targs.Add (new SimpleName (tp.Name, Location));
targs.Arguments[i] = local_tp.Type;
}
member_name = new MemberName (name, tparams, Location);
//
// Mutate any method type parameters from original
// to newly created hoisted version
//
var mutator = new TypeParameterMutator (hoisted_tparams, tparams);
return_type = mutator.Mutate (return_type);
local_param_types = mutator.Mutate (local_param_types);
} else {
member_name = new MemberName (name);
}
var base_parameters = new Parameter[method.Parameters.Count];
for (int i = 0; i < base_parameters.Length; ++i) {
var base_param = method.Parameters.FixedParameters[i];
base_parameters[i] = new Parameter (new TypeExpression (local_param_types [i], Location),
base_param.Name, base_param.ModFlags, null, Location);
base_parameters[i].Resolve (this, i);
}
var cloned_params = ParametersCompiled.CreateFullyResolved (base_parameters, method.Parameters.Types);
if (method.Parameters.HasArglist) {
cloned_params.FixedParameters[0] = new Parameter (null, "__arglist", Parameter.Modifier.NONE, null, Location);
cloned_params.Types[0] = Module.PredefinedTypes.RuntimeArgumentHandle.Resolve ();
}
// Compiler generated proxy
proxy_method = new Method (this, new TypeExpression (return_type, Location),
Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED | Modifiers.DEBUGGER_HIDDEN,
member_name, cloned_params, null);
var block = new ToplevelBlock (Compiler, proxy_method.ParameterInfo, Location) {
IsCompilerGenerated = true
};
var mg = MethodGroupExpr.CreatePredefined (method, method.DeclaringType, Location);
mg.InstanceExpression = new BaseThis (method.DeclaringType, Location);
if (targs != null)
mg.SetTypeArguments (rc, targs);
// Get all the method parameters and pass them as arguments
var real_base_call = new Invocation (mg, block.GetAllParametersArguments ());
Statement statement;
if (method.ReturnType.Kind == MemberKind.Void)
statement = new StatementExpression (real_base_call);
else
statement = new Return (real_base_call, Location);
block.AddStatement (statement);
proxy_method.Block = block;
members.Add (proxy_method);
proxy_method.Define ();
proxy_method.PrepareEmit ();
hoisted_base_call_proxies.Add (method, proxy_method);
//.........这里部分代码省略.........
示例4: Visit
public override void Visit (Method m)
{
MethodDeclaration newMethod = new MethodDeclaration ();
var location = LocationsBag.GetMemberLocation (m);
AddModifiers (newMethod, location);
newMethod.AddChild ((INode)m.TypeName.Accept (this), AbstractNode.Roles.ReturnType);
newMethod.AddChild (new Identifier (m.Name, Convert (m.Location)), AbstractNode.Roles.Identifier);
if (m.MemberName.TypeArguments != null) {
var typeArgLocation = LocationsBag.GetLocations (m.MemberName);
if (typeArgLocation != null)
newMethod.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), MemberReferenceExpression.Roles.LChevron);
// AddTypeArguments (newMethod, typeArgLocation, m.MemberName.TypeArguments);
if (typeArgLocation != null)
newMethod.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), MemberReferenceExpression.Roles.RChevron);
AddConstraints (newMethod, m.GenericMethod);
}
if (location != null)
newMethod.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
AddParameter (newMethod, m.ParameterInfo);
if (location != null)
newMethod.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
if (m.Block != null) {
INode bodyBlock = (INode)m.Block.Accept (this);
// if (m.Block is ToplevelBlock) {
// newMethod.AddChild (bodyBlock.FirstChild.NextSibling, MethodDeclaration.Roles.Body);
// } else {
newMethod.AddChild (bodyBlock, MethodDeclaration.Roles.Body);
// }
}
typeStack.Peek ().AddChild (newMethod, TypeDeclaration.Roles.Member);
}
示例5: SetPartialDefinition
public void SetPartialDefinition (Method methodDefinition)
{
caching_flags |= Flags.PartialDefinitionExists;
methodDefinition.partialMethodImplementation = this;
// Ensure we are always using method declaration parameters
for (int i = 0; i < methodDefinition.parameters.Count; ++i ) {
var md_p = methodDefinition.parameters [i];
var p = parameters [i];
p.Name = md_p.Name;
p.DefaultValue = md_p.DefaultValue;
if (md_p.OptAttributes != null) {
if (p.OptAttributes == null) {
p.OptAttributes = md_p.OptAttributes;
} else {
p.OptAttributes.Attrs.AddRange (md_p.OptAttributes.Attrs);
}
}
}
if (methodDefinition.attributes != null) {
if (attributes == null) {
attributes = methodDefinition.attributes;
} else {
attributes.Attrs.AddRange (methodDefinition.attributes.Attrs);
}
}
if (CurrentTypeParameters != null) {
for (int i = 0; i < CurrentTypeParameters.Count; ++i) {
var tp_other = methodDefinition.CurrentTypeParameters [i];
if (tp_other.OptAttributes == null)
continue;
var tp = CurrentTypeParameters [i];
if (tp.OptAttributes == null) {
tp.OptAttributes = tp_other.OptAttributes;
} else {
tp.OptAttributes.Attrs.AddRange (tp.OptAttributes.Attrs);
}
}
}
}
示例6: Define_Reset
void Define_Reset()
{
Method reset = new Method (
this, null, TypeManager.system_void_expr,
Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
new MemberName ("Reset", Location),
ParametersCompiled.EmptyReadOnlyParameters, null);
AddMethod (reset);
reset.Block = new ToplevelBlock (Compiler, Location);
TypeSpec ex_type = TypeManager.CoreLookupType (Compiler, "System", "NotSupportedException", MemberKind.Class, true);
if (ex_type == null)
return;
reset.Block.AddStatement (new Throw (new New (new TypeExpression (ex_type, Location), null, Location), Location));
}
示例7: Visit
public override void Visit (Method m)
{
DomMethod method = new DomMethod ();
method.Name = ConvertQuoted (m.MemberName.Name);
method.Documentation = RetrieveDocumentation (m.Location.Row);
method.Location = Convert (m.MemberName.Location);
method.Modifiers = ConvertModifiers (m.ModFlags);
if (m.Block != null) {
var location = LocationsBag.GetMemberLocation (m);
var region = ConvertRegion (location != null ? location[1] : m.Block.StartLocation, m.Block.EndLocation);
if (location != null)
region.Start = new DomLocation (region.Start.Line, region.Start.Column + 1);
method.BodyRegion = region;
}
method.ReturnType = ConvertReturnType (m.TypeName);
AddAttributes (method, m.OptAttributes, m);
AddParameter (method, m.ParameterInfo);
AddExplicitInterfaces (method, m);
method.Modifiers = ConvertModifiers (m.ModFlags);
if (method.IsStatic && method.Parameters.Count > 0 && method.Parameters[0].ParameterModifiers == ParameterModifiers.This)
method.MethodModifier |= MethodModifier.IsExtension;
if (m.GenericMethod != null)
AddTypeParameter (method, m.GenericMethod);
method.DeclaringType = typeStack.Peek ();
typeStack.Peek ().Add (method);
}
示例8: Visit
public virtual void Visit (Method m)
{
}
示例9: DefineAsyncMethods
void DefineAsyncMethods (CallingConventions cc)
{
//
// BeginInvoke
//
ParametersCompiled async_parameters;
if (Parameters.Count == 0) {
async_parameters = ParametersCompiled.EmptyReadOnlyParameters;
} else {
var compiled = new Parameter[Parameters.Count];
for (int i = 0; i < compiled.Length; ++i)
compiled[i] = new Parameter (new TypeExpression (Parameters.Types[i], Location),
Parameters.FixedParameters[i].Name,
Parameters.FixedParameters[i].ModFlags & (Parameter.Modifier.REF | Parameter.Modifier.OUT),
null, Location);
async_parameters = new ParametersCompiled (compiled);
}
async_parameters = ParametersCompiled.MergeGenerated (Compiler, async_parameters, false,
new Parameter[] {
new Parameter (new TypeExpression (TypeManager.asynccallback_type, Location), "callback", Parameter.Modifier.NONE, null, Location),
new Parameter (new TypeExpression (TypeManager.object_type, Location), "object", Parameter.Modifier.NONE, null, Location)
},
new [] {
TypeManager.asynccallback_type,
TypeManager.object_type
}
);
BeginInvokeBuilder = new Method (this, null,
new TypeExpression (TypeManager.iasyncresult_type, Location), MethodModifiers,
new MemberName ("BeginInvoke"), async_parameters, null);
BeginInvokeBuilder.Define ();
//
// EndInvoke is a bit more interesting, all the parameters labeled as
// out or ref have to be duplicated here.
//
//
// Define parameters, and count out/ref parameters
//
ParametersCompiled end_parameters;
int out_params = 0;
foreach (Parameter p in Parameters.FixedParameters) {
if ((p.ModFlags & Parameter.Modifier.ISBYREF) != 0)
++out_params;
}
if (out_params > 0) {
var end_param_types = new TypeSpec [out_params];
Parameter[] end_params = new Parameter[out_params];
int param = 0;
for (int i = 0; i < Parameters.FixedParameters.Length; ++i) {
Parameter p = Parameters [i];
if ((p.ModFlags & Parameter.Modifier.ISBYREF) == 0)
continue;
end_param_types[param] = Parameters.Types[i];
end_params[param] = p;
++param;
}
end_parameters = ParametersCompiled.CreateFullyResolved (end_params, end_param_types);
} else {
end_parameters = ParametersCompiled.EmptyReadOnlyParameters;
}
end_parameters = ParametersCompiled.MergeGenerated (Compiler, end_parameters, false,
new Parameter (
new TypeExpression (TypeManager.iasyncresult_type, Location),
"result", Parameter.Modifier.NONE, null, Location),
TypeManager.iasyncresult_type);
//
// Create method, define parameters, register parameters with type system
//
EndInvokeBuilder = new Method (this, null, ReturnType, MethodModifiers, new MemberName ("EndInvoke"), end_parameters, null);
EndInvokeBuilder.Define ();
}
示例10: GenerateNumberMatcher
Method GenerateNumberMatcher ()
{
var loc = Location;
var parameters = ParametersCompiled.CreateFullyResolved (
new [] {
new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, loc), "obj", 0, null, loc),
new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, loc), "value", 0, null, loc),
new Parameter (new TypeExpression (Compiler.BuiltinTypes.Bool, loc), "enumType", 0, null, loc),
},
new [] {
Compiler.BuiltinTypes.Object,
Compiler.BuiltinTypes.Object,
Compiler.BuiltinTypes.Bool
});
var m = new Method (this, new TypeExpression (Compiler.BuiltinTypes.Bool, loc),
Modifiers.PUBLIC | Modifiers.STATIC | Modifiers.DEBUGGER_HIDDEN, new MemberName ("NumberMatcher", loc),
parameters, null);
parameters [0].Resolve (m, 0);
parameters [1].Resolve (m, 1);
parameters [2].Resolve (m, 2);
ToplevelBlock top_block = new ToplevelBlock (Compiler, parameters, loc);
m.Block = top_block;
//
// if (enumType)
// return Equals (obj, value);
//
var equals_args = new Arguments (2);
equals_args.Add (new Argument (top_block.GetParameterReference (0, loc)));
equals_args.Add (new Argument (top_block.GetParameterReference (1, loc)));
var if_type = new If (
top_block.GetParameterReference (2, loc),
new Return (new Invocation (new SimpleName ("Equals", loc), equals_args), loc),
loc);
top_block.AddStatement (if_type);
//
// if (obj is Enum || obj == null)
// return false;
//
var if_enum = new If (
new Binary (Binary.Operator.LogicalOr,
new Is (top_block.GetParameterReference (0, loc), new TypeExpression (Compiler.BuiltinTypes.Enum, loc), loc),
new Binary (Binary.Operator.Equality, top_block.GetParameterReference (0, loc), new NullLiteral (loc))),
new Return (new BoolLiteral (Compiler.BuiltinTypes, false, loc), loc),
loc);
top_block.AddStatement (if_enum);
var system_convert = new MemberAccess (new QualifiedAliasMember ("global", "System", loc), "Convert", loc);
var expl_block = new ExplicitBlock (top_block, loc, loc);
//
// var converted = System.Convert.ChangeType (obj, System.Convert.GetTypeCode (value));
//
var lv_converted = LocalVariable.CreateCompilerGenerated (Compiler.BuiltinTypes.Object, top_block, loc);
var arguments_gettypecode = new Arguments (1);
arguments_gettypecode.Add (new Argument (top_block.GetParameterReference (1, loc)));
var gettypecode = new Invocation (new MemberAccess (system_convert, "GetTypeCode", loc), arguments_gettypecode);
var arguments_changetype = new Arguments (1);
arguments_changetype.Add (new Argument (top_block.GetParameterReference (0, loc)));
arguments_changetype.Add (new Argument (gettypecode));
var changetype = new Invocation (new MemberAccess (system_convert, "ChangeType", loc), arguments_changetype);
expl_block.AddStatement (new StatementExpression (new SimpleAssign (new LocalVariableReference (lv_converted, loc), changetype, loc)));
//
// return converted.Equals (value)
//
var equals_arguments = new Arguments (1);
equals_arguments.Add (new Argument (top_block.GetParameterReference (1, loc)));
var equals_invocation = new Invocation (new MemberAccess (new LocalVariableReference (lv_converted, loc), "Equals"), equals_arguments);
expl_block.AddStatement (new Return (equals_invocation, loc));
var catch_block = new ExplicitBlock (top_block, loc, loc);
catch_block.AddStatement (new Return (new BoolLiteral (Compiler.BuiltinTypes, false, loc), loc));
top_block.AddStatement (new TryCatch (expl_block, new List<Catch> () {
new Catch (catch_block, loc)
}, loc, false));
m.Define ();
m.PrepareEmit ();
AddMember (m);
return m;
}
示例11: case_915
void case_915()
#line 5953 "cs-parser.jay"
{
Evaluator.LoadAliases (current_namespace);
push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++),
Modifiers.PUBLIC, null), null);
var baseclass_list = new List<FullNamedExpression> ();
baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location));
current_container.AddBasesForPart (current_class, baseclass_list);
/* (ref object retval)*/
Parameter [] mpar = new Parameter [1];
mpar [0] = new Parameter (new TypeExpression (TypeManager.object_type, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null);
ParametersCompiled pars = new ParametersCompiled (mpar);
current_local_parameters = pars;
Method method = new Method (
current_class,
null, /* generic*/
new TypeExpression (TypeManager.void_type, Location.Null),
Modifiers.PUBLIC | Modifiers.STATIC,
new MemberName ("Host"),
pars,
null /* attributes */);
oob_stack.Push (method);
++lexer.parsing_block;
start_block (lexer.Location);
}
示例12: case_170
void case_170()
#line 1383 "cs-parser.jay"
{
MemberName name = (MemberName) yyVals[-3+yyTop];
Report.Error (1585, name.Location,
"Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) yyVals[-4+yyTop]));
Method method = new Method (current_class, null, (FullNamedExpression) yyVals[-5+yyTop],
0, name, (ParametersCompiled) yyVals[-1+yyTop], (Attributes) yyVals[-7+yyTop]);
current_local_parameters = (ParametersCompiled) yyVals[-1+yyTop];
if (RootContext.Documentation != null)
method.DocComment = Lexer.consume_doc_comment ();
yyVal = method;
}
示例13: case_169
void case_169()
#line 1328 "cs-parser.jay"
{
lexer.ConstraintsParsing = false;
valid_param_mod = 0;
MemberName name = (MemberName) yyVals[-6+yyTop];
current_local_parameters = (ParametersCompiled) yyVals[-3+yyTop];
if (yyVals[-1+yyTop] != null && name.TypeArguments == null)
Report.Error (80, lexer.Location,
"Constraints are not allowed on non-generic declarations");
Method method;
GenericMethod generic = null;
if (name.TypeArguments != null) {
generic = new GenericMethod (current_namespace, current_class, name,
new TypeExpression (TypeManager.void_type, GetLocation (yyVals[-7+yyTop])),
current_local_parameters);
generic.SetParameterInfo ((List<Constraints>) yyVals[0+yyTop]);
}
var modifiers = (Modifiers) yyVals[-9+yyTop];
const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN |
Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL;
if ((modifiers & invalid_partial_mod) != 0) {
Report.Error (750, name.Location, "A partial method cannot define access modifier or " +
"any of abstract, extern, new, override, sealed, or virtual modifiers");
modifiers &= ~invalid_partial_mod;
}
if ((current_class.ModFlags & Modifiers.PARTIAL) == 0) {
Report.Error (751, name.Location, "A partial method must be declared within a " +
"partial class or partial struct");
}
modifiers |= Modifiers.PARTIAL | Modifiers.PRIVATE;
method = new Method (current_class, generic, new TypeExpression (TypeManager.void_type, GetLocation (yyVals[-7+yyTop])),
modifiers, name, current_local_parameters, (Attributes) yyVals[-10+yyTop]);
if (RootContext.Documentation != null)
method.DocComment = Lexer.consume_doc_comment ();
/* TODO: lbag, push void*/
StoreModifierLocation (Modifiers.PARTIAL, GetLocation (yyVals[-8+yyTop]));
lbag.AddMember (method, GetModifierLocations (), GetLocation (yyVals[-5+yyTop]), GetLocation (yyVals[-2+yyTop]));
yyVal = method;
}
示例14: DefineAsyncMethods
void DefineAsyncMethods (TypeExpression returnType)
{
var iasync_result = Module.PredefinedTypes.IAsyncResult;
var async_callback = Module.PredefinedTypes.AsyncCallback;
//
// It's ok when async types don't exist, the delegate will have Invoke method only
//
if (!iasync_result.Define () || !async_callback.Define ())
return;
//
// BeginInvoke
//
ParametersCompiled async_parameters;
if (Parameters.Count == 0) {
async_parameters = ParametersCompiled.EmptyReadOnlyParameters;
} else {
var compiled = new Parameter[Parameters.Count];
for (int i = 0; i < compiled.Length; ++i) {
var p = parameters[i];
compiled[i] = new Parameter (new TypeExpression (parameters.Types[i], Location),
p.Name,
p.ModFlags & Parameter.Modifier.RefOutMask,
p.OptAttributes == null ? null : p.OptAttributes.Clone (), Location);
}
async_parameters = new ParametersCompiled (compiled);
}
async_parameters = ParametersCompiled.MergeGenerated (Compiler, async_parameters, false,
new Parameter[] {
new Parameter (new TypeExpression (async_callback.TypeSpec, Location), "callback", Parameter.Modifier.NONE, null, Location),
new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, Location), "object", Parameter.Modifier.NONE, null, Location)
},
new [] {
async_callback.TypeSpec,
Compiler.BuiltinTypes.Object
}
);
BeginInvokeBuilder = new Method (this,
new TypeExpression (iasync_result.TypeSpec, Location), MethodModifiers,
new MemberName ("BeginInvoke"), async_parameters, null);
BeginInvokeBuilder.Define ();
//
// EndInvoke is a bit more interesting, all the parameters labeled as
// out or ref have to be duplicated here.
//
//
// Define parameters, and count out/ref parameters
//
ParametersCompiled end_parameters;
int out_params = 0;
foreach (Parameter p in Parameters.FixedParameters) {
if ((p.ModFlags & Parameter.Modifier.RefOutMask) != 0)
++out_params;
}
if (out_params > 0) {
Parameter[] end_params = new Parameter[out_params];
int param = 0;
for (int i = 0; i < Parameters.FixedParameters.Length; ++i) {
Parameter p = parameters [i];
if ((p.ModFlags & Parameter.Modifier.RefOutMask) == 0)
continue;
end_params [param++] = new Parameter (new TypeExpression (p.Type, Location),
p.Name,
p.ModFlags & Parameter.Modifier.RefOutMask,
p.OptAttributes == null ? null : p.OptAttributes.Clone (), Location);
}
end_parameters = new ParametersCompiled (end_params);
} else {
end_parameters = ParametersCompiled.EmptyReadOnlyParameters;
}
end_parameters = ParametersCompiled.MergeGenerated (Compiler, end_parameters, false,
new Parameter (
new TypeExpression (iasync_result.TypeSpec, Location),
"result", Parameter.Modifier.NONE, null, Location),
iasync_result.TypeSpec);
//
// Create method, define parameters, register parameters with type system
//
EndInvokeBuilder = new Method (this, returnType, MethodModifiers, new MemberName ("EndInvoke"), end_parameters, null);
EndInvokeBuilder.Define ();
}
示例15: DoDefineMembers
protected override bool DoDefineMembers ()
{
var ctor_parameters = ParametersCompiled.CreateFullyResolved (
new [] {
new Parameter (new TypeExpression (TypeManager.object_type, Location), "object", Parameter.Modifier.NONE, null, Location),
new Parameter (new TypeExpression (TypeManager.intptr_type, Location), "method", Parameter.Modifier.NONE, null, Location)
},
new [] {
TypeManager.object_type,
TypeManager.intptr_type
}
);
Constructor = new Constructor (this, System.Reflection.ConstructorInfo.ConstructorName,
Modifiers.PUBLIC, null, ctor_parameters, null, Location);
Constructor.Define ();
//
// Here the various methods like Invoke, BeginInvoke etc are defined
//
// First, call the `out of band' special method for
// defining recursively any types we need:
//
var p = Parameters;
if (!p.Resolve (this))
return false;
//
// Invoke method
//
// Check accessibility
foreach (var partype in p.Types) {
if (!IsAccessibleAs (partype)) {
Report.SymbolRelatedToPreviousError (partype);
Report.Error (59, Location,
"Inconsistent accessibility: parameter type `{0}' is less accessible than delegate `{1}'",
TypeManager.CSharpName (partype), GetSignatureForError ());
}
}
ReturnType = ReturnType.ResolveAsTypeTerminal (this, false);
if (ReturnType == null)
return false;
var ret_type = ReturnType.Type;
//
// We don't have to check any others because they are all
// guaranteed to be accessible - they are standard types.
//
if (!IsAccessibleAs (ret_type)) {
Report.SymbolRelatedToPreviousError (ret_type);
Report.Error (58, Location,
"Inconsistent accessibility: return type `" +
TypeManager.CSharpName (ret_type) + "' is less " +
"accessible than delegate `" + GetSignatureForError () + "'");
return false;
}
CheckProtectedModifier ();
if (RootContext.StdLib && TypeManager.IsSpecialType (ret_type)) {
Method.Error1599 (Location, ret_type, Report);
return false;
}
TypeManager.CheckTypeVariance (ret_type, Variance.Covariant, this);
InvokeBuilder = new Method (this, null, ReturnType, MethodModifiers, new MemberName (InvokeMethodName), p, null);
InvokeBuilder.Define ();
//
// Don't emit async method for compiler generated delegates (e.g. dynamic site containers)
//
if (TypeManager.iasyncresult_type != null && TypeManager.asynccallback_type != null && !IsCompilerGenerated) {
DefineAsyncMethods (Parameters.CallingConvention);
}
return true;
}