private static Type GetReflectableClrType(TypeTypeValue type) { Type clrType; try { clrType = TypeManager.GetImplementingClass(type.Value.ID); } catch (InvalidOperationException) { throw NonReflectableType(); } Type reflectableType; if (clrType == typeof(AttachedScriptsFactory)) { reflectableType = ReflectUserType(type.Value.Name); } else { reflectableType = ReflectContext(clrType); } return(reflectableType); }
private static void FillMethodsTableForType(TypeTypeValue type, ValueTable.ValueTable result) { var clrType = GetReflectableClrType(type); var clrMethods = clrType.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); FillMethodsTable(result, ConvertToOsMethods(clrMethods)); }
public IValue AdjustValue(IValue value = null) { if (_types.Count == 0) { return(value ?? ValueFactory.Create()); } TypeTypeValue typeToCast = null; if (value != null && value.DataType != DataType.Undefined) { var valueType = new TypeTypeValue(value.SystemType); if (_types.Contains(valueType)) { // Если такой тип у нас есть typeToCast = valueType; } } if (typeToCast == null) { // Если типа нет, то нужно брать значение по-умолчанию if (_types.Count != 1) { // много типов - Неопределено return(ValueFactory.Create()); } typeToCast = _types[0]; } var adjuster = GetAdjusterForType(typeToCast); return(adjuster?.Adjust(value) ?? ValueFactory.Create()); }
public IValue ReadXml(XmlReaderImpl reader, TypeTypeValue requestedType = null) { var xdtoValue = XdtoFactory.ReadXml(reader); if (xdtoValue is IXdtoValue) { return(ReadXdto(xdtoValue as IXdtoValue)); } return(xdtoValue); }
private static void FillPropertiesTableForType(TypeTypeValue type, ValueTable.ValueTable result) { var clrType = GetReflectableClrType(type); var mapper = CreatePropertiesMapper(clrType); var actualType = mapper.GetType(); var infos = (IEnumerable <VariableInfo>)actualType.InvokeMember("GetProperties", BindingFlags.InvokeMethod, null, mapper, new object[0]); FillPropertiesTable(result, infos); }
private static bool MethodExistsForType(TypeTypeValue type, string methodName) { var clrType = GetReflectableClrType(type); var mapper = CreateMethodsMapper(clrType); var actualType = mapper.GetType(); int result = (int)actualType.InvokeMember("FindMethod", BindingFlags.InvokeMethod, null, mapper, new object[] { methodName }); return(result >= 0); }
public void Type_Value_Test() { var typeValue = new TypeTypeValue(new TypeDescriptor { Name = "Строка", ID = 1899 }); Assert.True(typeValue.DataType == DataType.Type); Assert.True(typeValue.AsString() == "Строка"); Assert.Throws <RuntimeException>(() => typeValue.AsNumber()); Assert.Throws <RuntimeException>(() => typeValue.AsBoolean()); Assert.Throws <RuntimeException>(() => typeValue.AsObject()); Assert.Throws <RuntimeException>(() => typeValue.AsDate()); }
private static void FillPropertiesTableForType(TypeTypeValue type, ValueTable.ValueTable result) { var clrType = GetReflectableClrType(type); var nativeProps = clrType.GetProperties() .Select(x => new { PropDef = x.GetCustomAttribute <ContextPropertyAttribute>(), Prop = x }) .Where(x => x.PropDef != null); int indices = 0; var infos = new List <VariableInfo>(); foreach (var prop in nativeProps) { var info = new VariableInfo(); info.Type = SymbolType.ContextProperty; info.Index = indices++; info.Identifier = prop.PropDef.GetName(); info.Annotations = GetAnnotations(prop.Prop.GetCustomAttributes <UserAnnotationAttribute>()); infos.Add(info); } if (clrType.BaseType == typeof(ScriptDrivenObject)) { var nativeFields = clrType.GetFields(); foreach (var field in nativeFields) { var info = new VariableInfo(); info.Type = SymbolType.ContextProperty; info.Index = indices++; info.Identifier = field.Name; info.Annotations = GetAnnotations(field.GetCustomAttributes <UserAnnotationAttribute>()); infos.Add(info); } } FillPropertiesTable(result, infos); }
private static Type GetReflectableClrType(TypeTypeValue type) { Type clrType; try { clrType = TypeManager.GetImplementingClass(type.Value.ID); } catch (InvalidOperationException) { throw RuntimeException.InvalidArgumentValue("Тип не может быть отражен."); } var attrs = clrType.GetCustomAttributes(typeof(ContextClassAttribute), false).ToArray(); if (attrs.Length == 0) { throw RuntimeException.InvalidArgumentValue("Тип не может быть отражен."); } return(clrType); }
IValueAdjuster GetAdjusterForType(TypeTypeValue type) { if (type.Value.Equals(TypeDescriptor.FromDataType(DataType.Number))) { return(NumberQualifiers); } if (type.Value.Equals(TypeDescriptor.FromDataType(DataType.String))) { return(StringQualifiers); } if (type.Value.Equals(TypeDescriptor.FromDataType(DataType.Date))) { return(DateQualifiers); } if (type.Value.Equals(TypeDescriptor.FromDataType(DataType.Boolean))) { return(new BooleanTypeAdjuster()); } return(null); }
private static bool MethodExistsForType(TypeTypeValue type, string methodName) { var clrType = GetReflectableClrType(type); return(clrType.GetMethod(methodName) != null); }
public IValue ReadXML(XmlReaderImpl xmlReader, IValue valueType = null) { TypeTypeValue typeValue = null; if (valueType is TypeTypeValue typeTypeValue) { typeValue = typeTypeValue; } else if (xmlReader.NodeType == xmlNodeEnum.FromNativeValue(XmlNodeType.Element)) { IValue xsiType = xmlReader.GetAttribute(ValueFactory.Create("type"), XmlSchema.InstanceNamespace); IValue xsiNil = xmlReader.GetAttribute(ValueFactory.Create("nil"), XmlSchema.InstanceNamespace); if (xsiType.DataType == DataType.String) { switch (xsiType.AsString()) { case "string": typeValue = new TypeTypeValue("String"); break; case "decimal": typeValue = new TypeTypeValue("Number"); break; case "boolean": typeValue = new TypeTypeValue("Boolean"); break; case "dateTime": typeValue = new TypeTypeValue("Date"); break; default: break; } } else if (xsiNil.DataType == DataType.String) { typeValue = new TypeTypeValue("Undefined"); } } ; if (typeValue == null) { throw RuntimeException.InvalidArgumentValue(); } Type implType = TypeManager.GetImplementingClass(typeValue.Value.ID); IValue result = ValueFactory.Create(); if (typeValue.Equals(new TypeTypeValue("Undefined"))) { result = ValueFactory.Create(); xmlReader.Skip(); } else if (implType == typeof(DataType)) { xmlReader.Read(); if (xmlReader.NodeType == xmlNodeEnum.FromNativeValue(XmlNodeType.Text)) { result = XMLValue(typeValue, xmlReader.Value); xmlReader.Read(); } else { throw RuntimeException.InvalidArgumentValue(); } } else if (typeof(IXDTOSerializableXML).IsAssignableFrom(implType)) { result = Activator.CreateInstance(implType, new object[] { xmlReader, this }) as IValue; } xmlReader.Read(); return(result); }