本文整理汇总了C#中SObject.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# SObject.GetType方法的具体用法?C# SObject.GetType怎么用?C# SObject.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SObject
的用法示例。
在下文中一共展示了SObject.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddMember
public static SObject AddMember(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
{
// Parameter #1: (String)Name of the new member
// [Parameter #2: Default value of the new member ] / Undefined
// [Parameter #3: Signature config of the new member] / instance member, no special settings
if (parameters.Length == 0)
return processor.Undefined;
Prototype prototype;
if (IsPrototype(instance.GetType()))
{
prototype = (Prototype)instance;
}
else
{
// The instance will be a prototype instance, so get its prototype from there:
var protoObj = (SProtoObject)instance;
prototype = protoObj.Prototype;
}
string memberName;
if (parameters[0] is SString)
memberName = ((SString)parameters[0]).Value;
else
memberName = parameters[0].ToString(processor).Value;
var defaultValue = processor.Undefined;
if (parameters.Length > 1)
{
defaultValue = parameters[1];
}
var isReadOnly = false;
var isStatic = false;
var isIndexerGet = false;
var isIndexerSet = false;
if (parameters.Length > 2)
{
var signature = parameters[2];
if (signature is SArray)
{
foreach (var arrayMember in ((SArray)signature).ArrayMembers)
{
if (arrayMember is SString)
{
var signatureMember = ((SString)arrayMember).Value;
switch (signatureMember)
{
case "readOnly":
isReadOnly = true;
break;
case "static":
isStatic = true;
break;
case "indexerGet":
isIndexerGet = true;
break;
case "indexerSet":
isIndexerSet = true;
break;
}
}
}
}
}
if ((isIndexerSet || isIndexerGet) && !(defaultValue is SFunction))
processor.ErrorHandler.ThrowError(ErrorType.TypeError, ErrorHandler.MESSAGE_TYPE_GETTER_SETTER_NOT_A_FUNCTION);
if (!ScriptProcessor.IsValidIdentifier(memberName))
processor.ErrorHandler.ThrowError(ErrorType.SyntaxError, ErrorHandler.MESSAGE_SYNTAX_MISSING_VAR_NAME);
prototype.AddMember(processor, new PrototypeMember(memberName, defaultValue, isStatic, isReadOnly, isIndexerGet, isIndexerSet));
return processor.Undefined;
}