public StoryVar Duplicate() { object val; if (this.Value == null || this.Value.GetType().IsValueType) { val = this.Value; } else { // Service type IVarTypeService service = GetTypeService(this.Value.GetType()); if (service != null) { val = service.Duplicate(this.Value); } // Var type else if (this.Value is IVarType) { val = (this.Value as IVarType).Duplicate(); } val = this.Value; } return(new StoryVar(val)); }
public StoryVar GetMember(StoryVar member) { if (Value == null) { throw new VarTypeMemberException("Cannot get members of an empty story variable."); } if (member.Value == null) { throw new VarTypeMemberException("Cannot treat an empty variable as a member."); } IVarTypeService service = GetTypeService(this.Value.GetType()); if (service != null) { return(service.GetMember(this.Value, member)); } if (this.Value is IVarType) { return(((IVarType)this.Value).GetMember(member)); } throw new VarTypeMemberException(string.Format("Cannot get member of a story variable of type {0}.", this.Value.GetType().Name)); }
public static IVarTypeService GetTypeService(Type t) { IVarTypeService service = null; _typeServices.TryGetValue(t, out service); return(service); }
public static bool TryConvertTo(object obj, Type t, out object result, bool strict) { object val = GetInnerValue(obj); // Source conversion if (val != null) { // Same type if (t.IsAssignableFrom(val.GetType())) { result = val; return(true); } // Service type IVarTypeService service = GetTypeService(val.GetType()); if (service != null && service.ConvertTo(val, t, out result, strict)) { return(true); } // Var type if (val is IVarType) { if ((val as IVarType).ConvertTo(t, out result, strict)) { return(true); } } } // Target converion IVarTypeService targetService = GetTypeService(t); if (targetService != null && targetService.ConvertFrom(val, out result, strict)) { return(true); } result = null; return(false); }
public void RemoveMember(StoryVar member) { if (Value == null) { throw new VarTypeMemberException("Cannot remove member of empty story variable."); } IVarTypeService service = GetTypeService(this.Value.GetType()); if (service != null) { service.RemoveMember(this.Value, member); return; } if (this.Value is IVarType) { ((IVarType)this.Value).RemoveMember(member); return; } throw new VarTypeMemberException(string.Format("Cannot remove member of a story variable of type {0}.", this.Value.GetType().Name)); }
public static void RegisterTypeService <T>(IVarTypeService service) { _typeServices[typeof(T)] = service; }