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


C# IConstructor.ConstructMapping方法代码示例

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


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

示例1: ConstructCliObject

        public static object ConstructCliObject(IConstructor ctor, string pref, Node node) {
            // TODO: should this use serialization or some more standard CLR mechanism?
            //       (it is very ad-hoc)
            // TODO: use DLR APIs instead of reflection
            try {
                Type type = Type.GetType(pref);
                object result = type.GetConstructor(Type.EmptyTypes).Invoke(null);

                foreach (KeyValuePair<object, object> e in ctor.ConstructMapping(node)) {
                    string name = e.Key.ToString();
                    name = "" + char.ToUpper(name[0]) + name.Substring(1);
                    PropertyInfo prop = type.GetProperty(name);

                    prop.SetValue(result, Convert.ChangeType(e.Value, prop.PropertyType), null);
                }
                return result;

            } catch (Exception e) {
                throw new ConstructorException("Can't construct a CLI object from class: " + pref, e);
            }
        }
开发者ID:bclubb,项目名称:ironruby,代码行数:21,代码来源:SafeConstructor.cs

示例2: ConstructSpecializedMap

 public static object ConstructSpecializedMap(IConstructor ctor, string pref, Node node) {
     Hash result = null;
     try {
         result = (Hash)Type.GetType(pref).GetConstructor(Type.EmptyTypes).Invoke(null);
     } catch (Exception e) {
         throw new ConstructorException("Can't construct a mapping from class: " + pref, e);
     }
     foreach (KeyValuePair<object, object> e in ctor.ConstructMapping(node)) {
         result.Add(e.Key, e.Value);
     }
     return result;
 }
开发者ID:bclubb,项目名称:ironruby,代码行数:12,代码来源:SafeConstructor.cs

示例3: ConstructYamlMap

 public static Hash ConstructYamlMap(IConstructor ctor, Node node) {
     return ctor.ConstructMapping(node);
 }        
开发者ID:bclubb,项目名称:ironruby,代码行数:3,代码来源:SafeConstructor.cs

示例4: ConstructYamlSet

 public static ICollection ConstructYamlSet(IConstructor ctor, Node node) {
     return ctor.ConstructMapping(node).Keys;
 }
开发者ID:bclubb,项目名称:ironruby,代码行数:3,代码来源:SafeConstructor.cs

示例5: ConstructRubyStruct

        public static object ConstructRubyStruct(IConstructor ctor, string className, Node node) {
            MappingNode mapping = node as MappingNode;
            if (mapping == null) {
                throw new ConstructorException("can only construct struct from mapping node");
            }

            RubyContext context = ctor.GlobalScope.Context;
            RubyModule module;
            RubyClass cls;
            if (context.TryGetModule(ctor.GlobalScope, className, out module)) {
                cls = module as RubyClass;
                if (cls == null) {
                    throw new ConstructorException("Struct type name must be Ruby class");
                }
            } else {
                RubyModule structModule = context.GetModule(typeof(RubyStruct));
                cls = RubyUtils.GetConstant(ctor.GlobalScope, structModule, className, false) as RubyClass;
                if (cls == null) {
                    throw new ConstructorException(String.Format("Cannot find struct class \"{0}\"", className));
                }
            }

            RubyStruct newStruct = RubyStruct.Create(cls);
            foreach (var pair in ctor.ConstructMapping(mapping)) {
                RubyStructOps.SetValue(newStruct, SymbolTable.StringToId(pair.Key.ToString()), pair.Value);        
            }
            return newStruct;
        }
开发者ID:bclubb,项目名称:ironruby,代码行数:28,代码来源:RubyConstructor.cs

示例6: ConstructPrivateObject

 public static object ConstructPrivateObject(IConstructor ctor, string className, Node node) {
     MappingNode mapping = node as MappingNode;
     if (mapping == null) {
         throw new ConstructorException("can only construct private type from mapping node");
     }
     RubyModule module;
     RubyGlobalScope globalScope = ctor.GlobalScope;
     if (globalScope.Context.TryGetModule(globalScope, className, out module)) {
         if (!module.IsClass) {
             throw new ConstructorException("Cannot construct module");
         }
         Hash values = ctor.ConstructMapping(mapping);
         RubyMethodInfo method = module.GetMethod("yaml_initialize") as RubyMethodInfo;
         if (method != null) {
             object result = RubyUtils.CreateObject((RubyClass)module);
             _YamlInitialize.Target(_YamlInitialize, globalScope.Context, result, className, values);
             return result;
         } else {
             return RubyUtils.CreateObject((RubyClass)module, values, true);
         }
     } else {
         //TODO: YAML::Object
         throw new NotImplementedError("YAML::Object is not implemented yet");
     }
 }
开发者ID:bclubb,项目名称:ironruby,代码行数:25,代码来源:RubyConstructor.cs


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