public WCFObjectBase Clone() { DataContractSerializer contractSerializer = new DataContractSerializer(this.GetType()); Stream stream = (Stream) new MemoryStream(); contractSerializer.WriteObject(stream, (object)this); stream.Seek(0L, SeekOrigin.Begin); WCFObjectBase wcfObjectBase = (WCFObjectBase)contractSerializer.ReadObject(stream); stream.Close(); return(wcfObjectBase); }
public static MetadataAttribute GetMetadata(string fieldExpression) { MetadataAttribute metadataAttribute = (MetadataAttribute)null; if (!string.IsNullOrEmpty(fieldExpression)) { try { string[] strArray1 = fieldExpression.Split('.'); FieldInfo fieldInfo = (FieldInfo)null; if (strArray1.Length > 1) { string str = strArray1[0] + "_Environment"; Type type = Type.GetType(string.Format("Camstar.WCF.ObjectStack.{0}, Camstar.WCFClient", (object)str)); if (type == (Type)null) { throw new WCFServiceException(":" + str + "Type '{0}' doesn`t exist."); } for (int index = 1; index < strArray1.Length; ++index) { string[] strArray2 = strArray1[index].Split(':'); string name = strArray2[0]; if (strArray2.Length > 1) { type = Type.GetType(string.Format("Camstar.WCF.ObjectStack.{0}, Camstar.WCFClient", (object)(strArray2[1] + "_Environment"))); if (type == (Type)null) { throw new WCFServiceException(":" + strArray2[1] + "Type '{0}' doesn`t exist."); } } else { fieldInfo = WCFObjectBase.GetField(type, name); type = fieldInfo.FieldType; } } } if (fieldInfo != (FieldInfo)null) { metadataAttribute = fieldInfo.GetCustomAttributes(typeof(MetadataAttribute), false)[0] as MetadataAttribute; } } catch (WCFServiceException ex) { throw new WCFServiceException(string.Format("Invalid path for '({0}).{1}' expression. {2}", (object)fieldExpression.Substring(0, fieldExpression.IndexOf('.')), (object)fieldExpression.Substring(fieldExpression.IndexOf('.') + 1), (object)ex.Message)); } } return(metadataAttribute); }
protected void PropertySet(string name, object value) { FieldInfo field = WCFObjectBase.GetField(this.GetType(), name); if (field.GetValue((object)this) == value) { return; } field.SetValue((object)this, value); this.NotifyPropertyChanged(name); if (!(value is CDOObject cdoObject)) { return; } cdoObject.PropertyChanged += (PropertyChangedEventHandler)((sender, e) => this.NotifyPropertyChanged(e.PropertyName)); }
private void SetCreateAttribute(WCFObjectBase parent, string fieldName) { Type type = parent.GetType(); FieldInfo field = WCFObjectBase.GetField(type, fieldName); if (!(field != (FieldInfo)null) || !(field.GetValue((object)parent) is CDOObject cdoObject)) { return; } MetadataAttribute customAttribute = WCFObjectBase.GetField(type.Assembly.GetType(type.Namespace + "." + type.Name + "_Environment"), fieldName).GetCustomAttributes(typeof(MetadataAttribute), false)[0] as MetadataAttribute; if (customAttribute.CreateOnInitialize || customAttribute.FieldTypeCode != FieldTypeCode.Object || customAttribute.IsReadOnly) { return; } cdoObject.FieldAction = new Action?(Action.Create); }
private object GetFieldValue(string fieldPath) { Type type = this.GetType(); int length = fieldPath.IndexOf('.'); object obj; if (length == -1) { string name = fieldPath.Split(':')[0]; FieldInfo field = WCFObjectBase.GetField(type, name); obj = field.GetValue((object)this); if (obj != null && field.FieldType.GetInterface(typeof(IPrimitive).Name, false) != (Type)null) { obj = (obj as IPrimitive).GetValue(); } } else { string name = fieldPath.Substring(0, length).Split(':')[0]; FieldInfo field = WCFObjectBase.GetField(type, name); obj = field.GetValue((object)this); if (field.FieldType.IsArray) { obj = obj == null || (obj as Array).Length == 0 ? (object)null : (obj as Array).GetValue(0); if (obj != null) { obj = (obj as WCFObjectBase).GetFieldValue(fieldPath.Substring(length + 1)); } } else if (obj != null) { obj = (obj as WCFObjectBase).GetFieldValue(fieldPath.Substring(length + 1)); } } return(obj); }
public static bool IsNullOrEmpty(this WCFObjectBase obj) { return(obj == null || obj.IsEmpty); }
private void SetFieldValue(string fieldPath, object value, bool replace) { Type type1 = this.GetType(); int length = fieldPath.IndexOf('.'); if (length == -1) { string name = fieldPath.Split(':')[0]; FieldInfo field = WCFObjectBase.GetField(type1, name); if (((field.GetValue((object)this) != null ? 0 : (value != null ? 1 : 0)) | (replace ? 1 : 0)) == 0) { return; } if (field.FieldType.GetInterface(typeof(IPrimitive).Name, true) != (Type)null) { object obj = Activator.CreateInstance(field.FieldType.Assembly.FullName, field.FieldType.FullName).Unwrap(); Type type2 = ((IEnumerable <Type>)field.FieldType.GetGenericArguments()).FirstOrDefault <Type>(); if (type2 != (Type)null && value is string) { value = !type2.IsEnum ? Convert.ChangeType(value, type2, (IFormatProvider)null) : Enum.Parse(type2, value as string, true); } (obj as IPrimitive).SetValue(value); value = obj; } field.SetValue((object)this, value); } else { string[] strArray = fieldPath.Substring(0, length).Split(':'); string str1 = strArray[0]; FieldInfo field = WCFObjectBase.GetField(type1, str1); string str2 = field.FieldType.Name; Type type2 = field.FieldType.GetElementType(); if (strArray.Length > 1) { string str3 = string.Empty; if (field.FieldType.IsSubclassOf(typeof(Info))) { str3 = "_Info"; } if (field.FieldType.IsSubclassOf(typeof(Environment))) { str3 = "_Environment"; } str2 = strArray[1] + str3; Type type3 = field.FieldType.Assembly.GetType(field.FieldType.Namespace + "." + str2); if (type3 == (Type)null) { throw new WCFServiceException(string.Format("Type '{0}' doesn`t exist.", (object)str2)); } type2 = type3; } object obj1 = field.GetValue((object)this); if (field.FieldType.IsArray) { if (obj1 == null || (obj1 as Array).Length == 0) { obj1 = (object)Array.CreateInstance(field.FieldType.GetElementType(), 1); } object obj2 = (obj1 as Array).GetValue(0) ?? Activator.CreateInstance(field.FieldType.Assembly.FullName, type2.FullName).Unwrap(); (obj2 as WCFObjectBase).SetFieldValue(fieldPath.Substring(length + 1), value, replace); (obj1 as Array).SetValue(obj2, 0); } else { if (obj1 == null) { obj1 = Activator.CreateInstance(field.FieldType.Assembly.FullName, field.FieldType.Namespace + "." + str2).Unwrap(); } (obj1 as WCFObjectBase).SetFieldValue(fieldPath.Substring(length + 1), value, replace); } field.SetValue((object)this, obj1); this.SetCreateAttribute(this, str1); } }
protected object PropertyGet(string name) { return(WCFObjectBase.GetField(this.GetType(), name).GetValue((object)this)); }