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


C# Object.AssertCast方法代码示例

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


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

示例1: AfterDeserialize

 public override Object AfterDeserialize(Type t, Object value)
 {
     var bar = value.AssertCast<IBar>();
     if (bar == null) return null;
     bar.Baz = bar.Baz ?? "null";
     return bar;
 }
开发者ID:xeno-by,项目名称:xenogears,代码行数:7,代码来源:JsonTests.cs

示例2: Json

        public Json(Object value, MemberInfo descriptor)
        {
            if (value == null && descriptor == null) return;
            var mi = descriptor ?? (value == null ? null : value.GetType());
            var pi = mi as PropertyInfo;
            var t = mi is Type ? (Type)mi : (value == null ? null : value.GetType());

            pi.Config().Validators.ForEach(validator => validator.Validate(pi, value));
            t.Config().Validators.ForEach(validator => validator.Validate(t, value));
            // todo. after BeforeSerialize value might have become undesirably changed in-place!
            // how do we revert such changes and hydrate the object back to life?!
            value = pi.Config().Adapters.Fold(value, (curr, adapter) => adapter.BeforeSerialize(pi, curr));
            value = t.Config().Adapters.Fold(value, (curr, adapter) => adapter.BeforeSerialize(t, curr));

            if (value == null)
            {
                _my_state = State.Primitive;
                _my_primitive = null;
            }
            else if (value is Json)
            {
                _wrappee = value.AssertCast<Json>();
            }
            else
            {
                var engine = pi.Config().Engine ?? t.Config().Engine ?? (Engine)new DefaultEngine();
                if (engine is TypeEngine && !(mi is Type)) mi = mi.Type();
                _wrappee = engine.Serialize(mi, value);
            }
        }
开发者ID:xeno-by,项目名称:xenogears,代码行数:30,代码来源:Json.Serialize.cs

示例3: GetData

        public override void GetData(Object target, Stream outgoingData)
        {
            var curr = target.AssertCast<IImmutableHierarchy>();
            var root = curr.Hierarchy().Last();

            var map = new Dictionary<IImmutableHierarchy, HierarchyNode>();
            root.Family().ForEach(node =>
            {
                var m_node = new HierarchyNode();
                map.Add(node, m_node);

                var m_parent = node.Parent == null ? null : map[node.Parent];
                if (m_parent != null)
                {
                    m_node.Parent = m_parent;
                    m_parent.Children.Add(m_node);
                }
            });

            var model = new HierarchyModel(map[root], map[curr]);
            new BinaryFormatter().Serialize(outgoingData, model);
        }
开发者ID:xeno-by,项目名称:xenogears,代码行数:22,代码来源:HierarchySource.cs

示例4: BeforeSerialize

 public override Object BeforeSerialize(PropertyInfo pi, Object value)
 {
     var s_value = value.AssertCast<String>();
     return s_value == null ? null : Convert.ToBase64String(Encoding.UTF8.GetBytes(s_value));
 }
开发者ID:xeno-by,项目名称:xenogears,代码行数:5,代码来源:Password.cs

示例5: AfterDeserialize

 public override Object AfterDeserialize(PropertyInfo pi, Object value)
 {
     var s_value = value.AssertCast<String>();
     return s_value == null ? null : Encoding.UTF8.GetString(Convert.FromBase64String(s_value));
 }
开发者ID:xeno-by,项目名称:xenogears,代码行数:5,代码来源:Password.cs

示例6: Validate

 public override void Validate(PropertyInfo pi, Object value)
 {
     var s_value = value.AssertCast<String>();
     s_value.AssertMatch(Pattern);
 }
开发者ID:xeno-by,项目名称:xenogears,代码行数:5,代码来源:Regex.cs

示例7: Serialize

        public override Json Serialize(Type t, Object obj)
        {
            if (obj == null) return new Json(null);
            if (t.IsNullable()) return Json.Serialize(obj.UndecorateNullable(), t.UndecorateNullable());
            if (t == typeof(DateTime)) return new Json(obj.AssertCast<DateTime>().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffZ"));

            var cfg = t.Config().DefaultEngine().Config;
            if (cfg.IsPrimitive)
            {
                if (t.IsJsonPrimitive())
                {
                    return new JsonPrimitive(obj);
                }
                else
                {
                    t.SupportsSerializationToString().AssertTrue();
                    return new JsonPrimitive(obj.ToInvariantString());
                }
            }
            else
            {
                if (cfg.IsHash)
                {
                    var cast = typeof(EnumerableExtensions).GetMethod("Cast", BF.PublicStatic).AssertNotNull();
                    cast = cast.XMakeGenericMethod(typeof(String), typeof(Object));
                    var hash = (IDictionary<String, Object>)cast.Invoke(null, new[]{obj});

                    var json = new JsonObject();
                    hash.ForEach(kvp =>
                    {
                        var key = kvp.Key;
                        var value = Json.Serialize(kvp.Value);
                        json.Add(key, value);
                    });

                    return json;
                }
                else if (cfg.IsList)
                {
                    var list = ((IEnumerable)obj).Cast<Object>();

                    var json = new JsonArray();
                    list.ForEach(value =>
                    {
                        var j_value = Json.Serialize(value);
                        json.Add(j_value);
                    });

                    return json;
                }
                else if (cfg.IsObject)
                {
                    var json = new JsonObject();

                    cfg.Slots.Where(mi => mi.CanRead()).ForEach(mi =>
                    {
                        var a_include = mi.AttrOrNull<JsonIncludeAttribute>();
                        var a_key = a_include == null ? null : a_include.Name;
                        var key = a_key ?? (cfg.LowercaseSlotNames ? mi.Name.ToLower() : mi.Name);
                        var value = mi.GetValue(obj);
                        var j_value = Json.Serialize(value, mi);
                        json.Add(key, j_value);
                    });

                    return json;
                }
                else
                {
                    throw AssertionHelper.Fail();
                }
            }
        }
开发者ID:xeno-by,项目名称:xenogears,代码行数:72,代码来源:DefaultEngine.cs

示例8: GetData

 public override void GetData(Object target, Stream outgoingData)
 {
     var debugView = target.AssertCast<Node.INodeDebugView>();
     base.GetData(debugView.Node.AssertNotNull(), outgoingData);
 }
开发者ID:xeno-by,项目名称:truesight-lite,代码行数:5,代码来源:NodeVisualizers.cs

示例9: GetData

 public override void GetData(Object target, Stream outgoingData)
 {
     var cfg = target.AssertCast<BaseControlFlowGraph>();
     new BinaryFormatter().Serialize(outgoingData, cfg.DumpAsText());
 }
开发者ID:xeno-by,项目名称:truesight-lite,代码行数:5,代码来源:GraphSource.cs


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