本文整理汇总了C#中Mono.CSharp.Constructor类的典型用法代码示例。如果您正苦于以下问题:C# Constructor类的具体用法?C# Constructor怎么用?C# Constructor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Constructor类属于Mono.CSharp命名空间,在下文中一共展示了Constructor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
public override void Visit (Constructor c)
{
ConstructorDeclaration newConstructor = new ConstructorDeclaration ();
var location = LocationsBag.GetMemberLocation (c);
AddModifiers (newConstructor, location);
newConstructor.AddChild (new Identifier (c.MemberName.Name, Convert (c.MemberName.Location)), AbstractNode.Roles.Identifier);
if (location != null) {
newConstructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
newConstructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
}
if (c.Block != null)
newConstructor.AddChild ((INode)c.Block.Accept (this), ConstructorDeclaration.Roles.Body);
typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.Roles.Member);
}
示例2: DefineDefaultConstructor
/// <summary>
/// Defines the default constructors
/// </summary>
protected virtual Constructor DefineDefaultConstructor (bool is_static)
{
// The default instance constructor is public
// If the class is abstract, the default constructor is protected
// The default static constructor is private
Modifiers mods;
ParametersCompiled parameters = null;
if (is_static) {
mods = Modifiers.STATIC | Modifiers.PRIVATE;
parameters = ParametersCompiled.EmptyReadOnlyParameters;
} else {
mods = ((ModFlags & Modifiers.ABSTRACT) != 0) ? Modifiers.PROTECTED : Modifiers.PUBLIC;
parameters = PrimaryConstructorParameters ?? ParametersCompiled.EmptyReadOnlyParameters;
}
var c = new Constructor (this, MemberName.Name, mods, null, parameters, Location);
if (Kind == MemberKind.Class)
c.Initializer = new GeneratedBaseInitializer (Location, PrimaryConstructorBaseArguments);
if (PrimaryConstructorParameters != null && !is_static) {
c.IsPrimaryConstructor = true;
c.caching_flags |= Flags.MethodOverloadsExist;
}
AddConstructor (c, true);
if (PrimaryConstructorBlock == null) {
c.Block = new ToplevelBlock (Compiler, parameters, Location) {
IsCompilerGenerated = true
};
} else {
c.Block = PrimaryConstructorBlock;
}
return c;
}
示例3: Visit
public override void Visit (Constructor c)
{
DomMethod method = new DomMethod ();
method.Name = ".ctor";
method.Documentation = RetrieveDocumentation (c.Location.Row);
method.Location = Convert (c.MemberName.Location);
method.Modifiers = ConvertModifiers (c.ModFlags);
if (c.Block != null) {
var location = LocationsBag.GetMemberLocation (c);
var region = ConvertRegion (location != null ? location[1] : c.Block.StartLocation, c.Block.EndLocation);
if (location != null)
region.Start = new DomLocation (region.Start.Line, region.Start.Column + 1);
method.BodyRegion = region;
}
method.Modifiers = ConvertModifiers (c.ModFlags) | MonoDevelop.Projects.Dom.Modifiers.SpecialName;
method.MethodModifier |= MethodModifier.IsConstructor;
AddAttributes (method, c.OptAttributes, c);
AddParameter (method, c.ParameterInfo);
AddExplicitInterfaces (method, c);
method.DeclaringType = typeStack.Peek ();
typeStack.Peek ().Add (method);
}
示例4: Visit
public override void Visit(Constructor c)
{
var newConstructor = new ConstructorDeclaration();
AddAttributeSection(newConstructor, c);
var location = LocationsBag.GetMemberLocation(c);
AddModifiers(newConstructor, location);
newConstructor.AddChild(Identifier.Create(c.MemberName.Name, Convert(c.MemberName.Location)), Roles.Identifier);
if (location != null && location.Count > 0)
newConstructor.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LPar), Roles.LPar);
AddParameter(newConstructor, c.ParameterInfo);
if (location != null && location.Count > 1)
newConstructor.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.RPar), Roles.RPar);
if (c.Initializer != null) {
var initializer = new ConstructorInitializer();
initializer.ConstructorInitializerType = c.Initializer is ConstructorBaseInitializer ? ConstructorInitializerType.Base : ConstructorInitializerType.This;
var initializerLocation = LocationsBag.GetLocations(c.Initializer);
if (initializerLocation != null)
newConstructor.AddChild(new CSharpTokenNode(Convert(initializerLocation [0]), Roles.Colon), Roles.Colon);
if (initializerLocation != null && initializerLocation.Count > 1) {
// this and base has the same length
var r = initializer.ConstructorInitializerType == ConstructorInitializerType.This ? ConstructorInitializer.ThisKeywordRole : ConstructorInitializer.BaseKeywordRole;
initializer.AddChild(new CSharpTokenNode(Convert(c.Initializer.Location), r), r);
initializer.AddChild(new CSharpTokenNode(Convert(initializerLocation [1]), Roles.LPar), Roles.LPar);
AddArguments(initializer, c.Initializer.Arguments);
initializer.AddChild(new CSharpTokenNode(Convert(initializerLocation [2]), Roles.RPar), Roles.RPar);
newConstructor.AddChild(initializer, ConstructorDeclaration.InitializerRole);
}
}
if (c.Block != null)
newConstructor.AddChild((BlockStatement)c.Block.Accept(this), Roles.Body);
typeStack.Peek().AddChild(newConstructor, Roles.TypeMemberRole);
}
示例5: AddConstructor
public void AddConstructor (Constructor c, bool isDefault)
{
bool is_static = (c.ModFlags & Modifiers.STATIC) != 0;
if (!isDefault)
AddNameToContainer (c, is_static ? Constructor.TypeConstructorName : Constructor.ConstructorName);
if (is_static && c.ParameterInfo.IsEmpty) {
PartialContainer.has_static_constructor = true;
} else {
PartialContainer.HasInstanceConstructor = true;
}
members.Add (c);
}
示例6: Visit
public override void Visit (Constructor c)
{
ConstructorDeclaration newConstructor = new ConstructorDeclaration ();
var location = LocationsBag.GetMemberLocation (c);
AddModifiers (newConstructor, location);
newConstructor.AddChild (new Identifier (c.MemberName.Name, Convert (c.MemberName.Location)), AstNode.Roles.Identifier);
if (location != null)
newConstructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
AddParameter (newConstructor, c.ParameterInfo);
if (location != null)
newConstructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
if (c.Initializer != null)
{
newConstructor.Initializer = new ConstructorInitializer();
if (c.Initializer is ConstructorBaseInitializer)
newConstructor.Initializer.ConstructorInitializerType = ConstructorInitializerType.Base;
if (c.Initializer is ConstructorThisInitializer)
newConstructor.Initializer.ConstructorInitializerType = ConstructorInitializerType.This;
AddArguments(newConstructor.Initializer, location, c.Initializer.Arguments);
}
if (c.Block != null)
newConstructor.AddChild ((BlockStatement)c.Block.Accept (this), ConstructorDeclaration.Roles.Body);
typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.MemberRole);
}
示例7: case_274
void case_274()
#line 2276 "cs-parser.jay"
{
valid_param_mod = 0;
current_local_parameters = (ParametersCompiled) yyVals[-1+yyTop];
var lt = (LocatedToken) yyVals[-4+yyTop];
var mods = (Modifiers) yyVals[-5+yyTop];
var c = new Constructor (current_type, lt.Value, mods, (Attributes) yyVals[-6+yyTop], current_local_parameters, lt.Location);
if (lt.Value != current_container.MemberName.Name) {
report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
} else if ((mods & Modifiers.STATIC) != 0) {
if ((mods & Modifiers.AccessibilityMask) != 0){
report.Error (515, c.Location,
"`{0}': static constructor cannot have an access modifier",
c.GetSignatureForError ());
}
}
current_type.AddConstructor (c);
lbag.AddMember (c, GetModifierLocations (), GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop]));
yyVal = c;
/**/
/* start block here, so possible anonymous methods inside*/
/* constructor initializer can get correct parent block*/
/**/
start_block (lexer.Location);
}
void case_275()
#line 2305 "cs-parser.jay"
{
if (yyVals[0+yyTop] != null) {
var c = (Constructor) yyVals[-1+yyTop];
c.Initializer = (ConstructorInitializer) yyVals[0+yyTop];
if (c.IsStatic) {
report.Error (514, c.Location,
"`{0}': static constructor cannot have an explicit `this' or `base' constructor call",
c.GetSignatureForError ());
}
}
yyVal = yyVals[-1+yyTop];
}
void case_281()
#line 2337 "cs-parser.jay"
{
--lexer.parsing_block;
yyVal = new ConstructorBaseInitializer ((Arguments) yyVals[-1+yyTop], GetLocation (yyVals[-4+yyTop]));
lbag.AddLocation (yyVal, GetLocation (yyVals[-5+yyTop]), GetLocation (yyVals[-3+yyTop]), GetLocation (yyVals[0+yyTop]));
}
void case_283()
#line 2347 "cs-parser.jay"
{
--lexer.parsing_block;
yyVal = new ConstructorThisInitializer ((Arguments) yyVals[-1+yyTop], GetLocation (yyVals[-4+yyTop]));
lbag.AddLocation (yyVal, GetLocation (yyVals[-5+yyTop]), GetLocation (yyVals[-3+yyTop]), GetLocation (yyVals[0+yyTop]));
}
void case_284()
#line 2353 "cs-parser.jay"
{
Error_SyntaxError (yyToken);
yyVal = new ConstructorThisInitializer (null, GetLocation (yyVals[0+yyTop]));
lbag.AddLocation (yyVal, GetLocation (yyVals[-1+yyTop]));
}
void case_285()
#line 2359 "cs-parser.jay"
{
Error_SyntaxError (yyToken);
yyVal = null;
}
void case_286()
#line 2367 "cs-parser.jay"
{
if (doc_support) {
tmpComment = Lexer.consume_doc_comment ();
Lexer.doc_state = XmlCommentState.NotAllowed;
}
current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters;
}
void case_287()
#line 2376 "cs-parser.jay"
{
var lt = (LocatedToken) yyVals[-3+yyTop];
if (lt.Value != current_container.MemberName.Name){
report.Error (574, lt.Location, "Name of destructor must match name of class");
} else if (current_container.Kind != MemberKind.Class){
report.Error (575, lt.Location, "Only class types can contain destructor");
}
//.........这里部分代码省略.........
示例8: DefineDefaultConstructor
/// <summary>
/// Defines the default constructors
/// </summary>
protected virtual Constructor DefineDefaultConstructor (bool is_static)
{
// The default instance constructor is public
// If the class is abstract, the default constructor is protected
// The default static constructor is private
Modifiers mods;
if (is_static) {
mods = Modifiers.STATIC | Modifiers.PRIVATE;
} else {
mods = ((ModFlags & Modifiers.ABSTRACT) != 0) ? Modifiers.PROTECTED : Modifiers.PUBLIC;
}
var c = new Constructor (this, MemberName.Name, mods, null, ParametersCompiled.EmptyReadOnlyParameters, Location);
c.Initializer = new GeneratedBaseInitializer (Location);
AddConstructor (c, true);
c.Block = new ToplevelBlock (Compiler, ParametersCompiled.EmptyReadOnlyParameters, Location) {
IsCompilerGenerated = true
};
return c;
}
示例9: Create
public static AnonymousTypeClass Create (CompilerContext ctx, TypeContainer parent, IList<AnonymousTypeParameter> parameters, Location loc)
{
string name = ClassNamePrefix + types_counter++;
SimpleName [] t_args = new SimpleName [parameters.Count];
TypeParameterName [] t_params = new TypeParameterName [parameters.Count];
Parameter [] ctor_params = new Parameter [parameters.Count];
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = (AnonymousTypeParameter) parameters [i];
t_args [i] = new SimpleName ("<" + p.Name + ">__T", p.Location);
t_params [i] = new TypeParameterName (t_args [i].Name, null, p.Location);
ctor_params [i] = new Parameter (t_args [i], p.Name, 0, null, p.Location);
}
//
// Create generic anonymous type host with generic arguments
// named upon properties names
//
AnonymousTypeClass a_type = new AnonymousTypeClass (parent.NamespaceEntry.SlaveDeclSpace,
new MemberName (name, new TypeArguments (t_params), loc), parameters, loc);
if (parameters.Count > 0)
a_type.SetParameterInfo (null);
Constructor c = new Constructor (a_type, name, Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
null, new AnonymousParameters (ctx, ctor_params), null, loc);
c.Block = new ToplevelBlock (ctx, c.ParameterInfo, loc);
//
// Create fields and contructor body with field initialization
//
bool error = false;
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = (AnonymousTypeParameter) parameters [i];
Field f = new Field (a_type, t_args [i], Modifiers.PRIVATE | Modifiers.READONLY,
new MemberName ("<" + p.Name + ">", p.Location), null);
if (!a_type.AddField (f)) {
error = true;
continue;
}
c.Block.AddStatement (new StatementExpression (
new SimpleAssign (new MemberAccess (new This (p.Location), f.Name),
c.Block.GetParameterReference (p.Name, p.Location))));
ToplevelBlock get_block = new ToplevelBlock (ctx, p.Location);
get_block.AddStatement (new Return (
new MemberAccess (new This (p.Location), f.Name), p.Location));
Property prop = new Property (a_type, t_args [i], Modifiers.PUBLIC,
new MemberName (p.Name, p.Location), null);
prop.Get = new Property.GetMethod (prop, 0, null, p.Location);
prop.Get.Block = get_block;
a_type.AddProperty (prop);
}
if (error)
return null;
a_type.AddConstructor (c);
return a_type;
}
示例10: 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;
}
示例11: Visit
public virtual void Visit (Constructor c)
{
}
示例12: DefineDefaultConstructor
//
// Defines the default constructors
//
void DefineDefaultConstructor (bool is_static)
{
Constructor c;
int mods = 0;
c = new Constructor (Basename, Parameters.EmptyReadOnlyParameters,
new ConstructorBaseInitializer (
null, Parameters.EmptyReadOnlyParameters,
Location.Null),
Location.Null);
if (is_static)
mods = Modifiers.STATIC;
c.ModFlags = mods;
AddConstructor (c);
c.Block = new Block (null);
}
示例13: AddConstructor
public AdditionResult AddConstructor (Constructor c)
{
if (c.Name != Basename)
return AdditionResult.NotAConstructor;
bool is_static = (c.ModFlags & Modifiers.STATIC) != 0;
if (is_static){
have_static_constructor = true;
if (default_static_constructor != null){
Console.WriteLine ("I have a static constructor already");
Console.WriteLine (" " + default_static_constructor);
return AdditionResult.MethodExists;
}
default_static_constructor = c;
} else {
if (c.IsDefault ()){
if (default_constructor != null)
return AdditionResult.MethodExists;
default_constructor = c;
}
if (instance_constructors == null)
instance_constructors = new ArrayList ();
instance_constructors.Add (c);
}
return AdditionResult.Success;
}
示例14: Visit
public override void Visit (Constructor c)
{
ConstructorDeclaration newConstructor = new ConstructorDeclaration ();
AddAttributeSection (newConstructor, c);
var location = LocationsBag.GetMemberLocation (c);
AddModifiers (newConstructor, location);
newConstructor.AddChild (Identifier.Create (c.MemberName.Name, Convert (c.MemberName.Location)), AstNode.Roles.Identifier);
if (location != null)
newConstructor.AddChild (new CSharpTokenNode (Convert (location[0]), 1), MethodDeclaration.Roles.LPar);
AddParameter (newConstructor, c.ParameterInfo);
if (location != null)
newConstructor.AddChild (new CSharpTokenNode (Convert (location[1]), 1), MethodDeclaration.Roles.RPar);
if (c.Initializer != null) {
var initializer = new ConstructorInitializer ();
initializer.ConstructorInitializerType = c.Initializer is ConstructorBaseInitializer ? ConstructorInitializerType.Base : ConstructorInitializerType.This;
var initializerLocation = LocationsBag.GetLocations (c.Initializer);
if (initializerLocation != null)
newConstructor.AddChild (new CSharpTokenNode (Convert (initializerLocation[0]), 1), ConstructorDeclaration.Roles.Colon);
// this and base has the same length
initializer.AddChild (new CSharpTokenNode (Convert (c.Initializer.Location), "this".Length), ConstructorDeclaration.Roles.Keyword);
if (initializerLocation != null)
initializer.AddChild (new CSharpTokenNode (Convert (initializerLocation[1]), 1), ConstructorDeclaration.Roles.LPar);
AddArguments (initializer, LocationsBag.GetLocations (c.Initializer.Arguments), c.Initializer.Arguments);
if (initializerLocation != null)
initializer.AddChild (new CSharpTokenNode (Convert (initializerLocation[2]), 1), ConstructorDeclaration.Roles.RPar);
newConstructor.AddChild (initializer, ConstructorDeclaration.InitializerRole);
}
if (c.Block != null)
newConstructor.AddChild ((BlockStatement)c.Block.Accept (this), ConstructorDeclaration.Roles.Body);
typeStack.Peek ().AddChild (newConstructor, TypeDeclaration.MemberRole);
}
示例15: AddConstructor
public void AddConstructor (Constructor c)
{
bool is_static = (c.ModFlags & Modifiers.STATIC) != 0;
if (!AddToContainer (c, is_static ? Constructor.ConstructorName : Constructor.TypeConstructorName))
return;
if (is_static && c.ParameterInfo.IsEmpty){
if (default_static_constructor != null) {
Report.SymbolRelatedToPreviousError (default_static_constructor);
Report.Error (111, c.Location,
"A member `{0}' is already defined. Rename this member or use different parameter types",
c.GetSignatureForError ());
return;
}
default_static_constructor = c;
} else {
if (c.ParameterInfo.IsEmpty)
default_constructor = c;
if (instance_constructors == null)
instance_constructors = new List<Constructor> ();
instance_constructors.Add (c);
}
}