本文整理汇总了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);
}
}
示例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;
}
示例3: ConstructYamlMap
public static Hash ConstructYamlMap(IConstructor ctor, Node node) {
return ctor.ConstructMapping(node);
}
示例4: ConstructYamlSet
public static ICollection ConstructYamlSet(IConstructor ctor, Node node) {
return ctor.ConstructMapping(node).Keys;
}
示例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;
}
示例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");
}
}