本文整理汇总了C#中Context类的典型用法代码示例。如果您正苦于以下问题:C# Context类的具体用法?C# Context怎么用?C# Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于命名空间,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecTest
static void ExecTest(Context context, IMatch testToken)
{
var token = new CaptureGroup(testToken);
if(token.Match(context))
{
WriteInfo("Match success.");
WriteLine(context);
while (token.MatchNext(context))
{
WriteInfo("MatchNext success.");
WriteLine(context);
}
WriteError("MatchNext failed.");
WriteLine(context);
}
else
{
WriteError("Match failed.");
WriteLine(context);
}
if (context.offset != 0)
WriteError("Warning: Context offset not reset to 0.");
}
示例2: ensures_same_deterministic_order_when_getting_entities_after_DestroyAllEntities
public void ensures_same_deterministic_order_when_getting_entities_after_DestroyAllEntities()
{
var context = new Context(1);
const int numEntities = 10;
for (int i = 0; i < numEntities; i++) {
context.CreateEntity();
}
var order1 = new int[numEntities];
var entities1 = context.GetEntities();
for (int i = 0; i < numEntities; i++) {
order1[i] = entities1[i].creationIndex;
}
context.DestroyAllEntities();
context.ResetCreationIndex();
for (int i = 0; i < numEntities; i++) {
context.CreateEntity();
}
var order2 = new int[numEntities];
var entities2 = context.GetEntities();
for (int i = 0; i < numEntities; i++) {
order2[i] = entities2[i].creationIndex;
}
for (int i = 0; i < numEntities; i++) {
var index1 = order1[i];
var index2 = order2[i];
Assert.AreEqual(index1, index2);
}
}
示例3: StartListening
private void StartListening()
{
context = new Context(1);
socket = context.Socket(SocketType.PULL);
socket.Connect("tcp://127.0.0.1:8400"); // Connect to 8400
UpdateTextBox("Connected to 127.0.0.1:8400");
}
示例4: Parse
/// <summary>
/// Parse bytes in context into a FlaggedPropertyValueNode
/// </summary>
/// <param name="context">The value of Context</param>
public override void Parse(Context context)
{
this.Flag = context.PropertyBytes[context.CurIndex++];
switch (this.Flag)
{
// PropertyValue presents
case 0:
break;
// PropertyValue not presents
case 1:
return;
// Property error code
case 0xA:
// If the Flag is 0x0A, the property type should be PtypErrorCode.
context.CurProperty.Type = PropertyType.PtypErrorCode;
break;
// Not defined value
default:
break;
}
base.Parse(context);
}
示例5: ReadTemplateFile
public string ReadTemplateFile(Context context, string templateName)
{
string templatePath = (string) context[templateName];
switch (templatePath)
{
case "product":
return "Product: {{ product.title }} ";
case "locale_variables":
return "Locale: {{echo1}} {{echo2}}";
case "variant":
return "Variant: {{ variant.title }}";
case "nested_template":
return "{% include 'header' %} {% include 'body' %} {% include 'footer' %}";
case "body":
return "body {% include 'body_detail' %}";
case "nested_product_template":
return "Product: {{ nested_product_template.title }} {%include 'details'%} ";
case "recursively_nested_template":
return "-{% include 'recursively_nested_template' %}";
case "pick_a_source":
return "from TestFileSystem";
default:
return templatePath;
}
}
示例6: GetAIStateClient
protected AIStateClient GetAIStateClient(Context context)
{
if (Shmipl.StatePath.IsSubState(context.State, Phase.Auction))
return new AIStateClient_Auction();
if (context.armyFight != null || context.navyFight != null)
return new AIStateClient_Fight();
if (context.State.StartsWith("Turn.PlaceMetro"))
return new AIStateClient_PlaceMetro(context.State.Equals("Turn.PlaceMetroBuilding"));
switch (context.turn.CurrentGod)
{
case God.Zeus:
return new AIStateClient_Zeus();
case God.Sophia:
return new AIStateClient_Sophia();
case God.Poseidon:
return new AIStateClient_Poseidon();
case God.Mars:
return new AIStateClient_Mars();
case God.Appolon:
return new AIStateClient_Apollo();
}
throw new Exception("AI: unknown GetAIStateClient");
}
示例7: TransportadorasController
public TransportadorasController()
{
context = new Context();
var dataBaseInitializer = new DataBaseInitializer();
dataBaseInitializer.InitializeDatabase(context);
repositorioTransportadora = new Repository<Transportadora>(context);
}
示例8: Decode
/// <summary>
/// Decodes the specified instruction.
/// </summary>
/// <param name="ctx">The context.</param>
/// <param name="decoder">The instruction decoder, which holds the code stream.</param>
public override void Decode(Context ctx, IInstructionDecoder decoder)
{
// Decode base classes first
base.Decode(ctx, decoder);
Token token = decoder.DecodeTokenType();
ITypeModule module = null;
Mosa.Runtime.TypeSystem.Generic.CilGenericType genericType = decoder.Method.DeclaringType as Mosa.Runtime.TypeSystem.Generic.CilGenericType;
if (genericType != null)
module = (decoder.Method.DeclaringType as Mosa.Runtime.TypeSystem.Generic.CilGenericType).BaseGenericType.Module;
else
module = decoder.Method.Module;
ctx.RuntimeField = module.GetField(token);
if (ctx.RuntimeField.ContainsGenericParameter)
{
foreach (RuntimeField field in decoder.Method.DeclaringType.Fields)
if (field.Name == ctx.RuntimeField.Name)
{
ctx.RuntimeField = field;
break;
}
Debug.Assert(!ctx.RuntimeField.ContainsGenericParameter);
}
SigType sigType = ctx.RuntimeField.SignatureType;
ctx.Result = LoadInstruction.CreateResultOperand(decoder, Operand.StackTypeFromSigType(sigType), sigType);
}
示例9: ExecIdCall
public override System.Object ExecIdCall(IdFunctionObject f, Context cx, IScriptable scope, IScriptable thisObj, System.Object [] args)
{
if (!f.HasTag (XMLCTOR_TAG)) {
return base.ExecIdCall (f, cx, scope, thisObj, args);
}
int id = f.MethodId;
switch (id) {
case Id_defaultSettings: {
lib.SetDefaultSettings ();
IScriptable obj = cx.NewObject (scope);
WriteSetting (obj);
return obj;
}
case Id_settings: {
IScriptable obj = cx.NewObject (scope);
WriteSetting (obj);
return obj;
}
case Id_setSettings: {
if (args.Length == 0 || args [0] == null || args [0] == Undefined.Value) {
lib.SetDefaultSettings ();
}
else if (args [0] is IScriptable) {
ReadSettings ((IScriptable)args [0]);
}
return Undefined.Value;
}
}
throw new System.ArgumentException (System.Convert.ToString (id));
}
示例10: Set
public object Set(Context cx, object value)
{
if (xmlObject == null)
throw ScriptRuntime.UndefWriteError (this, ToString (), value);
xmlObject.PutXMLProperty (this, value);
return value;
}
示例11: TestEncodeMessageWithAllFieldTypes
public void TestEncodeMessageWithAllFieldTypes()
{
var template = new MessageTemplate(
"",
new Field[]
{
new Scalar("1", FastType.String, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("2", FastType.ByteVector, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("3", FastType.Decimal, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("4", FastType.I32, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("5", FastType.String, Operator.Copy, ScalarValue.Undefined, false),
new Scalar("6", FastType.U32, Operator.Copy, ScalarValue.Undefined, false),
});
var context = new Context();
context.RegisterTemplate(113, template);
var message = new Message(template);
message.SetString(1, "H");
message.SetByteVector(2, new[] {(byte) 0xFF});
message.SetDecimal(3, 1.201);
message.SetInteger(4, -1);
message.SetString(5, "abc");
message.SetInteger(6, 2);
// --PMAP-- --TID--- ---#1--- -------#2-------- ------------#3------------ ---#4--- ------------#5------------ ---#6---
const string msgstr =
"11111111 11110001 11001000 10000001 11111111 11111101 00001001 10110001 11111111 01100001 01100010 11100011 10000010";
AssertEquals(msgstr, new FastEncoder(context).Encode(message));
}
示例12: InsertBlockProtectInstructions
private void InsertBlockProtectInstructions()
{
foreach (var handler in MethodCompiler.Method.ExceptionHandlers)
{
var tryBlock = BasicBlocks.GetByLabel(handler.TryStart);
var tryHandler = BasicBlocks.GetByLabel(handler.HandlerStart);
var context = new Context(InstructionSet, tryBlock);
while (context.IsEmpty || context.Instruction == IRInstruction.TryStart)
{
context.GotoNext();
}
context.AppendInstruction(IRInstruction.TryStart, tryHandler);
context = new Context(InstructionSet, tryHandler);
if (handler.HandlerType == ExceptionHandlerType.Exception)
{
var exceptionObject = MethodCompiler.CreateVirtualRegister(handler.Type);
context.AppendInstruction(IRInstruction.ExceptionStart, exceptionObject);
}
else if (handler.HandlerType == ExceptionHandlerType.Finally)
{
context.AppendInstruction(IRInstruction.FinallyStart);
}
}
}
示例13: ContinueCodelet
public ContinueCodelet(double salience, Context context, IContinuation succ, IFailure fail)
: base(context.Coderack, salience, 4 * 4, 5)
{
this.context = context;
this.succ = succ;
this.fail = fail;
}
示例14: test_empty
public static void test_empty()
{
var context = new Context("abc");
var empty = new Empty();
ExecTest(context, empty);
}
示例15: Process
public Process(Context context)
: base(context)
{
Constructor = new ProcessConstructor(context, "Process", new ProcessInstance(context.Events.EventEmitter.InstancePrototype, false));
Instance = Constructor.Construct();
Populate();
}