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


C# RubyModule.GetOrCreateSingletonClass方法代码示例

本文整理汇总了C#中IronRuby.Builtins.RubyModule.GetOrCreateSingletonClass方法的典型用法代码示例。如果您正苦于以下问题:C# RubyModule.GetOrCreateSingletonClass方法的具体用法?C# RubyModule.GetOrCreateSingletonClass怎么用?C# RubyModule.GetOrCreateSingletonClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IronRuby.Builtins.RubyModule的用法示例。


在下文中一共展示了RubyModule.GetOrCreateSingletonClass方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Included

 public static object Included(RubyContext/*!*/ context, RubyModule/*!*/ self, RubyModule/*!*/ includedIn) {
     var singleton = includedIn.GetOrCreateSingletonClass();
     singleton.AddMethod(
         context,
         "induced_from",
         new RubyLibraryMethodInfo(
             new[] { LibraryOverload.Create(new Func<RubyModule, object, object>(InducedFrom), false, 0, 0) }, 
             RubyMethodVisibility.Public, 
             singleton
         )
     );
     return self;
 }
开发者ID:ExpertsInside,项目名称:IronSP,代码行数:13,代码来源:Precision.cs

示例2: SetMethodAttributes

        internal static void SetMethodAttributes(RubyModule/*!*/ module, string/*!*/[]/*!*/ methodNames, RubyMethodAttributes attributes) {
            var context = module.Context;

            bool isModuleFunction = (attributes & RubyMethodAttributes.ModuleFunction) == RubyMethodAttributes.ModuleFunction;
            var instanceVisibility = isModuleFunction ? RubyMethodVisibility.Private : 
                (RubyMethodVisibility)(attributes & RubyMethodAttributes.VisibilityMask);

            foreach (string methodName in methodNames) {
                RubyMemberInfo method;

                // we need to define new methods one by one since the method_added events can define a new method that might be used here:
                using (context.ClassHierarchyLocker()) {
                    MethodLookup options = MethodLookup.FallbackToObject;
                    if (!isModuleFunction) {
                        options |= MethodLookup.ReturnForwarder;
                    }

                    method = module.ResolveMethodNoLock(methodName, VisibilityContext.AllVisible, options).Info;
                    if (method == null) {
                        throw RubyExceptions.CreateUndefinedMethodError(module, methodName);
                    }

                    // MRI only adds method to the target module if visibility differs:
                    if (method.Visibility != instanceVisibility) {
                        module.SetVisibilityNoEventNoLock(context, methodName, method, instanceVisibility);
                    }

                    if (isModuleFunction) {
                        module.SetModuleFunctionNoEventNoLock(context, methodName, method);
                    }
                }

                if (method.Visibility != instanceVisibility) {
                    module.MethodAdded(methodName);
                }

                if (isModuleFunction) {
                    module.GetOrCreateSingletonClass().MethodAdded(methodName);
                }
            }
        }
开发者ID:yarrow2,项目名称:ironruby,代码行数:41,代码来源:ModuleOps.cs

示例3: RubyModule

        object IDuplicable.Duplicate(RubyContext/*!*/ context, bool copySingletonMembers) {
            
            // capture the current immediate class (it can change any time if it not a singleton class)
            RubyClass immediate = _immediateClass;

            RubyModule result = new RubyModule(immediate.IsSingletonClass ? immediate.SuperClass : immediate, null);

            // singleton members are copied here, not in InitializeCopy:
            if (copySingletonMembers && immediate.IsSingletonClass) {
                var singletonClass = result.GetOrCreateSingletonClass();
                using (Context.ClassHierarchyLocker()) {
                    singletonClass.InitializeMembersFrom(immediate);
                }
            }
            
            // copy instance variables:
            _context.CopyInstanceData(this, result, false);
            return result;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:19,代码来源:RubyModule.cs

示例4: MakeClassMethodsPublic

 public static RubyModule/*!*/ MakeClassMethodsPublic(RubyModule/*!*/ self,
     [DefaultProtocol, NotNullItems]params string/*!*/[]/*!*/ methodNames) {
     SetMethodAttributes(self.GetOrCreateSingletonClass(), methodNames, RubyMethodAttributes.Public);
     return self;
 }
开发者ID:yarrow2,项目名称:ironruby,代码行数:5,代码来源:ModuleOps.cs


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