本文整理汇总了C#中Table.Get方法的典型用法代码示例。如果您正苦于以下问题:C# Table.Get方法的具体用法?C# Table.Get怎么用?C# Table.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table
的用法示例。
在下文中一共展示了Table.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
public CodeExpression[] Generate(Table table, HardwireCodeGenerationContext generatorContext, CodeTypeMemberCollection members)
{
string className = "AIDX_" + Guid.NewGuid().ToString("N");
string name = table.Get("name").String;
bool setter = table.Get("setter").Boolean;
CodeTypeDeclaration classCode = new CodeTypeDeclaration(className);
classCode.TypeAttributes = System.Reflection.TypeAttributes.NestedPrivate | System.Reflection.TypeAttributes.Sealed;
classCode.BaseTypes.Add(typeof(ArrayMemberDescriptor));
CodeConstructor ctor = new CodeConstructor();
ctor.Attributes = MemberAttributes.Assembly;
classCode.Members.Add(ctor);
ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(name));
ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(setter));
DynValue vparams = table.Get("params");
if (vparams.Type == DataType.Table)
{
List<HardwireParameterDescriptor> paramDescs = HardwireParameterDescriptor.LoadDescriptorsFromTable(vparams.Table);
ctor.BaseConstructorArgs.Add(new CodeArrayCreateExpression(typeof(ParameterDescriptor), paramDescs.Select(e => e.Expression).ToArray()));
}
members.Add(classCode);
return new CodeExpression[] { new CodeObjectCreateExpression(className) };
}
示例2: Generate
public CodeExpression[] Generate(Table table, HardwireCodeGenerationContext generatorContext, CodeTypeMemberCollection members)
{
string className = "DVAL_" + Guid.NewGuid().ToString("N");
DynValue kval = table.Get("value");
DynValue vtype = table.Get("type");
DynValue vstaticType = table.Get("staticType");
string type = (vtype.Type == DataType.String) ? vtype.String : null;
string staticType = (vstaticType.Type == DataType.String) ? vstaticType.String : null;
CodeTypeDeclaration classCode = new CodeTypeDeclaration(className);
classCode.TypeAttributes = System.Reflection.TypeAttributes.NestedPrivate | System.Reflection.TypeAttributes.Sealed;
classCode.BaseTypes.Add(typeof(DynValueMemberDescriptor));
CodeConstructor ctor = new CodeConstructor();
ctor.Attributes = MemberAttributes.Assembly;
classCode.Members.Add(ctor);
if (type == null)
{
Table tbl = new Table(null);
tbl.Set(1, kval);
string str = tbl.Serialize();
ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(table.Get("name").String));
ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(str));
}
else if (type == "userdata")
{
ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(table.Get("name").String));
CodeMemberProperty p = new CodeMemberProperty();
p.Name = "Value";
p.Type = new CodeTypeReference(typeof(DynValue));
p.Attributes = MemberAttributes.Override | MemberAttributes.Public;
p.GetStatements.Add(
new CodeMethodReturnStatement(
new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(typeof(UserData)),
"CreateStatic", new CodeTypeOfExpression(staticType))));
classCode.Members.Add(p);
}
members.Add(classCode);
return new CodeExpression[] { new CodeObjectCreateExpression(className) };
}
示例3: Generate
public CodeExpression[] Generate(Table table, HardwireCodeGenerationContext generator,
CodeTypeMemberCollection members)
{
string type = (string)table["$key"];
string className = "TYPE_" + Guid.NewGuid().ToString("N");
CodeTypeDeclaration classCode = new CodeTypeDeclaration(className);
classCode.Comments.Add(new CodeCommentStatement("Descriptor of " + type));
classCode.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Descriptor of " + type));
classCode.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));
classCode.TypeAttributes = System.Reflection.TypeAttributes.NestedPrivate | System.Reflection.TypeAttributes.Sealed;
classCode.BaseTypes.Add(typeof(HardwiredUserDataDescriptor));
CodeConstructor ctor = new CodeConstructor();
ctor.Attributes = MemberAttributes.Assembly;
ctor.BaseConstructorArgs.Add(new CodeTypeOfExpression(type));
classCode.Members.Add(ctor);
generator.DispatchTablePairs(table.Get("members").Table,
classCode.Members, (key, exp) =>
{
var mname = new CodePrimitiveExpression(key);
ctor.Statements.Add(new CodeMethodInvokeExpression(
new CodeThisReferenceExpression(), "AddMember", mname, exp));
});
generator.DispatchTablePairs(table.Get("metamembers").Table,
classCode.Members, (key, exp) =>
{
var mname = new CodePrimitiveExpression(key);
ctor.Statements.Add(new CodeMethodInvokeExpression(
new CodeThisReferenceExpression(), "AddMetaMember", mname, exp));
});
members.Add(classCode);
return new CodeExpression[] {
new CodeObjectCreateExpression(className)
};
}
示例4: LoadDescriptorsFromTable
public static List<HardwireParameterDescriptor> LoadDescriptorsFromTable(Table t)
{
List<HardwireParameterDescriptor> list = new List<HardwireParameterDescriptor>();
for (int i = 1; i <= t.Length; i++)
{
list.Add(new HardwireParameterDescriptor(t.Get(i).Table));
}
return list;
}
示例5: Generate
public CodeExpression[] Generate(Table table, HardwireCodeGenerationContext generator,
CodeTypeMemberCollection members)
{
List<CodeExpression> initializers = new List<CodeExpression>();
generator.DispatchTablePairs(table.Get("overloads").Table, members, exp =>
{
initializers.Add(exp);
});
var name = new CodePrimitiveExpression((table["name"] as string));
var type = new CodeTypeOfExpression(table["decltype"] as string);
var array = new CodeArrayCreateExpression(typeof(IOverloadableMemberDescriptor), initializers.ToArray());
return new CodeExpression[] {
new CodeObjectCreateExpression(typeof(OverloadedMethodMemberDescriptor), name, type, array)
};
}
示例6: TableToJson
/// <summary>
/// Tables to json.
/// </summary>
/// <param name="sb">The sb.</param>
/// <param name="table">The table.</param>
private static void TableToJson(StringBuilder sb, Table table)
{
bool first = true;
if (table.Length == 0)
{
sb.Append("{");
foreach (TablePair pair in table.Pairs)
{
if (pair.Key.Type == DataType.String && IsValueJsonCompatible(pair.Value))
{
if (!first)
sb.Append(',');
ValueToJson(sb, pair.Key);
sb.Append(':');
ValueToJson(sb, pair.Value);
first = false;
}
}
sb.Append("}");
}
else
{
sb.Append("[");
for (int i = 1; i <= table.Length; i++)
{
DynValue value = table.Get(i);
if (IsValueJsonCompatible(value))
{
if (!first)
sb.Append(',');
ValueToJson(sb, value);
first = false;
}
}
sb.Append("]");
}
}
示例7: MoonSharpInit
public static void MoonSharpInit(Table globalTable, Table ioTable)
{
DynValue package = globalTable.Get("package");
if (package.IsNil())
{
package = DynValue.NewTable(globalTable.OwnerScript);
globalTable["package"] = package;
}
else if (package.Type != DataType.Table)
{
throw new InternalErrorException("'package' global variable was found and it is not a table");
}
#if PCL
string cfg = "\\\n;\n?\n!\n-\n";
#else
string cfg = System.IO.Path.DirectorySeparatorChar + "\n;\n?\n!\n-\n";
#endif
package.Table.Set("config", DynValue.NewString(cfg));
}
示例8: Response
public Response(Table req) : base("response")
{
success = true;
request_seq = req.Get("seq").ToObject<int>();
command = req.Get("command").ToObject<string>();
}
示例9: PullData
private static void PullData(Table table, BuffCastEventPrototype proto)
{
proto.timer = (int)table.Get("timer").Number;
proto.stat = (stats)(int)table.Get("stat").Number;
proto.amount = (int)table.Get("amount").Number;
}
示例10: HardwireParameterDescriptor
public HardwireParameterDescriptor(Table tpar)
{
CodeExpression ename = new CodePrimitiveExpression(tpar.Get("name").String);
CodeExpression etype = new CodeTypeOfExpression(tpar.Get("origtype").String);
CodeExpression hasDefaultValue = new CodePrimitiveExpression(tpar.Get("default").Boolean);
CodeExpression defaultValue = tpar.Get("default").Boolean ? (CodeExpression)(new CodeObjectCreateExpression(typeof(DefaultValue))) :
(CodeExpression)(new CodePrimitiveExpression(null));
CodeExpression isOut = new CodePrimitiveExpression(tpar.Get("out").Boolean);
CodeExpression isRef = new CodePrimitiveExpression(tpar.Get("ref").Boolean);
CodeExpression isVarArg = new CodePrimitiveExpression(tpar.Get("varargs").Boolean);
CodeExpression restrictType = tpar.Get("restricted").Boolean ? (CodeExpression)(new CodeTypeOfExpression(tpar.Get("type").String)) :
(CodeExpression)(new CodePrimitiveExpression(null));
Expression = new CodeObjectCreateExpression(typeof(ParameterDescriptor), new CodeExpression[] {
ename, etype, hasDefaultValue, defaultValue, isOut, isRef,
isVarArg }
);
ParamType = tpar.Get("origtype").String;
HasDefaultValue = tpar.Get("default").Boolean;
IsOut = tpar.Get("out").Boolean;
IsRef = tpar.Get("ref").Boolean;
}
示例11: ConvertTableToPortraitOptions
/// <summary>
/// Convert a Moonsharp table to portrait options
/// If the table returns a null for any of the parameters, it should keep the defaults
/// </summary>
/// <param name="table">Moonsharp Table</param>
/// <param name="stage">Stage</param>
/// <returns></returns>
public static PortraitOptions ConvertTableToPortraitOptions(Table table, Stage stage)
{
PortraitOptions options = new PortraitOptions(true);
// If the table supplies a nil, keep the default
options.character = table.Get("character").ToObject<Character>()
?? options.character;
options.replacedCharacter = table.Get("replacedCharacter").ToObject<Character>()
?? options.replacedCharacter;
if (!table.Get("portrait").IsNil())
{
options.portrait = options.character.GetPortrait(table.Get("portrait").CastToString());
}
if (!table.Get("display").IsNil())
{
options.display = table.Get("display").ToObject<DisplayType>();
}
if (!table.Get("offset").IsNil())
{
options.offset = table.Get("offset").ToObject<PositionOffset>();
}
if (!table.Get("fromPosition").IsNil())
{
options.fromPosition = stage.GetPosition(table.Get("fromPosition").CastToString());
}
if (!table.Get("toPosition").IsNil())
{
options.toPosition = stage.GetPosition(table.Get("toPosition").CastToString());
}
if (!table.Get("facing").IsNil())
{
var facingDirection = FacingDirection.None;
DynValue v = table.Get("facing");
if (v.Type == DataType.String)
{
if (string.Compare(v.String, "left", true) == 0)
{
facingDirection = FacingDirection.Left;
}
else if (string.Compare(v.String, "right", true) == 0)
{
facingDirection = FacingDirection.Right;
}
}
else
{
facingDirection = table.Get("facing").ToObject<FacingDirection>();
}
options.facing = facingDirection;
}
if (!table.Get("useDefaultSettings").IsNil())
{
options.useDefaultSettings = table.Get("useDefaultSettings").CastToBool();
}
if (!table.Get("fadeDuration").IsNil())
{
options.fadeDuration = table.Get("fadeDuration").ToObject<float>();
}
if (!table.Get("moveDuration").IsNil())
{
options.moveDuration = table.Get("moveDuration").ToObject<float>();
}
if (!table.Get("move").IsNil())
{
options.move = table.Get("move").CastToBool();
}
else if (options.fromPosition != options.toPosition)
{
options.move = true;
}
if (!table.Get("shiftIntoPlace").IsNil())
{
options.shiftIntoPlace = table.Get("shiftIntoPlace").CastToBool();
}
if (!table.Get("waitUntilFinished").IsNil())
{
options.waitUntilFinished = table.Get("waitUntilFinished").CastToBool();
}
//.........这里部分代码省略.........
示例12: GenerateCall
private CodeStatementCollection GenerateCall(Table table, HardwireCodeGenerationContext generator, bool isVoid, bool isCtor, bool isStatic, bool isExtension, CodeExpression[] arguments, CodeExpression paramThis, string declaringType, bool specialName, int refparCount)
{
string arrayCtorType = table.Get("arraytype").IsNil() ? null : table.Get("arraytype").String;
CodeStatementCollection coll = new CodeStatementCollection();
CodeExpression retVal = null;
if (isCtor)
{
if (arrayCtorType != null)
{
var exp = generator.TargetLanguage.CreateMultidimensionalArray(arrayCtorType,
arguments);
retVal = new CodeArrayCreateExpression(arrayCtorType, arguments);
}
else
{
retVal = new CodeObjectCreateExpression(table.Get("ret").String, arguments);
}
}
else if (specialName)
{
GenerateSpecialNameCall(table, generator, isVoid, isCtor, isStatic, isExtension,
arguments, paramThis, declaringType, table.Get("name").String, coll);
}
else
{
retVal = new CodeMethodInvokeExpression(paramThis, table.Get("name").String, arguments);
}
if (retVal != null)
{
if (isVoid)
{
coll.Add(new CodeExpressionStatement(retVal));
retVal = new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(typeof(DynValue)), (refparCount == 0) ? "Void" : "Nil");
}
if (refparCount == 0)
{
coll.Add(new CodeMethodReturnStatement(retVal));
}
else
{
coll.Add(new CodeVariableDeclarationStatement(typeof(object), "retv", retVal));
List<CodeExpression> retVals = new List<CodeExpression>();
retVals.Add(WrapFromObject(new CodeVariableReferenceExpression("retv")));
for (int i = 0; i < refparCount; i++)
retVals.Add(WrapFromObject(new CodeVariableReferenceExpression(GenerateRefParamVariable(i))));
var arrayExp = new CodeArrayCreateExpression(typeof(DynValue), retVals.ToArray());
var tupleExp = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(DynValue)), "NewTuple", arrayExp);
coll.Add(new CodeMethodReturnStatement(tupleExp));
}
}
return coll;
}
示例13: Generate
public CodeExpression[] Generate(Table table, HardwireCodeGenerationContext generator, CodeTypeMemberCollection members)
{
bool isStatic = table.Get("static").Boolean;
string memberType = table.Get("type").String;
string name = table.Get("name").String;
string decltype = table.Get("decltype").String;
bool declvtype = table.Get("declvtype").Boolean;
bool canWrite = table.Get("write").Boolean;
bool canRead = table.Get("read").Boolean;
if (declvtype && canWrite)
{
generator.Warning("Member '{0}.{1}::Set' will be a no-op, as it's a member of a value type.", decltype, name);
}
MemberDescriptorAccess access = 0;
if (canWrite)
access = access | MemberDescriptorAccess.CanWrite;
if (canRead)
access = access | MemberDescriptorAccess.CanRead;
string className = GetPrefix() + "_" + Guid.NewGuid().ToString("N");
CodeTypeDeclaration classCode = new CodeTypeDeclaration(className);
classCode.TypeAttributes = System.Reflection.TypeAttributes.NestedPrivate | System.Reflection.TypeAttributes.Sealed;
classCode.BaseTypes.Add(typeof(HardwiredMemberDescriptor));
// protected HardwiredMemberDescriptor(Type memberType, string name, bool isStatic, MemberDescriptorAccess access)
CodeConstructor ctor = new CodeConstructor();
ctor.Attributes = MemberAttributes.Assembly;
ctor.BaseConstructorArgs.Add(new CodeTypeOfExpression(memberType));
ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(name));
ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(isStatic));
ctor.BaseConstructorArgs.Add(new CodeCastExpression(typeof(MemberDescriptorAccess), new CodePrimitiveExpression((int)access)));
classCode.Members.Add(ctor);
var thisExp = isStatic
? (CodeExpression)(new CodeTypeReferenceExpression(decltype))
: (CodeExpression)(new CodeCastExpression(decltype, new CodeVariableReferenceExpression("obj")));
if (canRead)
{
var memberExp = GetMemberAccessExpression(thisExp, name);
// protected virtual object GetValueImpl(Script script, object obj)
CodeMemberMethod m = new CodeMemberMethod();
classCode.Members.Add(m);
m.Name = "GetValueImpl";
m.Attributes = MemberAttributes.Override | MemberAttributes.Family;
m.ReturnType = new CodeTypeReference(typeof(object));
m.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Script), "script"));
m.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "obj"));
m.Statements.Add(new CodeMethodReturnStatement(memberExp));
}
if (canWrite)
{
// protected virtual object GetValueImpl(Script script, object obj)
CodeMemberMethod m = new CodeMemberMethod();
classCode.Members.Add(m);
m.Name = "SetValueImpl";
m.Attributes = MemberAttributes.Override | MemberAttributes.Family;
m.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Script), "script"));
m.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "obj"));
m.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "value"));
var valExp = new CodeCastExpression(memberType, new CodeVariableReferenceExpression("value"));
if (isStatic)
{
var e = GetMemberAccessExpression(thisExp, name);
m.Statements.Add(new CodeAssignStatement(e, valExp));
}
else
{
m.Statements.Add(new CodeVariableDeclarationStatement(decltype, "tmp", thisExp));
var memberExp = GetMemberAccessExpression(new CodeVariableReferenceExpression("tmp"), name);
m.Statements.Add(new CodeAssignStatement(memberExp, valExp));
}
}
members.Add(classCode);
return new CodeExpression[] { new CodeObjectCreateExpression(className) };
}
示例14: GetTimeTableField
private static int? GetTimeTableField(Table t, string key)
{
DynValue v = t.Get(key);
double? d = v.CastToNumber();
if (d.HasValue)
return (int)d.Value;
return null;
}
示例15: ConvertTableToPortraitOptions
/// <summary>
/// Convert a Moonsharp table to portrait options
/// If the table returns a null for any of the parameters, it should keep the defaults
/// </summary>
/// <param name="table">Moonsharp Table</param>
/// <param name="stage">Stage</param>
/// <returns></returns>
public static PortraitOptions ConvertTableToPortraitOptions(Table table, Stage stage)
{
PortraitOptions options = new PortraitOptions(true);
// If the table supplies a nil, keep the default
options.character = table.Get("character").ToObject<Character>()
?? options.character;
options.replacedCharacter = table.Get("replacedCharacter").ToObject<Character>()
?? options.replacedCharacter;
if (!table.Get("portrait").IsNil())
{
options.portrait = options.character.GetPortrait(table.Get("portrait").CastToString());
}
if (!table.Get("display").IsNil())
{
options.display = table.Get("display").ToObject<DisplayType>();
}
if (!table.Get("offset").IsNil())
{
options.offset = table.Get("offset").ToObject<PositionOffset>();
}
if (!table.Get("fromPosition").IsNil())
{
options.fromPosition = stage.GetPosition(table.Get("fromPosition").CastToString());
}
if (!table.Get("toPosition").IsNil())
{
options.toPosition = stage.GetPosition(table.Get("toPosition").CastToString());
}
if (!table.Get("facing").IsNil())
{
options.facing = table.Get("facing").ToObject<FacingDirection>();
}
if (!table.Get("useDefaultSettings").IsNil())
{
options.useDefaultSettings = table.Get("useDefaultSettings").CastToBool();
}
if (!table.Get("fadeDuration").IsNil())
{
options.fadeDuration = table.Get("fadeDuration").ToObject<float>();
}
if (!table.Get("moveDuration").IsNil())
{
options.moveDuration = table.Get("moveDuration").ToObject<float>();
}
if (!table.Get("move").IsNil())
{
options.move = table.Get("move").CastToBool();
}
else if (options.fromPosition != options.toPosition)
{
options.move = true;
}
if (!table.Get("shiftIntoPlace").IsNil())
{
options.shiftIntoPlace = table.Get("shiftIntoPlace").CastToBool();
}
//TODO: Make the next lua command wait when this options is true
if (!table.Get("waitUntilFinished").IsNil())
{
options.waitUntilFinished = table.Get("waitUntilFinished").CastToBool();
}
return options;
}