private static StructInfo GetStructInfo(Type typeClass, Dictionary <string, StructInfo> allStructs, Dictionary <string, EnumInfo> allEnums) { var res = new StructInfo(); res.FullName = typeClass.FullName; res.Name = typeClass.Name; object defaultObject = Activator.CreateInstance(typeClass); PropertyInfo[] properties = typeClass.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (PropertyInfo p in properties) { Type t = p.PropertyType; bool ignore = p.GetCustomAttribute <Ignore>() != null; if (ignore) { continue; } Dimension dim = GetDimensionFromPropertyType(t); if (t.IsGenericType) // Nullable or List { t = t.GetGenericArguments()[0]; } else if (t.IsArray) { t = t.GetElementType(); } DataType type = DataValue.TypeToDataType(t); string typeConstraints = ""; if (type == DataType.Enum || type == DataType.Struct) { typeConstraints = t.FullName; } if (type == DataType.Struct) { if (!allStructs.ContainsKey(t.FullName)) { allStructs[t.FullName] = new StructInfo(); allStructs[t.FullName] = GetStructInfo(t, allStructs, allEnums); } } else if (type == DataType.Enum) { if (!allEnums.ContainsKey(t.FullName)) { allEnums[t.FullName] = GetEnumInfo(t); } } object value = p.GetValue(defaultObject, null); DataValue?defaultValue = null; if (value != null) { defaultValue = DataValue.FromObject(value); } res.Member.Add(new SimpleMember(p.Name, type, typeConstraints, dim, defaultValue, false, "")); } return(res); }
protected override Dictionary <string, DataValue?> Execute(Dictionary <string, DataValue?> inputs) { var s = inputs["s"]; var r = inputs["r"]; if (s.HasValue && r.HasValue && !(s.Value && r.Value)) { if (s.Value) { _out = true; } else if (r.Value) { _out = false; } } else { _out = null; } return(new Dictionary <string, DataValue?>(2) { ["out"] = _out, ["inv"] = _out.HasValue ? !_out.Value : _out }); }
public override bool TryGetValue(out DataValue?value) { var pi = this.Property; if (pi.CanRead) { value = new DataValue(this.Property.GetValue(this.Target)); return(true); } value = default(DataValue); return(false); }
public override bool TryGetValue(out DataValue?value) { var pi = Property; if (pi.CanRead) { value = (DataValue?)pi.GetValue(Target); return(true); } value = default(DataValue); return(false); }
public SimpleMember(string name, DataType type, string typeConstraints, Dimension dimension, DataValue?defaultValue, bool browseable, string category) { if (name == null) { throw new ArgumentNullException(nameof(name), nameof(name) + "may not be null"); } Name = name; Type = type; TypeConstraints = typeConstraints ?? ""; Dimension = dimension; DefaultValue = defaultValue; Browseable = browseable; Category = category; }
public void WriteDataValue(string?fieldName, DataValue?value) { if (value == null) { this.WriteByte(null, 0); return; } byte b = 0; if (!Variant.IsNull(value.Variant)) { b |= 1; } if (value.StatusCode != 0u) { b |= 2; } if (value.SourceTimestamp != DateTime.MinValue) { b |= 4; } if (value.SourcePicoseconds != 0) { b |= 16; } if (value.ServerTimestamp != DateTime.MinValue) { b |= 8; } if (value.ServerPicoseconds != 0) { b |= 32; } this.WriteByte(null, b); if ((b & 1) != 0) { this.WriteVariant(null, value.Variant); } if ((b & 2) != 0) { this.WriteStatusCode(null, value.StatusCode); } if ((b & 4) != 0) { this.WriteDateTime(null, value.SourceTimestamp); } if ((b & 16) != 0) { this.WriteUInt16(null, value.SourcePicoseconds); } if ((b & 8) != 0) { this.WriteDateTime(null, value.ServerTimestamp); } if ((b & 32) != 0) { this.WriteUInt16(null, value.ServerPicoseconds); } }
public DataValue?Execute(DataValue? @in) => @in.HasValue ? Execute(@in.Value) : new DataValue?();
private static ClassInfo GetClassInfo(Type typeClass, Dictionary <string, ClassInfo> allClasses, Dictionary <string, StructInfo> allStructs, Dictionary <string, EnumInfo> allEnums) { var res = new ClassInfo(); res.FullName = typeClass.FullName; res.Name = typeClass.Name; res.IsAbstract = typeClass.IsAbstract; Type super = typeClass.BaseType; if (super != null && super.FullName != "System.Object" && super.FullName != "Mediator.Util.ModelObject") { res.BaseClassName = super.FullName; } object defaultObject = Activator.CreateInstance(typeClass); Type tIModelObject = typeof(IModelObject); Type tIModelObjectEnum = typeof(IEnumerable <IModelObject>); PropertyInfo[] properties = typeClass.GetProperties(BindingFlags.Instance | BindingFlags.Public); DefaultCategory defaultCategory = typeClass.GetCustomAttribute <DefaultCategory>(); IdPrefix idPrefix = typeClass.GetCustomAttribute <IdPrefix>(); if (idPrefix != null) { res.IdPrefix = idPrefix.Value; } else { res.IdPrefix = typeClass.Name; } foreach (PropertyInfo p in properties) { Type t = p.PropertyType; bool browseable = p.GetCustomAttribute <Browseable>() != null; if (tIModelObject.IsAssignableFrom(t)) { if (!allClasses.ContainsKey(t.FullName)) { allClasses[t.FullName] = new ClassInfo(); allClasses[t.FullName] = GetClassInfo(t, allClasses, allStructs, allEnums); } res.ObjectMember.Add(new ObjectMember(p.Name, t.FullName, Dimension.Scalar, browseable)); } else if (t.IsGenericType && tIModelObjectEnum.IsAssignableFrom(t)) { t = t.GetGenericArguments()[0]; if (!allClasses.ContainsKey(t.FullName)) { allClasses[t.FullName] = new ClassInfo(); allClasses[t.FullName] = GetClassInfo(t, allClasses, allStructs, allEnums); } res.ObjectMember.Add(new ObjectMember(p.Name, t.FullName, Dimension.Array, browseable)); } else // SimpleMember { Dimension dim = GetDimensionFromPropertyType(t); if (t.IsGenericType) // Nullable or List { t = t.GetGenericArguments()[0]; } else if (t.IsArray) { t = t.GetElementType(); } DataType type = DataValue.TypeToDataType(t); string typeConstraints = ""; if (type == DataType.Enum || type == DataType.Struct) { typeConstraints = t.FullName; } if (type == DataType.Struct) { if (!allStructs.ContainsKey(t.FullName)) { allStructs[t.FullName] = new StructInfo(); allStructs[t.FullName] = GetStructInfo(t, allStructs, allEnums); } } else if (type == DataType.Enum) { if (!allEnums.ContainsKey(t.FullName)) { allEnums[t.FullName] = GetEnumInfo(t); } } object value = p.GetValue(defaultObject, null); DataValue?defaultValue = null; if (value != null) { defaultValue = DataValue.FromObject(value); } Category category = p.GetCustomAttribute <Category>(); string cat = category == null ? (defaultCategory == null ? "" : defaultCategory.Name) : category.Name; res.SimpleMember.Add(new SimpleMember(p.Name, type, typeConstraints, dim, defaultValue, browseable, cat)); } } return(res); }
public override bool TryGetValue(out DataValue?value) { value = default(DataValue); return(false); }
public abstract bool TryGetValue(out DataValue?value);
public DataValue?Execute(DataValue?a, DataValue?b) => (a.HasValue && b.HasValue) ? Execute(a.Value, b.Value) : new DataValue?();