コード例 #1
0
        public ChildEntity Expose(string name, object obj)
        {
            ChildEntity entity;

            if (!children.TryGetValue(name, out entity))
            {
                entity = new ChildEntity(this, name, obj);

                foreach (FacetRegistration reg in Root.facetRegistrations)
                {
                    IFacet facet;
                    if (reg.TryCreate(entity, out facet))
                    {
                        entity.AddFacet(facet);
                    }
                }

                children.Add(name, entity);
            }
            else if (entity.obj != obj)
            {
                throw new ArgumentException("Attempting to expose different objects under the same name '" + name + "'");
            }
            return(entity);
        }
コード例 #2
0
 public bool TryCreate(ChildEntity obj, out IFacet facet)
 {
     if (objType.IsAssignableFrom(obj.obj.GetType()))
     {
         facet = (IFacet)Activator.CreateInstance(facetType, obj, obj.obj);
         return(true);
     }
     else
     {
         facet = null;
         return(false);
     }
 }
コード例 #3
0
        public bool TryResolve(string name, Dictionary <string, object> payload, out ChildEntity entity)
        {
            if (children.TryGetValue(name, out entity))
            {
                return(true);
            }

            foreach (IFacet facet in facets)
            {
                object obj;
                if (facet.TryResolve(name, payload, out obj))
                {
                    entity = Expose(name, obj);
                    return(true);
                }
            }

            entity = null;
            return(false);
        }