/// <summary> /// Initializes a new instance of the <see cref="ValueFactoryWithOptionalConcreteValue"/> class. /// </summary> /// <param name="valueFactory">The value factory.</param> /// <param name="value">The value.</param> internal ValueFactoryWithOptionalConcreteValue(IValueFactory valueFactory, object value) { if (valueFactory == null) { throw new ArgumentNullException("valueFactory"); } _valueFactory = valueFactory; _value = value; _isConcrete = true; }
public IValueFactory CreateValueFactory() { IValueFactory factory = null; try { factory = new ValueFactory(); } finally { } return(factory); }
///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// 添加工厂类 /// </summary> /// <param name="typeCode"></param> /// <param name="factory"></param> static internal void addFactory(ProtoTypeCode typeCode, IValueFactory factory) { if (factory == null) { return; } if (_factories.ContainsKey(typeCode)) { return; } _factories[typeCode] = factory; }
public IValue Add(IValueWithMathOperands other, IValueFactory fac) { return(other.Type switch { EilangType.String => fac.String(Item + other.As <StringValue>().Item), EilangType.Integer => fac.String(Item + other.Get <int>()), EilangType.Long => fac.String(Item + other.Get <long>()), EilangType.Double => fac.String(Item + other.Get <double>()), EilangType.Byte => fac.String(Item + other.Get <byte>()), EilangType.Bool => fac.String(Item + other.Get <bool>()), EilangType.Uninitialized => this, EilangType.List => fac.String(Item + other), EilangType.Map => fac.String(Item + other), _ => throw ThrowHelper.TypeMismatch(Type, "+", other.Type) });
internal void SetObjectProperty(Type t, object o, string propName, IValueFactory factory, IValueInitInfo valueInfo) { if (ReflectionCacheEnabled) { ReflectionPropertyCacheKey cacheKey = new ReflectionPropertyCacheKey(t, propName); ReflectionPropertyCacheValue cacheValue; if (!propertyInfoCache.TryGetValue(cacheKey, out cacheValue)) { System.Reflection.PropertyInfo propInfo = t.GetProperty(propName); if (propInfo == null) { throw new MissingMethodException(t.ToString(), propName); } MethodInfo setMethodInfo = propInfo.GetSetMethod(false); DynamicMethod setDynMethod = new DynamicMethod(String.Empty, typeof(void), new Type[] { typeof(object), typeof(object) }, t, true); ILGenerator setGenerator = setDynMethod.GetILGenerator(); setGenerator.Emit(OpCodes.Ldarg_0); setGenerator.Emit(OpCodes.Ldarg_1); if (setMethodInfo.GetParameters()[0].ParameterType.IsValueType) { setGenerator.Emit(OpCodes.Unbox_Any, setMethodInfo.GetParameters()[0].ParameterType); } setGenerator.Emit(OpCodes.Call, setMethodInfo); setGenerator.Emit(OpCodes.Ret); cacheValue = new ReflectionPropertyCacheValue( (PropertySetHandler)setDynMethod.CreateDelegate(typeof(PropertySetHandler)), propInfo.PropertyType); // despite the fact Dictionary is thread safe, for some reason sometimes exceptions are thrown without extra lock lock (propertyInfoCache) { propertyInfoCache[cacheKey] = cacheValue; } } object value = valueInfo.GetValue(factory, cacheValue.PropertyType); cacheValue.SetHandler(o, value); } else { System.Reflection.PropertyInfo propInfo = t.GetProperty(propName); if (propInfo == null) { throw new MissingMethodException(t.ToString(), propName); } propInfo.SetValue(o, valueInfo.GetValue(factory, propInfo.PropertyType), null); } }
public static IValue ToValue(this object obj, IValueFactory factory = default) { if (factory == null) { factory = new ValueFactory(); } return(obj switch { string s => factory.String(s), int i => factory.Integer(i), long l => factory.Long(l), double d => factory.Double(d), bool b => factory.Bool(b), IntPtr ptr => factory.IntPtr(ptr), _ => ConvertToEilangInstance(obj, factory) });
public DisposableClass(IOperationCodeFactory factory, IValueFactory valueFactory) : base( SpecialVariables.Disposable, SpecialVariables.Global) { CtorForMembersWithValues.Write(factory.Pop()); // pop self instance used for 'me' variable CtorForMembersWithValues.Write(factory.Return()); Functions.Add("dispose", new MemberFunction("dispose", Module, new List <string> { }, this) { Code = { new Bytecode(factory.Pop()), // pops unused argument count new Bytecode(factory.Reference(valueFactory.String(SpecialVariables.Disposable))), new Bytecode(factory.Dispose()), new Bytecode(factory.Return()) } }); }
/// <summary> /// Initializes a new instance of the <see cref="ValueFactoryWithOptionalConcreteValue"/> class. /// </summary> /// <param name="valueFactory">The value factory.</param> public ValueFactoryWithOptionalConcreteValue(IValueFactory valueFactory) { if (valueFactory == null) { throw new ArgumentNullException("valueFactory"); } _valueFactory = valueFactory; SingleValueFactory asSingleValueFactory = valueFactory as SingleValueFactory; if (asSingleValueFactory != null) { // If it's a single value, it's concrete. _value = asSingleValueFactory.GetBaseValue(); _isConcrete = true; } else { _isConcrete = false; } }
public object GetValue(IValueFactory factory, Type conversionType) { if (ComponentMethod != null) { var targetInstance = factory.GetInstance(ComponentRef, typeof(object)); var delegFactory = new DelegateFactory(targetInstance, ComponentMethod); if (typeof(Delegate).IsAssignableFrom(conversionType)) { delegFactory.DelegateType = conversionType; } return(factory.GetInstance( delegFactory.GetObject(), conversionType )); } else { return(factory.GetInstance(ComponentRef, conversionType)); } }
public object GetValue(IValueFactory factory, Type conversionType) { lock (cachedTypedArraysSyncObject) { // try to find in consts cache if (isOnlyConstValues && cachedTypedArrays != null && conversionType.IsArray && cachedTypedArrays.ContainsKey(conversionType.GetElementType())) { return(cachedTypedArrays[conversionType.GetElementType()].Clone()); } // try to create instance of desired type Type elemType = typeof(object); if (conversionType.IsArray) { elemType = conversionType.GetElementType(); } Array listArray = Array.CreateInstance(elemType, Values.Length); for (int i = 0; i < Values.Length; i++) { IValueInitInfo value = Values[i]; listArray.SetValue(value.GetValue(factory, elemType), i); } // store in consts cache if (isOnlyConstValues && conversionType.IsArray) { if (cachedTypedArrays == null) { cachedTypedArrays = new Dictionary <Type, Array>(); } cachedTypedArrays[elemType] = (Array)listArray.Clone(); } if (conversionType.IsArray) { return(listArray); // nothing to convert } return(factory.GetInstance(listArray, conversionType)); } }
/// <summary> /// Creates a new instance of a compound object. /// </summary> /// <param name="valueFactory">The object responsible for creating instances of values in a field.</param> /// <param name="objectType">The type of the object.</param> /// <param name="initialize">Indicates whether the object should be initialized with zeroes.</param> /// <exception cref="NotSupportedException"></exception> public HleStructValue(IValueFactory valueFactory, TypeSignature objectType, bool initialize) { if (valueFactory == null) { throw new ArgumentNullException(nameof(valueFactory)); } _is32Bit = valueFactory.Is32Bit; Type = objectType ?? throw new ArgumentNullException(nameof(objectType)); switch (objectType.ElementType) { case ElementType.Class: case ElementType.ValueType: case ElementType.GenericInst: break; default: throw new NotSupportedException("Unsupported object type."); } InitializeFields(valueFactory, initialize); }
internal RelativeComparison(Opperator opperator, string asString, IValueFactory valueFactory) { _opperator = opperator; _asString = asString; _valueFactory = valueFactory; }
/// <summary> /// Creates a new low level emulated object. /// </summary> /// <param name="valueFactory">The object responsible for memory management in the virtual machine.</param> /// <param name="valueType">The type of the object.</param> /// <param name="contents">The raw contents of the object.</param> public LleStructValue(IValueFactory valueFactory, TypeSignature valueType, IMemoryAccessValue contents) { Type = valueType ?? throw new ArgumentNullException(nameof(valueType)); ValueFactory = valueFactory ?? throw new ArgumentNullException(nameof(valueFactory)); Contents = contents ?? throw new ArgumentNullException(nameof(contents)); }
/// <summary> /// Creates a new empty instance of the <see cref="CilProgramState"/> class. /// </summary> public CilProgramState(IValueFactory valueFactory) { _valueFactory = valueFactory ?? throw new ArgumentNullException(nameof(valueFactory)); Stack = new StackState <IConcreteValue>(); Variables = new CilVariableState(valueFactory); }
/// <summary> /// Creates a new variable state snapshot, using the provided default value. /// </summary> /// <param name="valueFactory">The factory responsible for creating the default value for all variables.</param> public CilVariableState(IValueFactory valueFactory) { _valueFactory = valueFactory ?? throw new ArgumentNullException(nameof(valueFactory)); }
public ReplEnvironment(IOperationCodeFactory operationCodeFactory, IValueFactory valueFactory) : base(operationCodeFactory, valueFactory) { }
internal Logical(Opperator opperator, string asString, IValueFactory valueFactory) { _opperator = opperator; _asString = asString; _valueFactory = valueFactory; }
public Repository(IScheduler uiThreadScheduler, ISimpleDb simpleDb, IRestApi restApi, IEntityFactory entityFactory, IValueFactory valueFactory) { this.uiThreadScheduler = uiThreadScheduler; this.simpleDb = simpleDb; this.restApi = restApi; this.entityFactory = entityFactory; this.valueFactory = valueFactory; }
public DataReaderCompanyPositionBuilder(IValueFactory valueFactory, IEnumParser enumParser) : base(valueFactory) { _enumParser = Guard.EnsureIsNotNull("enumParser", enumParser); }
internal InterpreterVisitor(IValueFactory valueFactory) { _valueFactory = valueFactory; }
protected ValueFactoryBuilderBase(IValueFactory valueFactory) { ValueFactory = Guard.EnsureIsNotNull("valueFactory", valueFactory); }
internal OperatorFactory(IValueFactory valueFactory) { _valueFactory = valueFactory; }
/// <summary> /// Creates a new empty instance of the <see cref="CilProgramState"/> class. /// </summary> public CilProgramState(IValueFactory valueFactory) { Stack = new StackState<ICliValue>(); Variables = new CilVariableState(valueFactory); }
internal AbsoluteComparison(Operator @operator, string asString, IValueFactory valueFactor) { _operator = @operator; _asString = asString; _valueFactory = valueFactor; }
public QueryVehicleRegistrationHistoryFunction() { this.qldbDriver = new QldbService().GetDriver(); this.tableMetadataService = new MetadataService(); this.valueFactory = new ValueFactory(); }
public CreateIndexes(IAsyncQldbDriver qldbDriver) { this.qldbDriver = qldbDriver; this.valueFactory = new ValueFactory(); }
public AddSecondaryOwnerFunction() { this.qldbDriver = new QldbService().GetDriver(); this.tableMetadataService = new MetadataService(); this.valueFactory = new ValueFactory(); }
public ReflectionBasedDataReaderBuilder(IValueFactory valueFactory) : base(valueFactory) { }
public IValue ValueNotEquals(IEilangEquatable other, IValueFactory fac) { return(fac.Bool(!BoolEquals(other))); }
protected ValueFactoryBuilderBase(IValueFactory valueFactory) { ValueFactory = Guard.ThrowIfNull("valueFactory", valueFactory); }
public object GetValue(IValueFactory factory, Type conversionType) { return(factory.GetInstance(Value, conversionType)); }
public MetadataService() { this.valueFactory = new ValueFactory(); }