public PersistantValueInfo(IMemberAL storage) { if (!BuildProcs(storage.MemberType, out Creator, out Persistor, out Restorer, ref storage)) { throw new DMError("Type {0} is not supposed to be marked with {2}. Invalid type. Only ValueTypes, strings and classes which implement {1} or {5}. Any combination with {3}<T> and {4}<T> by this types also supported.", storage.MemberType.FullName, typeof(IViewStateSerializable).Name, typeof(PersistantFieldAttribute).Name, typeof(IVariable <>).Name, typeof(ICollection <>).Name, typeof(IIntKeyedDataObject).Name); } Storage = storage; }
public PersistantValueInfo(IMemberAL storage) { if (!BuildProcs(storage.MemberType, out Creator, out Persistor, out Restorer, ref storage)) { throw new DMError(Translations.PersistantValueInfo_PersistantValueInfo_Type__0__is_not_supposed_to_be_marked_with__2___Invalid_type__Only_ValueTypes__strings_and_classes_which_implement__1__or__5___Any_combination_with__3__T__and__4__T__by_this_types_also_supported_, storage.MemberType.FullName, typeof(IViewStateSerializable).Name, typeof(PersistantFieldAttribute).Name, typeof(IVariable <>).Name, typeof(ICollection <>).Name, typeof(IIntKeyedDataObject).Name); } Storage = storage; }
public static IMemberAL GetMember([NotNull] this IMemberAL owner, [NotNull] string memberName) { var t = owner.MemberType; var f = t.GetField(memberName); if (f != null) { return(new ChainAbstraction(owner, f.ToAbstaction())); } var p = t.GetProperty(memberName); if (p != null) { return(new ChainAbstraction(owner, p.ToAbstraction())); } return(null); }
static ControllerParametersUtility() { // compiling controller parameters foreach (var field in typeof(TController).GetFields(BindingFlags.Instance | BindingFlags.SetField | BindingFlags.Public | BindingFlags.NonPublic)) { if (field.HasAtr <ControllerParameterAttribute>()) { IMemberAL al = field.ToAbstaction(); var mt = al.MemberType; if (mt == typeof(int) || mt == typeof(string) || mt.IsEnum) { __ControllerParameters.Add(field.Name, al); } else { throw new DMError("Type {0} cannot be specified for controller parameter", mt.FullName); } } } }
private static bool BuildProcs(Type type, out ConstructorInfo creator, out Func <object, object> persistor, out Func <ConstructorInfo, object, object> restorer, ref IMemberAL storage) { if (type.IsValueType || type == typeof(string)) { persistor = Persist_SimpleValue; restorer = Restore_SimpleValue; creator = null; return(true); } bool isViewStateSerializable = false, isTypedVariable = false, isTypedCollection = false, isIntKeyedDataObject = false; foreach (var intf in type.GetInterfaces().Append(type)) { if (typeof(IViewStateSerializable).IsAssignableFrom(type)) { isViewStateSerializable = true; } if (typeof(IIntKeyedDataObject).IsAssignableFrom(type)) { isIntKeyedDataObject = true; } if (intf.IsGenericType) { var gIntf = intf.GetGenericTypeDefinition(); if (gIntf == typeof(IVariable <>)) { isTypedVariable = true; } if (gIntf == typeof(ICollection <>)) { isTypedCollection = true; } } } if (isIntKeyedDataObject) { persistor = Persist_IntKeyedDataObject; restorer = Restore_IntKeyedDataObject; creator = SafeGetConstructor(type); return(true); } if (isViewStateSerializable) { persistor = Persist_IViewStateSerializable; restorer = Restore_IViewStateSerializable; creator = SafeGetConstructor(type); return(true); } if (isTypedVariable) { storage = storage.GetMember("Value"); if (BuildProcs(storage.MemberType, out creator, out persistor, out restorer, ref storage)) { return(true); } } if (isTypedCollection) { var subType = type.GetGenericArguments()[0]; ConstructorInfo c; Func <object, object> p; Func <ConstructorInfo, object, object> r; if (BuildProcs(subType, out c, out p, out r, ref storage)) { creator = SafeGetConstructor(type); var man = (IPersistManager)typeof(TypedCollectionValueInfo <>).MakeGenericType(new[] { subType }).GetConstructor(TYPED_COLLECTION_VALUE_INFO_CONSTRUCTOR_PARAMETERS) .Invoke(new object[] { creator, c, p, r }); persistor = man.Persist; restorer = man.Restore; return(true); } } persistor = null; restorer = null; creator = null; return(false); }
public ChainAbstraction(IMemberAL owner, IMemberAL member) { _Owner = owner; _Member = member; }