本文整理汇总了C#中Mono.CSharp.Class类的典型用法代码示例。如果您正苦于以下问题:C# Class类的具体用法?C# Class怎么用?C# Class使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Class类属于Mono.CSharp命名空间,在下文中一共展示了Class类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: case_1008
void case_1008()
#line 6889 "cs-parser.jay"
{
--lexer.parsing_block;
var method = (InteractiveMethod) oob_stack.Pop ();
method.Block = (ToplevelBlock) end_block(lexer.Location);
if (interactive_async == true) {
method.ChangeToAsync ();
}
InteractiveResult = (Class) pop_current_class ();
current_local_parameters = null;
}
示例2: CompileBlock
static CompiledMethod CompileBlock (Class host, Undo undo, Report Report)
{
AssemblyDefinitionDynamic assembly;
AssemblyBuilderAccess access;
if (Environment.GetEnvironmentVariable ("SAVE") != null) {
access = AssemblyBuilderAccess.RunAndSave;
assembly = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, current_debug_name, current_debug_name);
assembly.Importer = loader.Importer;
} else {
#if NET_4_0
access = AssemblyBuilderAccess.RunAndCollect;
#else
access = AssemblyBuilderAccess.Run;
#endif
assembly = new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, current_debug_name);
}
assembly.Create (AppDomain.CurrentDomain, access);
if (host != null) {
host.CreateType ();
host.Define ();
}
RootContext.ToplevelTypes.CreateType ();
RootContext.ToplevelTypes.Define ();
if (Report.Errors != 0){
undo.ExecuteUndo ();
return null;
}
TypeBuilder tb = null;
MethodBuilder mb = null;
if (host != null){
tb = host.TypeBuilder;
mb = null;
foreach (MemberCore member in host.Methods){
if (member.Name != "Host")
continue;
MethodOrOperator method = (MethodOrOperator) member;
mb = method.MethodBuilder;
break;
}
if (mb == null)
throw new Exception ("Internal error: did not find the method builder for the generated method");
host.EmitType ();
}
RootContext.ToplevelTypes.Emit ();
if (Report.Errors != 0){
undo.ExecuteUndo ();
return null;
}
RootContext.ToplevelTypes.CloseType ();
if (host != null)
host.CloseType ();
if (access == AssemblyBuilderAccess.RunAndSave)
assembly.Save ();
if (host == null)
return null;
//
// Unlike Mono, .NET requires that the MethodInfo is fetched, it cant
// work from MethodBuilders. Retarded, I know.
//
var tt = assembly.Builder.GetType (tb.Name);
MethodInfo mi = tt.GetMethod (mb.Name);
// Pull the FieldInfos from the type, and keep track of them
foreach (Field field in queued_fields){
FieldInfo fi = tt.GetField (field.Name);
Tuple<FieldSpec, FieldInfo> old;
// If a previous value was set, nullify it, so that we do
// not leak memory
if (fields.TryGetValue (field.Name, out old)) {
if (old.Item1.MemberType.IsStruct) {
//
// TODO: Clear fields for structs
//
} else {
try {
old.Item2.SetValue (null, null);
} catch {
}
}
fields [field.Name] = Tuple.Create (field.Spec, fi);
} else {
fields.Add (field.Name, Tuple.Create (field.Spec, fi));
//.........这里部分代码省略.........
示例3: yyparse
//.........这里部分代码省略.........
{
current_role = null;
}
break;
case 121:
#line 1045 "D:\GitHub\M\Marvin\mcs\cs-parser.jay"
{ yyVal = null; }
break;
case 122:
#line 1047 "D:\GitHub\M\Marvin\mcs\cs-parser.jay"
{
TypeParameter tparam = null;
var simple = current_role.TypeExpression as SimpleName;
if((simple != null && simple.Name != "dynamic") || (simple.Type != null && simple.Type.BuiltinType != BuiltinTypeSpec.Type.Dynamic)){
if(current_class.IsGeneric){
for(int i = 0; tparam == null && i<current_class.TypeParameters.Length;i++){
if(simple.Name == current_class.TypeParameters[i].Name){
tparam = current_class.TypeParameters[i];
}
}
}
if(tparam == null) {
report.Error (10009, GetLocation (yyVals[0+yyTop]), "Contracts can only be used for none typed roles");
}
}
var contractName = GetCurrentRoleContractName();
MemberName name = MakeName (new MemberName(contractName));
var inter = new Interface (current_namespace, current_class, name, Modifiers.PUBLIC, null);
if(tparam != null) {
tparam.Type.RolePlayerContract = inter.Type;
var ns = current_namespace.NS;
var className = new MemberName (ns.MemberName, new MemberName("><_extensionContainerFor" + GetCurrentRoleContractName(),GetLocation (yyVals[0+yyTop])));
current_extensionContainer = new Class (current_namespace,
current_class.Parent,
className,
Modifiers.PUBLIC | Modifiers.STATIC,
null);
}
RoleContracts.Add(contractName,inter);
push_current_class (inter, null);
lbag.AddMember (current_class, mod_locations, GetLocation (yyVals[0+yyTop]));
}
break;
case 123:
#line 1081 "D:\GitHub\M\Marvin\mcs\cs-parser.jay"
{
--lexer.parsing_declaration;
if (doc_support)
Lexer.doc_state = XmlCommentState.Allowed;
lbag.AppendToMember (current_class, GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop]));
if(current_extensionContainer != null) {
var cls = current_class;
var container = current_container;
current_container = current_class.Module;
push_current_class((Class)current_extensionContainer, null);
lbag.AddMember (current_extensionContainer, mod_locations, GetLocation (yyVals[-4+yyTop]));
lbag.AppendToMember (current_extensionContainer, GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop]));
pop_current_class();
current_class = cls;
current_container = container;
current_extensionContainer = null;
}
yyVal = pop_current_class ();
}
break;
示例4: Visit
public virtual void Visit (Class c)
{
VisitTypeDefinition (c);
}
示例5: Visit
public override void Visit(Class c)
{
var newType = new TypeDeclaration();
newType.ClassType = ClassType.Class;
AddAttributeSection(newType, c);
var location = LocationsBag.GetMemberLocation(c);
AddModifiers(newType, location);
int curLoc = 0;
if (location != null && location.Count > 0)
newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.ClassKeyword), Roles.ClassKeyword);
newType.AddChild(Identifier.Create(c.MemberName.Name, Convert(c.MemberName.Location)), Roles.Identifier);
AddTypeParameters(newType, c.MemberName);
if (c.TypeBaseExpressions != null) {
if (location != null && curLoc < location.Count)
newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.Colon), Roles.Colon);
var commaLocations = LocationsBag.GetLocations(c.TypeBaseExpressions);
int i = 0;
foreach (var baseTypes in c.TypeBaseExpressions) {
newType.AddChild(ConvertToType(baseTypes), Roles.BaseType);
if (commaLocations != null && i < commaLocations.Count) {
newType.AddChild(new CSharpTokenNode(Convert(commaLocations [i]), Roles.Comma), Roles.Comma);
i++;
}
}
}
AddConstraints(newType, c.CurrentTypeParameters);
if (location != null && curLoc < location.Count)
newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.LBrace), Roles.LBrace);
typeStack.Push(newType);
base.Visit(c);
AddAttributeSection(newType, c.UnattachedAttributes, EntityDeclaration.UnattachedAttributeRole);
if (location != null && curLoc < location.Count) {
newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.RBrace), Roles.RBrace);
if (location != null && curLoc < location.Count)
newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.Semicolon), Roles.Semicolon);
} else {
// parser error, set end node to max value.
newType.AddChild(new ErrorNode(), Roles.Error);
}
typeStack.Pop();
AddType(newType);
}
示例6: CompileBlock
CompiledMethod CompileBlock (Class host, Undo undo, Report Report)
{
#if STATIC
throw new NotSupportedException ();
#else
string current_debug_name = "eval-" + count + ".dll";
++count;
AssemblyDefinitionDynamic assembly;
AssemblyBuilderAccess access;
if (Environment.GetEnvironmentVariable ("SAVE") != null) {
access = AssemblyBuilderAccess.RunAndSave;
assembly = new AssemblyDefinitionDynamic (module, current_debug_name, current_debug_name);
assembly.Importer = importer;
} else {
#if NET_4_0
access = AssemblyBuilderAccess.RunAndCollect;
#else
access = AssemblyBuilderAccess.Run;
#endif
assembly = new AssemblyDefinitionDynamic (module, current_debug_name);
}
assembly.Create (AppDomain.CurrentDomain, access);
Method expression_method;
if (host != null) {
var base_class_imported = importer.ImportType (base_class);
var baseclass_list = new List<FullNamedExpression> (1) {
new TypeExpression (base_class_imported, host.Location)
};
host.SetBaseTypes (baseclass_list);
expression_method = (Method) host.Members[0];
if ((expression_method.ModFlags & Modifiers.ASYNC) != 0) {
//
// Host method is async. When WaitOnTask is set we wrap it with wait
//
// void AsyncWait (ref object $retval) {
// $retval = Host();
// ((Task)$retval).Wait(); // When WaitOnTask is set
// }
//
var p = new ParametersCompiled (
new Parameter (new TypeExpression (module.Compiler.BuiltinTypes.Object, Location.Null), "$retval", Parameter.Modifier.REF, null, Location.Null)
);
var method = new Method(host, new TypeExpression(module.Compiler.BuiltinTypes.Void, Location.Null),
Modifiers.PUBLIC | Modifiers.STATIC, new MemberName("AsyncWait"), p, null);
method.Block = new ToplevelBlock(method.Compiler, p, Location.Null);
method.Block.AddStatement(new StatementExpression (new SimpleAssign(
new SimpleName(p [0].Name, Location.Null),
new Invocation(new SimpleName(expression_method.MemberName.Name, Location.Null), new Arguments(0)),
Location.Null), Location.Null));
if (WaitOnTask) {
var task = new Cast (expression_method.TypeExpression, new SimpleName (p [0].Name, Location.Null), Location.Null);
method.Block.AddStatement (new StatementExpression (new Invocation (
new MemberAccess (task, "Wait", Location.Null),
new Arguments (0)), Location.Null));
}
host.AddMember(method);
expression_method = method;
}
host.CreateContainer();
host.DefineContainer();
host.Define();
} else {
expression_method = null;
}
module.CreateContainer ();
// Disable module and source file re-definition checks
module.EnableRedefinition ();
source_file.EnableRedefinition ();
module.Define ();
if (Report.Errors != 0){
if (undo != null)
undo.ExecuteUndo ();
return null;
}
if (host != null){
host.PrepareEmit ();
host.EmitContainer ();
}
//.........这里部分代码省略.........
示例7: Visit
public override void Visit (Class c)
{
VisitClass(c);
}
示例8: CompileBlock
static CompiledMethod CompileBlock (Class host, Undo undo, Report Report)
{
RootContext.ResolveTree ();
if (Report.Errors != 0){
undo.ExecuteUndo ();
return null;
}
RootContext.PopulateTypes ();
if (Report.Errors != 0){
undo.ExecuteUndo ();
return null;
}
TypeBuilder tb = null;
MethodBuilder mb = null;
if (host != null){
tb = host.TypeBuilder;
mb = null;
foreach (MemberCore member in host.Methods){
if (member.Name != "Host")
continue;
MethodOrOperator method = (MethodOrOperator) member;
mb = method.MethodBuilder;
break;
}
if (mb == null)
throw new Exception ("Internal error: did not find the method builder for the generated method");
}
RootContext.EmitCode ();
if (Report.Errors != 0){
undo.ExecuteUndo ();
return null;
}
RootContext.CloseTypes (ctx);
if (Environment.GetEnvironmentVariable ("SAVE") != null)
CodeGen.Save (current_debug_name, false, Report);
if (host == null)
return null;
//
// Unlike Mono, .NET requires that the MethodInfo is fetched, it cant
// work from MethodBuilders. Retarded, I know.
//
var tt = CodeGen.Assembly.Builder.GetType (tb.Name);
MethodInfo mi = tt.GetMethod (mb.Name);
// Pull the FieldInfos from the type, and keep track of them
foreach (Field field in queued_fields){
FieldInfo fi = tt.GetField (field.Name);
Tuple<FieldSpec, FieldInfo> old;
// If a previous value was set, nullify it, so that we do
// not leak memory
if (fields.TryGetValue (field.Name, out old)) {
if (old.Item1.MemberType.IsStruct) {
//
// TODO: Clear fields for structs
//
} else {
try {
old.Item2.SetValue (null, null);
} catch {
}
}
fields [field.Name] = Tuple.Create (old.Item1, fi);
} else {
fields.Add (field.Name, Tuple.Create (field.Spec, fi));
}
}
//types.Add (tb);
queued_fields.Clear ();
return (CompiledMethod) System.Delegate.CreateDelegate (typeof (CompiledMethod), mi);
}
示例9: AddClass
public AdditionResult AddClass (Class c)
{
AdditionResult res;
if ((res = IsValid (c.Basename)) != AdditionResult.Success)
return res;
DefineName (c.Name, c);
types.Add (c);
return AdditionResult.Success;
}
示例10: case_637
void case_637()
#line 4203 "cs-parser.jay"
{
MemberName name = MakeName ((MemberName) yyVals[0+yyTop]);
Class c = new Class (current_namespace, current_class, name, (Modifiers) yyVals[-4+yyTop], (Attributes) yyVals[-5+yyTop]);
if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
FeatureIsNotAvailable (c.Location, "static classes");
}
push_current_class (c, yyVals[-3+yyTop]);
}
示例11: Visit
public override void Visit (Class c)
{
TypeDeclaration newType = new TypeDeclaration ();
newType.ClassType = ClassType.Class;
var location = LocationsBag.GetMemberLocation (c);
AddModifiers (newType, location);
if (location != null)
newType.AddChild (new CSharpTokenNode (Convert (location[0]), "class".Length), TypeDeclaration.Roles.Keyword);
newType.AddChild (new Identifier (c.Basename, Convert (c.MemberName.Location)), AstNode.Roles.Identifier);
if (c.MemberName.TypeArguments != null) {
var typeArgLocation = LocationsBag.GetLocations (c.MemberName);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[0]), 1), TypeDeclaration.Roles.LChevron);
AddTypeParameters (newType, typeArgLocation, c.MemberName.TypeArguments);
if (typeArgLocation != null)
newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation[1]), 1), TypeDeclaration.Roles.RChevron);
AddConstraints (newType, c);
}
if (c.TypeBaseExpressions != null) {
AddBaseTypes(newType, c);
}
if (location != null && location.Count > 1)
newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AstNode.Roles.LBrace);
typeStack.Push (newType);
base.Visit (c);
if (location != null && location.Count > 2)
newType.AddChild (new CSharpTokenNode (Convert (location[2]), 1), AstNode.Roles.RBrace);
typeStack.Pop ();
AddType (newType);
}
示例12: AddBaseTypes
void AddBaseTypes(TypeDeclaration parent, Class c)
{
if (c == null || c.TypeBaseExpressions == null)
return;
foreach (var expr in c.TypeBaseExpressions) {
parent.BaseTypes.Add(ConvertToType(expr));
}
}
示例13: case_639
void case_639()
{
Class c = new Class (current_container, (MemberName) yyVals[0+yyTop], (Modifiers) yyVals[-4+yyTop], (Attributes) yyVals[-5+yyTop]);
if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
FeatureIsNotAvailable (c.Location, "static classes");
}
push_current_container (c, yyVals[-3+yyTop]);
}
示例14: case_685
void case_685()
#line 4751 "cs-parser.jay"
{
lexer.ConstraintsParsing = true;
Class c = new Class (current_container, (MemberName) yyVals[0+yyTop], (Modifiers) yyVals[-4+yyTop], (Attributes) yyVals[-5+yyTop]);
if (((c.ModFlags & Modifiers.STATIC) != 0) && lang_version == LanguageVersion.ISO_1) {
FeatureIsNotAvailable (c.Location, "static classes");
}
push_current_container (c, yyVals[-3+yyTop]);
lbag.AddMember (current_container, GetModifierLocations (), GetLocation (yyVals[-2+yyTop]));
}
示例15: VisitClass
private void VisitClass(Class c)
{
if (visitedClasses.Contains(c)) {
Skip = true;
return;
}
visitedClasses.Add(c);
switch (CurrentPass) {
case Pass.DiscoverClassesAndMethods: {
TypeSpec baseType = c.BaseType;
if (baseType != null) {
if (verbose) {
Console.WriteLine("[Auto-sealing] Found parent class {0} for class {1}.", baseType.GetSignatureForError(), c.GetSignatureForError());
}
baseTypes.Add (baseType);
if (baseType.MemberDefinition is ImportedTypeDefinition) {
// The base class is coming from another assembly - It will not be visited as part of this assembly
// But we still have to get some of its information recursively
// and visit all the methods
// TODO: Do the parsing work
}
}
break;
}
case Pass.FinalizeModifierFlags:
// Last class of a hierarchy are auto-sealed if they are not static
if (IsLeafClass(c.CurrentType) && ((c.ModFlags & Modifiers.STATIC) == 0)) {
if (verbose) {
Console.WriteLine("[Auto-sealing] Making class {0} sealed.", c.GetSignatureForError());
}
// When we seal here, we get proper compile error, however the class does not seem to be marked as sealed in IL
c.ModFlags |= Modifiers.SEALED;
}
break;
}
}