private static void SerializeEnumerable(JsonWriter writer, object obj, Type valueType, ISurrogateContext context) { var isArray = valueType.IsArray; if (isArray) { var length = (obj as Array).Length; writer.WritePropertyName("__isArray"); writer.WriteValue(isArray); writer.WritePropertyName("__arrayLength"); writer.WriteValue(length); writer.WritePropertyName("__elementType"); string elementTypeName = SurrogatesDirectory.TypeToContractedString(valueType.GetElementType()); writer.WriteValue(elementTypeName); } writer.WritePropertyName("__arr"); var array = obj as IEnumerable; writer.WriteStartArray(); foreach (object item in array) { var prop = item.GetType(); WriteValueAux(writer, item, prop, context); } writer.WriteEndArray(); }
/// <summary> /// Iterates on the dependencies queue expanding all calculated dependendies inside /// this same queue /// </summary> /// <param name="queue"></param> private void ExpandDependencies(DependenciesQueue queue) { //Process all generated dependencies. while (queue.PendingCount != 0) { var resolutionInfo = queue.Pop(); var objectValue = resolutionInfo.value; var dependencyValues = SurrogatesDirectory.GetObjectDependencies(objectValue, _stateManager, _stateManager.surrogateManager, this); foreach (var dependencyValue in dependencyValues) { if (dependencyValue != null) { DependencyResolutionInfo resolutionInfoForDependency; if (!queue.TryGetValue(dependencyValue, out resolutionInfoForDependency)) { queue.Add(dependencyValue, resolutionInfoForDependency = new DependencyResolutionInfo()); } queue.RegisterParentDependency(new DependencyParentInfo() { child = resolutionInfoForDependency, ParentValue = objectValue, ParentSurrogate = resolutionInfo.ResolvedSurrogate }); } else { queue.RegisterParentDependency(new DependencyParentInfo() { child = null, ParentValue = objectValue, ParentSurrogate = resolutionInfo.ResolvedSurrogate }); } } } }
public static void RegisterSurrogateForXmlNode() { string signature = SurrogatesDirectory.ValidSignature("XMLNODE"); SurrogatesDirectory.RegisterSurrogate(signature: signature, supportedType: typeof(System.Xml.XmlNode), calculateDependencies: new SurrogateDependencyCalculation[] { CalculateXmlNodeDependencies }, serializeEx: SerializeXmlNode, deserializeEx: DeSerializeXmlNode); }
public void Initialize(IStateManager stateManager, IReferenceManager referenceManager, ISurrogateManager surrogateManager) { this.stateManager = stateManager; this.referenceManager = referenceManager; this.surrogateManager = surrogateManager; var tkey = typeof(TKey); var tvalue = typeof(TValue); var tkeyIsValueTypeOrStringOrTypeNotStruct = IsValueTypeOrStringOrTypeNotStruct(tkey); var tvalueIsValueTypeOrString = IsValueTypeOrStringOrType(tvalue); if (tkeyIsValueTypeOrStringOrTypeNotStruct && tvalueIsValueTypeOrString) { implementation = new DictCase1 <TKey, TValue>(); CaseType = 1; } else if (tkeyIsValueTypeOrStringOrTypeNotStruct && (typeof(IStateObject).IsAssignableFrom(tvalue) || TypeCacheUtils.IsIListOrIDictionary(tvalue)) ) { implementation = new DictCase2 <TKey, TValue>(stateManager, referenceManager); ((DictCase2 <TKey, TValue>)implementation).SetParent(this); CaseType = 2; } else if (tkeyIsValueTypeOrStringOrTypeNotStruct && typeof(Delegate).IsAssignableFrom(tvalue)) { implementation = new DictCase5 <TKey, TValue>(stateManager, surrogateManager); CaseType = 5; } else if (typeof(IStateObject).IsAssignableFrom(tkey) && tvalueIsValueTypeOrString) { implementation = new DictCase3 <TKey, TValue>(); CaseType = 3; } else if (typeof(IStateObject).IsAssignableFrom(tkey) && (typeof(IStateObject).IsAssignableFrom(tvalue) || TypeCacheUtils.IsIListOrIDictionary(tvalue)) ) { implementation = new DictCase4 <TKey, TValue>(); CaseType = 4; } else if (tkeyIsValueTypeOrStringOrTypeNotStruct && SurrogatesDirectory.IsSurrogateRegistered(tvalue)) { implementation = new DictCase6 <TKey, TValue>(stateManager, surrogateManager, referenceManager); ((DictCase6 <TKey, TValue>)implementation).SetParent(this); CaseType = 6; } else { throw new NotSupportedException(); } }
public static void RegisterSurrogate() { string signature = SurrogatesDirectory.ValidSignature("SLIST"); SurrogatesDirectory.RegisterSurrogate( signature: signature, supportedType: typeof(System.Collections.SortedList), applyBindingAction: null, serializeEx: Serialize, deserializeEx: Deserialize); }
public SerializerMethods(JsonReader reader, Type keyType, Type valueType) { this.reader = reader; this.keyType = keyType; this.valueType = valueType; //First assign delegate depending on keyType if (typeof(string) == keyType) { ReadKeyMethod = ReadInputAsString; } else if (typeof(Type) == keyType) { ReadKeyMethod = ReadInputAsType; } else if (typeof(IStateObject).IsAssignableFrom(keyType)) { ReadKeyMethod = ReadInputAsStateObject; } else if (keyType.IsEnum) { ReadKeyMethod = ReadInputAsEnum; } else { ReadKeyMethod = ReadInputAsOther; } //Second assign delegate depending on valueType if (typeof(string) == valueType) { ReadValueMethod = ReadInputAsString; } else if (typeof(Type) == valueType) { ReadValueMethod = ReadInputAsType; } else if (valueType.IsEnum) { ReadValueMethod = ReadInputValueAsEnum; } else if (typeof(IStateObject).IsAssignableFrom(valueType) || TypeCacheUtils.IsIListOrIDictionary(valueType) || typeof(Delegate).IsAssignableFrom(valueType) || SurrogatesDirectory.IsSurrogateRegistered(valueType)) { ReadValueMethod = ReadInputAsStateObject; } else { ReadValueMethod = ReadInputValueAsOther; } }
private static void RegisterSurrogateForAdoRecordSetHelper() { string signatureAdoRecordSetHelper = SurrogatesDirectory.ValidSignature("ADORS"); SurrogatesDirectory.RegisterSurrogate(signatureAdoRecordSetHelper, typeof(ADORecordSetHelper), serializeEx: Serialize, deserializeEx: Deserialize, applyBindingAction: ApplyBindingAction, calculateDependencies: new SurrogateDependencyCalculation[] { CalculateDependencies }, PropertyGetter: PropertyGetter, PropertySetter: PropertySetter); }
public static void RegisterSurrogateForDataRowView() { constructorDataViewRow = typeof(DataRowView).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(DataView), typeof(DataRow) }, null); string signature = SurrogatesDirectory.ValidSignature("DRVIEW"); SurrogatesDirectory.RegisterSurrogate( signature: signature, supportedType: typeof(System.Data.DataRowView), serializeEx: SerializeDataRowView, deserializeEx: DeserializeDataRowView, calculateDependencies: new SurrogateDependencyCalculation[] { CalculateDataRowViewDependencies }); }
public static void RegisterSurrogateForDataRow() { signature = SurrogatesDirectory.ValidSignature("DROW"); SurrogatesDirectory.RegisterSurrogate( signature: signature, supportedType: typeof(System.Data.DataRow), applyBindingAction: null, serializeEx: SerializeDataRow, deserializeEx: DeserializeDataRow, calculateDependencies: new SurrogateDependencyCalculation[] { CalculateDataTableDependency } ); }
public static void RegisterSurrogateForDataset() { Debug.WriteLine("Registering surrogate for DATASET"); string signatureDataSet = SurrogatesDirectory.ValidSignature("DATASET"); SurrogatesDirectory.RegisterSurrogate( signature: signatureDataSet, supportedType: typeof(DataSet), serializeEx: SerializeDataSet, deserializeEx: DeserializeDataSet, calculateDependencies: new SurrogateDependencyCalculation[] { (obj, dependenciesContext) => NODATASET_DEPENDENCIES }); }
/// <summary> /// Method to register a surrogate in order to save the State of the method being executed. /// </summary> /// <param name="codePromiseType"></param> /// <param name="target"></param> /// <returns></returns> internal static void RegisterSurrogateForDisplayClass(Type codePromiseType, object target, string parentSurrogateId = null) { //Lets register the surrogate only if it's not already registered. if (!SurrogatesDirectory.IsSurrogateRegistered(codePromiseType)) { var signature = SurrogatesDirectory.GenerateNewSurrogateFromType(codePromiseType); var surrogateForDisplayClass = new SurrogateForDisplayClass(codePromiseType, signature); SurrogatesDirectory.RegisterSurrogate( signature: signature, supportedType: codePromiseType, serializeEx: surrogateForDisplayClass.Serialize, deserializeEx: surrogateForDisplayClass.Deserialize, calculateDependencies: new SurrogateDependencyCalculation[] { surrogateForDisplayClass.CalculateDependencies }); } }
public void SaveSurrogate(StateObjectSurrogate surrogate) { //Save surrogate header var surrogateContext = StateManager.Current.surrogateManager.GetSurrogateContext(surrogate.UniqueID, surrogate); var raw = SurrogatesDirectory.ObjectToRaw(surrogate, surrogateContext); SaveRaw(surrogate.UniqueID, raw); //Save surrogate value var uid = UniqueIDGenerator.GetRelativeUniqueID(surrogate, StateObjectSurrogate.VALUE_PREFIX); surrogateContext = StateManager.Current.surrogateManager.GetSurrogateContext(uid, surrogate.Value); raw = SurrogatesDirectory.ObjectToRaw(surrogate.Value, surrogateContext); SaveRaw(uid, raw); }
public static void RegisterSurrogateForCommand() { Debug.WriteLine("Registering surrogate for DbCommand"); var signature = SurrogatesDirectory.ValidSignature("cmd"); SurrogatesDirectory.RegisterSurrogate( signature: signature, supportedType: typeof(System.Data.Common.DbCommand), applyBindingAction: null, serializeEx: Serialize, deserializeEx: Deserialize, calculateDependencies: new SurrogateDependencyCalculation[] { CalculateDependencies }); Debug.WriteLine("Registering surrogate for OleDbCommand"); signature = SurrogatesDirectory.ValidSignature("cmd1"); SurrogatesDirectory.RegisterSurrogate( signature: signature, supportedType: typeof(System.Data.OleDb.OleDbCommand), applyBindingAction: null, serializeEx: Serialize, deserializeEx: Deserialize, calculateDependencies: new SurrogateDependencyCalculation[] { CalculateDependencies } ); Debug.WriteLine("Registering surrogate for OdbcCommand"); signature = SurrogatesDirectory.ValidSignature("cmd2"); SurrogatesDirectory.RegisterSurrogate( signature: signature, supportedType: typeof(System.Data.Odbc.OdbcCommand), applyBindingAction: null, serializeEx: Serialize, deserializeEx: Deserialize, calculateDependencies: new SurrogateDependencyCalculation[] { CalculateDependencies } ); signature = SurrogatesDirectory.ValidSignature("cmd3"); Debug.WriteLine("Registering surrogate for SqlCommand"); SurrogatesDirectory.RegisterSurrogate( signature: signature, supportedType: typeof(System.Data.SqlClient.SqlCommand), applyBindingAction: null, serializeEx: Serialize, deserializeEx: Deserialize, calculateDependencies: new SurrogateDependencyCalculation[] { CalculateDependencies } ); }
public static void RegisterSurrogateForDataTable() { string signature = SurrogatesDirectory.ValidSignature("DTABLE"); SurrogatesDirectory.RegisterSurrogate( signature: signature, supportedType: typeof(System.Data.DataTable), applyBindingAction: null, calculateDependencies: CalculateDependencies, writeComparer: ExtractDependencyIdentifier, serializeEx: SerializeDataTable, deserializeEx: DeserializeDataTable, isValidDependency: IsValidDependency ); }
public void SaveSurrogate(StateObjectSurrogate surrogate) { //Saving surrogate header var surrogatecontext = _surrogateManager.GetSurrogateContext(surrogate.UniqueID, surrogate); var raw = SurrogatesDirectory.ObjectToRaw(surrogate, surrogatecontext); SaveRaw(surrogate.UniqueID, raw); //Saving surrogateValue if (surrogate.ShouldSerializeValue) { var uid = UniqueIDGenerator.GetRelativeUniqueID(surrogate, StateObjectSurrogate.VALUE_PREFIX); surrogatecontext = _surrogateManager.GetSurrogateContext(uid, surrogate.Value); raw = SurrogatesDirectory.ObjectToRaw(surrogate.Value, surrogatecontext); SaveRaw(uid, raw); } }
internal static void ProcessSetterSimpleTypes(PropertyInfoEx propEx, object parentObject, object newObjectValue, bool isNew = false) { if (isNew) { return; } string propName = propEx.prop.Name; var parentInstance = (IStateObject)parentObject; var tracker = StateManager.Current.Tracker; // Delta Tracking of modified property if (!tracker.IsDirtyModel(parentInstance)) { tracker.MarkAsModified(parentInstance, propEx.propertyPositionIndex); } var stateManager = StateManager.Current; if (!stateManager.flagInBind) { var bindinguid = UniqueIDGenerator.GetRelativeUniqueID(parentInstance, propName + StateManager.BindingKey); var bindingPointer = StateManager.Current.GetObject(bindinguid) as StateObjectPointer; if (bindingPointer != null) { var bindingSurrogate = bindingPointer.Target as StateObjectSurrogate; if (bindingSurrogate != null) { var binding = bindingSurrogate.Value as DataBinding; if (binding != null) { var dataSource = binding.DataSourceReference; if (dataSource is StateObjectSurrogate) { var surrogate = (StateObjectSurrogate)dataSource; var surrogateValue = surrogate.Value; var setter = SurrogatesDirectory.GetPropertySetter(surrogate.Value); setter(surrogateValue, binding.DataSourceProperty, newObjectValue); } else { throw new NotImplementedException(); } } } } } }
public SerializerMethods(JsonWriter writer, Type keyType, Type valueType) { this.writer = writer; this.keyType = keyType; this.valueType = valueType; //First assign delegate depending on keyType if (typeof(string) == keyType) { WriteKeyMethod = WriteKeyGeneric; } else if (typeof(Type) == keyType) { WriteKeyMethod = WriteKeyType; } else if (typeof(IStateObject).IsAssignableFrom(keyType)) { WriteKeyMethod = WriteKeyStateObject; } else { WriteKeyMethod = WriteKeyGeneric; } //Second assign delegate depending on valueType if (typeof(string) == valueType) { WriteValueMethod = WriteValueGeneric; } else if (typeof(Type) == valueType) { WriteValueMethod = WriteValueType; } else if (typeof(IStateObject).IsAssignableFrom(valueType) || TypeCacheUtils.IsIListOrIDictionary(valueType) || typeof(Delegate).IsAssignableFrom(valueType) || SurrogatesDirectory.IsSurrogateRegistered(valueType)) { WriteValueMethod = WriteValueStateObject; } else { WriteValueMethod = WriteValueGeneric; } }
public static void RegisterForAssembly() { Debug.WriteLine("Registering surrogate for Assembly"); var signature = SurrogatesDirectory.ValidSignature("asse1"); SurrogatesDirectory.RegisterSurrogate( signature: signature, supportedType: typeof(System.Reflection.Assembly), applyBindingAction: null, serializeEx: Serialize, deserializeEx: Deserialize ); var runtimeAssembly = Type.GetType("System.Reflection.RuntimeAssembly"); Debug.WriteLine("Registering surrogate for RuntimeAssembly"); signature = SurrogatesDirectory.ValidSignature("asse2"); SurrogatesDirectory.RegisterSurrogate(signature: signature, supportedType: runtimeAssembly, serializeEx: Serialize, deserializeEx: Deserialize); }
public static IList <object> CalculateDependencies(object value, ISurrogateDependenciesContext dependenciesContext) { var fldArr = GetFieldInfosIncludingBaseClasses(value.GetType(), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); var res = new object[fldArr.Count]; for (int i = 0; i < res.Length; i++) { var currentField = fldArr[i]; if (typeof(IStateObject).IsAssignableFrom(currentField.FieldType)) { res[i] = currentField.GetValue(value); } else if (currentField.FieldType.IsSerializable && typeof(MulticastDelegate).IsAssignableFrom(currentField.FieldType)) { //Skip do no support delegate fields } else if (SurrogatesDirectory.IsSurrogateRegistered(currentField.FieldType)) { res[i] = currentField.GetValue(value); } } return(res); }
static Func <object[], IIocContainerFlags, T> DetermineStrategy() { var type = typeof(T); if (typeof(ILogic).IsAssignableFrom(type)) { return((object[] parameters, IIocContainerFlags flags) => _current.ResolveNonSinglentonLogic <T>(parameters, flags)); } if (typeof(IStateObject).IsAssignableFrom(type)) { return((object[] parameters, IIocContainerFlags flags) => _current.ResolveNonSinglentonIStateObject <T>(parameters, flags)); } if (typeof(T).IsGenericType) { if (typeof(T).GetGenericTypeDefinition() == typeof(IList <>)) { var listType = typeof(VirtualList <>).MakeGenericType(typeof(T).GetGenericArguments()); var func = Expression.Lambda <Func <object> >(Expression.Convert(Expression.New(listType), typeof(object))).Compile(); return((object[] parameters, IIocContainerFlags flags) => (T)_current.ResolveList(listType, func, parameters, flags)); } if (typeof(T).GetGenericTypeDefinition() == typeof(IDictionary <,>)) { var dictionaryType = typeof(ObservableDictionaryEx <,>).MakeGenericType(typeof(T).GetGenericArguments()); var func = Expression.Lambda <Func <object> >(Expression.Convert(Expression.New(dictionaryType), typeof(object))).Compile(); return((object[] parameters, IIocContainerFlags flags) => (T)_current.ResolveDictionary(dictionaryType, func, parameters, flags)); } } if (SurrogatesDirectory.IsSurrogateRegistered(typeof(T))) { return((object[] parameters, IIocContainerFlags flags) => _current.ResolveSurrogate <T>(parameters)); } if (typeof(T).GetCustomAttributes(typeof(Singleton), false).Length > 0) { return((object[] parameters, IIocContainerFlags flags) => _current.ResolveSinglenton <T>(parameters, flags)); } return((object[] parameters, IIocContainerFlags flags) => (T)_current.ResolveReduced(typeof(T), parameters, flags)); }
public string GetUniqueIdForSurrogate(object obj, string parentUniqueId = null, bool generateIfNotFound = true) { return(SurrogatesDirectory.GetUniqueIDForSurrogateDelegate(obj, parentUniqueId, generateIfNotFound)); }
private static void LoadTable(Type type) { lock (cachePropertiesEx) { if (cachePropertiesEx.ContainsKey(type)) { return; } PropertiesExDictionary properties; var ancestorProperties = GetAncestorProperties(type); properties = ancestorProperties != null ? new PropertiesExDictionary(ancestorProperties) : new PropertiesExDictionary(); //Use to asign a IndexParameter field when don't have index parameters for the property int numberOfParentProperties = 0; if (ALIAS_ENABLED) { //Determine how many properties the parent has var baseType = type.BaseType; while (baseType != null) { numberOfParentProperties += baseType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Count(); baseType = baseType.BaseType; } } //short i = 0; var aliasIndex = numberOfParentProperties; //TODO: should we exclude properties here? like non-virtual or stateobject false? var assemblyAttribute = (StateManagementDefaultValue)type.Assembly.GetCustomAttribute(typeof(StateManagementDefaultValue)); var typeName = type.Name; bool flag = false; foreach (PropertyInfo prop in type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { var propName = prop.Name; string propertyAlias = aliasIndex.ToBase48ToString(); aliasIndex++; var typeAttribute = (StateManagementDefaultValue)Attribute.GetCustomAttribute(prop.DeclaringType, typeof(StateManagementDefaultValue), false); var attr = (StateManagement)prop.GetCustomAttributes(typeof(StateManagement), true).FirstOrDefault(); if (attr != null && !attr.RequiresStateManagement()) { properties.RemoveProperty(propName); continue; } bool isStrongReference = false; bool isWeakReference = false; bool onlyHasGetter = false; bool isAssignableFromIModel; bool isAssignableFromITopLevelStateObject; bool isAssignableFromIViewManager; bool isAssignableFromIIocContainer; bool isAssignableFromILogicWithViewModel_IViewModel; bool isVisibleStateFlag = false; bool hasIndexParameters = false; bool isAssignableFromIDependantViewModel = false; //if (HasNoGetter(prop)) //{ // //It will not be added to the list of propertyInfoEx // continue; //} //else if (HasNoSetter(prop)) //{ // //It will not added to the list of propertyInfoEx but we will keep the flag // if (attr == null) // attr = new StateManagement(StateManagementValues.ClientOnly); // onlyHasGetter = true; //} /*if (!prop.CanRead) * { * attr = new StateManagement(StateManagementValues.None); * }*/ //We should exclude ViewManager and Container if ((propName == "ViewManager" && prop.PropertyType == typeof(IViewManager)) || (propName == "Container" && prop.PropertyType == typeof(IIocContainer))) { continue; } var isStateObject = typeof(IStateObject).IsAssignableFrom(prop.PropertyType); var propertyType = prop.PropertyType; var propertyInfoEx = new PropertyInfoEx(); propertyInfoEx.OnlyHasGetter = onlyHasGetter; if (ALIAS_ENABLED) { var aliasAttribute = (StateManagementAlias)prop.GetCustomAttributes(typeof(StateManagementAlias), true).FirstOrDefault(); if (aliasAttribute != null) { propertyInfoEx.alias = aliasAttribute.Value; } else { propertyInfoEx.alias = propertyAlias; } } propertyInfoEx.prop = prop; propertyInfoEx.hasSurrogate = SurrogatesDirectory.IsSurrogateRegistered(propertyType); var attrRef = prop.GetCustomAttributes(typeof(Reference), true).FirstOrDefault() as Reference; propertyInfoEx.hasReferenceAttribute = attrRef != null; if (propertyInfoEx.hasReferenceAttribute) { isStrongReference = attrRef.Value == ReferenceTypeValues.Strong; isWeakReference = attrRef.Value == ReferenceTypeValues.Weak; } isAssignableFromIModel = typeof(IModel).IsAssignableFrom(propertyType); propertyInfoEx.isAssignableFromIDependantStateObject = typeof(IDependentStateObject).IsAssignableFrom(propertyType); isAssignableFromIDependantViewModel = typeof(IDependentViewModel).IsAssignableFrom(propertyType); isAssignableFromITopLevelStateObject = typeof(ITopLevelStateObject).IsAssignableFrom(propertyType); isAssignableFromIIocContainer = typeof(IIocContainer).IsAssignableFrom(propertyType); isAssignableFromIViewManager = typeof(IViewManager).IsAssignableFrom(propertyType); propertyInfoEx.isAnIDictionary = TypeCacheUtils.IsAnIDictionary(propertyType); propertyInfoEx.isAnIList = TypeCacheUtils.IsAnIList(propertyType); if (prop.Name.Equals("VisibleState", StringComparison.Ordinal) && prop.PropertyType == typeof(VisibleState)) { isVisibleStateFlag = true; } StateManagementValues stateManagementAttribute = StateManagementValues.Both; if (attr != null) { stateManagementAttribute = attr.Value; } else if (typeAttribute != null) { if (!propertyInfoEx.isAnIList && !isAssignableFromIDependantViewModel) { stateManagementAttribute = typeAttribute.Value; } } else if (assemblyAttribute != null) { if (!propertyInfoEx.isAnIList && !isAssignableFromIDependantViewModel) { stateManagementAttribute = assemblyAttribute.Value; } } propertyInfoEx.stateManagementAttribute = stateManagementAttribute; var indexParameters = prop.GetIndexParameters(); hasIndexParameters = (indexParameters != null) && (indexParameters.Length > 0); //propertyInfoEx.propertyPositionIndex = i; propertyInfoEx.mustIgnoreMemberForClient = StateManagementUtils.MustIgnoreMember(true, prop) /*check the statemanagement attribute*/ || TypeCacheUtils.IsExcludedProperty(prop) || propertyInfoEx.hasSurrogate || isAssignableFromIDependantViewModel; // propertyInfoEx.CanRead = prop.CanRead && prop.GetGetMethod(false) != null; // propertyInfoEx.CanWrite = prop.CanWrite && prop.GetGetMethod(false) != null; //Read JsonNet attributes //propertyInfoEx.jsonPropertyAttribute = Attribute.GetCustomAttribute(prop, typeof(Newtonsoft.Json.Serialization.JsonProperty), false); //propertyInfoEx.defaultValueAttribute = Attribute.GetCustomAttribute(prop, typeof(System.ComponentModel.DefaultValueAttribute), false) as System. //Validate if this is an IList of object bool isASupportedValueTypeForIList = false; if (propertyInfoEx.isAnIList && !propertyInfoEx.isAnIList) { //It could be an IList<object>, but it need to have the statemanagement attribute Generict //var collAtt = // (GenericCollectionTypeInfo)prop.GetCustomAttributes(typeof(GenericCollectionTypeInfo), true).FirstOrDefault(); //if (collAtt != null && collAtt.RuntimeType == typeof(IList<IStateObject>)) //{ // propertyInfoEx.isAnIListOfSomethingThatImplementsIStateObject = true; //} //else //{ var listItemType = propertyType.GetGenericArguments()[0]; isASupportedValueTypeForIList = interceptionDelegates.isASupportedValueTypeForIListDelegate(listItemType); TraceUtil.TraceError("invalid IList<object> possible statemanagement issues"); //} } isAssignableFromILogicWithViewModel_IViewModel = typeof(ILogicWithViewModel <IViewModel>).IsAssignableFrom(propertyType); propertyInfoEx.isStateObject = isStateObject; propertyInfoEx.isNonStateObjectFixedType = propertyType.IsValueType || typeof(string) == propertyType || typeof(Type) == propertyType; propertyInfoEx.isObjectPropertyType = typeof(Object) == propertyType; //We Assign the corresponding getter Action if (isStrongReference || propertyInfoEx.isObjectPropertyType) { propertyInfoEx.ProcessGetter = interceptionDelegates.ProcessGetterStrongReference; } else if (isWeakReference) { propertyInfoEx.ProcessGetter = interceptionDelegates.ProcessGetterWeakReference; } else if (propertyInfoEx.hasSurrogate) { propertyInfoEx.ProcessGetter = interceptionDelegates.ProcessGetterSurrogate; } else if (propertyInfoEx.isAssignableFromIDependantStateObject || propertyInfoEx.isAnIList || propertyInfoEx.isAnIDictionary || isASupportedValueTypeForIList) { propertyInfoEx.ProcessGetter = interceptionDelegates.ProcessGetterNonTopLevelIStateObject; } else if (isAssignableFromITopLevelStateObject) { propertyInfoEx.ProcessGetter = interceptionDelegates.ProcessGetterTopLevelIStateObject; } else if (isAssignableFromILogicWithViewModel_IViewModel) { propertyInfoEx.ProcessGetter = interceptionDelegates.ProcessGetterNoAction; } else { propertyInfoEx.ProcessGetter = interceptionDelegates.ProcessGetterNoAction; } //We Assign the corresponding setter Action if (isVisibleStateFlag) { //This is a special process setter for handling property VisibleState of ControlBase or FormBase propertyInfoEx.ProcessSetter = interceptionDelegates.ProcessSetterVisibleState; } else if (propertyInfoEx.isObjectPropertyType) { propertyInfoEx.ProcessSetter = interceptionDelegates.ProcessSetterObjectReference; } else if (propertyInfoEx.hasSurrogate) { propertyInfoEx.ProcessSetter = interceptionDelegates.ProcessSetterSurrogate; } else if (isStrongReference) { propertyInfoEx.ProcessSetter = interceptionDelegates.ProcessSetterStrongReference; } else if (propertyInfoEx.hasReferenceAttribute) { propertyInfoEx.ProcessSetter = interceptionDelegates.ProcessSetterWeakReference; } else if (!propertyInfoEx.hasReferenceAttribute && !propertyInfoEx.hasSurrogate) { if (propertyInfoEx.prop.PropertyType.IsValueType || propertyInfoEx.prop.PropertyType == typeof(string)) { propertyInfoEx.ProcessSetter = interceptionDelegates.ProcessSetterSimpleTypes; } else if (isAssignableFromILogicWithViewModel_IViewModel) { propertyInfoEx.ProcessSetter = interceptionDelegates.ProcessSetterSimpleTypes; } else { if (propertyInfoEx.prop.PropertyType.IsClass && !typeof(IStateObject).IsAssignableFrom(propertyInfoEx.prop.PropertyType)) { propertyInfoEx.ProcessSetter = interceptionDelegates.ProcessSetterSimpleTypes; } else { propertyInfoEx.ProcessSetter = interceptionDelegates.ProcessSetterMostCases; } } } RegisterProperty(propertyInfoEx, properties, hasIndexParameters); #if DEBUG if (ViewModelAnalysis) { if (!typeof(IInternalData).IsAssignableFrom(type)) { if (propertyType.IsInterface && //!propertyInfoEx.isAnIListOfSomethingThatImplementsIStateObject && !isAssignableFromIIocContainer && !isAssignableFromIViewManager && !propertyInfoEx.isAssignableFromIDependantStateObject && !(propertyInfoEx.isAnIList && isASupportedValueTypeForIList) && !isAssignableFromIModel && !typeof(IViewModel).IsAssignableFrom(propertyType)) { var improperType = type; if (improperType.Assembly.IsDynamic) { improperType = improperType.BaseType; } Dictionary <string, Type> improperTypeTable; if (!ImproperTypes.TryGetValue(improperType, out improperTypeTable)) { ImproperTypes[improperType] = improperTypeTable = new Dictionary <string, Type>(); } improperTypeTable[prop.Name] = propertyType; } else if (propertyType == typeof(object) && !propertyInfoEx.hasReferenceAttribute) { var warningType = type; if (warningType.Assembly.IsDynamic) { warningType = warningType.BaseType; } Dictionary <string, Type> warningTypeTable; if (!WarningTypes.TryGetValue(warningType, out warningTypeTable)) { WarningTypes[warningType] = warningTypeTable = new Dictionary <string, Type>(); } warningTypeTable[prop.Name] = propertyType; } } } #endif } ////for loop is faster, but cannot iterate on the dictionary //foreach (var item in properties) //{ // tuple2.Add(item.Key, item.Value.propertyPositionIndex); // bitArrayMappedTable[item.Value.propertyPositionIndex] = item.Value; //} //cache with position properties.PropertiesList = properties.PropertiesList.ToArray(); cachePropertiesEx.Add(type, properties); } }
public bool IsSurrogateRegistered(Type supportedType) { return(SurrogatesDirectory.IsSurrogateRegistered(supportedType)); }
public Action <object, string, object> GetPropertySetter(object obj) { return(SurrogatesDirectory.GetPropertySetter(obj)); }
public void ApplyBindingHandlers(object surrogateValue, Action <bool> bindingAction) { SurrogatesDirectory.ApplyBindingHandlers(surrogateValue, bindingAction); }
public Func <object, string, object> GetPropertyGetter(object obj) { return(SurrogatesDirectory.GetPropertyGetter(obj)); }
public string ValidSignature(string signature) { return(SurrogatesDirectory.ValidSignature(signature)); }
public object RestoreSurrogate(string uniqueId) { return(SurrogatesDirectory.RestoreSurrogate(uniqueId)); }
public object RawToObject(string surrogateUniqueID, object raw) { var context = this.GetSurrogateContext(surrogateUniqueID); return(SurrogatesDirectory.RawToObject(raw, context)); }
public object ObjectToRaw(string surrogateUniqueID, object obj) { var surrogateContext = GetSurrogateContext(surrogateUniqueID, obj); return(SurrogatesDirectory.ObjectToRaw(obj, surrogateContext)); }