Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a variable to a TypeGo
        /// </summary>
        public static TVariable InitializeVariable <TVariable>(BaseTypeGoInfo typeGoInfo, ITypeOptions options)
            where TVariable : BaseVariable, new()
        {
            TVariable variable = new TVariable();

            variable.InitializeBase(typeGoInfo, options);
            return(variable);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// property info of a type
        /// </summary>
        public PropertyGoInfo(PropertyInfo property, ITypeOptions options)
        {
            //coming from change structure
            if (property == null)
            {
                if (options.TryGetValueOfTypeGo(typeof(TPropertyType), out object typeGoInfoProperty))
                {
                    TypeGoInfo = (TypeGoInfo<TPropertyType>)typeGoInfoProperty;
                }
                else
                {
                    TypeGoInfo = BaseTypeGoInfo.Generate<TPropertyType>(options);
                }
                GetValue = (ref TObject obj) => default;
                SetValue = (TObject obj, TPropertyType value) => { };
            }
            //coming from normal binary Go
            else
            {
                if (options.TryGetValueOfTypeGo(property.PropertyType, out object typeGoInfoProperty))
                {
                    TypeGoInfo = (TypeGoInfo<TPropertyType>)typeGoInfoProperty;
                }
                else
                {
                    TypeGoInfo = BaseTypeGoInfo.Generate<TPropertyType>(options);
                }

                PropertyCallerInfo<TObject, TPropertyType> propertyCaller;

                try
                {
                    propertyCaller = ReflectionHelper.GetDelegateInstance<TObject, TPropertyType>(property);
                }
                catch (Exception ex)
                {
                    throw new Exception($"Cannot create delegate for property {property.Name} in type {TypeGoInfo.Type.FullName}", ex);
                }
                GetValue = propertyCaller.GetValueAction;
                SetValue = propertyCaller.SetValueAction;
            }
            Type = typeof(TPropertyType);
        }