当前位置: 首页>>代码示例>>C#>>正文


C# SObject.GetType方法代码示例

本文整理汇总了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;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:80,代码来源:ObjectPrototype.cs


注:本文中的SObject.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。