Beispiel #1
0
        //
        public void SetField(DataField aField)
        {
            ConsoleTrace(" - " + aField.GetType().Name);


            //SharpDisplayManager.Program.iMainForm.SetClientFieldThreadSafe(SessionId, aField);
        }
    /// <summary>
    /// Instanciate a generic DataField<T> given an XElement
    /// </summary>
    public static DataField CreateDataField(XElement element)
    {
        //Determine the type of element we deal with
        string elementTypeName = element.Attribute("Type").Value;
        Type   elementType     = Type.GetType(elementTypeName);
        //Instanciate a new Generic element of type: DataField<T>
        DataField dataField = (DataField)Activator.CreateInstance(typeof(DataField <>).MakeGenericType(elementType));

        dataField.Name = element.Name.ToString();
        //Convert the inner value to the target element type
        object value = Convert.ChangeType(element.Value, elementType);
        //Set the value into DataField
        PropertyInfo valueProperty = dataField.GetType().GetProperty("Value");

        valueProperty.SetValue(dataField, value, null);
        return(dataField);
    }