public void GetValue() { Assert.AreEqual(0, _getter.Get(_instance)); _instance.Increment(); Assert.AreEqual(1, _getter.Get(_instance)); Assert.AreEqual(_expectedBlahGetterCalled, _instance.BlahGetterCalled, "pascalcase-m-underscore"); Assert.AreEqual(_expectedCamelBazGetterCalled, _instance.CamelBazGetterCalled, "camelcase"); Assert.AreEqual(_expectedCamelUnderscoreFooGetterCalled, _instance.CamelUnderscoreFooGetterCalled, "camelcase-underscore"); Assert.AreEqual(_expectedLowerUnderscoreFooGetterCalled, _instance.LowerUnderscoreFooGetterCalled, "lowercase-underscore"); Assert.AreEqual(_expectedLowerFooGetterCalled, _instance.LowerFooGetterCalled, "lowercase"); Assert.AreEqual(_expectedPascalUnderscoreFooGetterCalled, _instance.PascalUnderscoreFooCalled, "pascalcase-underscore"); Assert.AreEqual(_expectedCamelMUnderscoreGetterCalled, _instance.CamelMUnderscoreGetterCalled, "camelcase-m-underscore"); }
public IQuery SetProperties(object bean) { System.Type clazz = bean.GetType(); string[] @params = NamedParameters; for (int i = 0; i < @params.Length; i++) { string namedParam = @params[i]; try { IGetter getter = ReflectHelper.GetGetter(clazz, namedParam, "property"); System.Type retType = getter.ReturnType; object obj = getter.Get(bean); if (typeof(ICollection).IsAssignableFrom(retType)) { SetParameterList(namedParam, (ICollection)obj); } else if (retType.IsArray) { SetParameterList(namedParam, (Object[])obj); } else { SetParameter(namedParam, obj, DetermineType(namedParam, retType)); } } catch (PropertyNotFoundException) { // ignore } } return(this); }
/// <summary> /// /// </summary> /// <param name="component"></param> /// <returns></returns> public override object DeepCopy(object component) { if (component == null) { return(null); } object[] values = GetPropertyValues(component); for (int i = 0; i < propertySpan; i++) { values[i] = propertyTypes[i].DeepCopy(values[i]); } object result = Instantiate(); SetPropertyValues(result, values); // TODO NH: The code below is present in H2.1, but it breaks some // tests in NH because FooComponent.Parent setter throws // an exception if setting parent to null. // // not absolutely necessary, but helps for some // Equals/GetHashCode implementations // if (parentGetter != null) { parentSetter.Set(result, parentGetter.Get(component)); } return(result); }
public object GetIdentifier(object entity) { object id; if (entityMetamodel.IdentifierProperty.IsEmbedded) { id = entity; } else { if (idGetter == null) { if (identifierMapperType == null) { throw new HibernateException("The class has no identifier property: " + EntityName); } else { ComponentType copier = (ComponentType)entityMetamodel.IdentifierProperty.Type; id = copier.Instantiate(EntityMode); copier.SetPropertyValues(id, identifierMapperType.GetPropertyValues(entity, EntityMode), EntityMode); } } else { id = idGetter.Get(entity); } } return(id); }
public static VersionValue GetUnsavedVersionValue( String versionUnsavedValue, IGetter versionGetter, IVersionType versionType, ConstructorInfo constructor) { if (versionUnsavedValue == null) { if (constructor != null) { object defaultValue = versionGetter.Get(Instantiate(constructor)); if (defaultValue != null && defaultValue.GetType().IsValueType) { return(new VersionValue(defaultValue)); } else { // if the version of a newly instantiated object is not the same // as the version seed value, use that as the unsaved-value return (versionType.IsEqual(versionType.Seed(null), defaultValue) ? VersionValue.VersionUndefined : new VersionValue(defaultValue)); } } else { return(VersionValue.VersionUndefined); } } else if ("undefined" == versionUnsavedValue) { return(VersionValue.VersionUndefined); } else if ("null" == versionUnsavedValue) { return(VersionValue.VersionSaveNull); } else if ("negative" == versionUnsavedValue) { return(VersionValue.VersionNegative); } else { // NHibernate-specific try { return(new VersionValue(versionType.FromStringValue(versionUnsavedValue))); } catch (InvalidCastException ice) { throw new MappingException("Bad version type: " + versionType.Name, ice); } catch (Exception e) { throw new MappingException("Could not parse version unsaved-value: " + versionUnsavedValue, e); } } }
public void StringTextExtraction() { Property property = GenerateTextProperty(); IGetter getter = PropertyAccessorFactory.GetPropertyAccessor(property, EntityMode.Xml).GetGetter(null, null); var name = (string)getter.Get(dom); Assert.That(name, Is.EqualTo("description...")); }
public void StringElementExtraction() { Property property = GenerateNameProperty(); IGetter getter = PropertyAccessorFactory.GetPropertyAccessor(property, EntityMode.Xml).GetGetter(null, null); var name = (string)getter.Get(dom); Assert.That(name, Is.EqualTo("NHForge")); }
public void LongElementAttributeExtraction() { Property property = GenerateAccountIdProperty(); IGetter getter = PropertyAccessorFactory.GetPropertyAccessor(property, EntityMode.Xml).GetGetter(null, null); var id = (long)getter.Get(dom); Assert.That(id, Is.EqualTo(456L)); }
public IEnumerable <T> Get() { if (GITM != null) { EITM = GITM.Get() ?? Enumerable.Empty <T>(); } return(this.getFiltered(EITM)); }
public void Setup_IGetter_メソッドのモック化のサンプル_nullを仕込む場合() { // IGetterのモックオブジェクトの作成 var getterMock = new Mock <IGetter>(); // モックオブジェクトからIGetterインスタンスとして取り出し IGetter mockAsGetter = getterMock.Object; // モック化していない場合はdefaultを返す Assert.Null(mockAsGetter.Get()); // Getメソッドのモック化("Hello Moq!"を返すように仕込み) getterMock.Setup(m => m.Get()).Returns(null); // then Assert.Null(mockAsGetter.Get()); }
public override ExecuteResult Execute(Context context) { var dat = SRC.Get(); DST.Set(dat); return(new ExecuteResult(true)); }
public override object GetParent(object component) { if (isBytecodeProviderImpl && optimizer?.AccessOptimizer != null) { return(optimizer.AccessOptimizer.GetSpecializedPropertyValue(component)); } return(parentGetter.Get(component)); }
public void Reset() { CUR = -1; if (SRC != null) { ACMD = SRC.Get(); } ITM = null; }
public async Task <IViewComponentResult> InvokeAsync(UniqueList <string> modules) { modules.Add(nameof(ConfirmationDialogViewComponent).ViewComponentName()); return(View(new DoctorPositionEditorViewModel { Positions = await _positions.Get() })); }
public void CamelCaseUnderscoreNamingStrategy() { IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyTwo", "field.camelcase-underscore"); Assert.IsNotNull(fieldGetter, "should have found getter"); Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field."); Assert.AreEqual(typeof(Boolean), fieldGetter.ReturnType, "returns Boolean."); Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields."); Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields."); Assert.AreEqual(true, fieldGetter.Get(obj), "Get() for Boolean"); }
public void LowerCaseUnderscoreNamingStrategy() { IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyFour", "field.lowercase-underscore"); Assert.IsNotNull(fieldGetter, "should have found getter"); Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field."); Assert.AreEqual(typeof(Int64), fieldGetter.ReturnType, "returns Int64."); Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields."); Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields."); Assert.AreEqual(Int64.MaxValue, fieldGetter.Get(obj), "Get() for Int64"); }
public void CamelCaseNamingStrategy() { IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyOne", "field.camelcase"); Assert.IsNotNull(fieldGetter, "should have found getter"); Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field."); Assert.AreEqual(typeof(DateTime), fieldGetter.ReturnType, "returns DateTime."); Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields."); Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields."); Assert.AreEqual(DateTime.Parse("2000-01-01"), fieldGetter.Get(obj), "Get() for DateTime"); }
public void NoNamingStrategy() { IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "Id", "field"); Assert.IsNotNull(fieldGetter, "should have found getter"); Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field."); Assert.AreEqual(typeof(Int32), fieldGetter.ReturnType, "returns Int32."); Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields."); Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields."); Assert.AreEqual(7, fieldGetter.Get(obj), "Get() for Int32"); }
public void PascalCaseMUnderscoreNamingStrategy() { IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyThree", "field.pascalcase-m-underscore"); Assert.IsNotNull(fieldGetter, "should have found getter"); Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field."); Assert.AreEqual(typeof(TimeSpan), fieldGetter.ReturnType, "returns DateTime."); Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields."); Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields."); Assert.AreEqual(new TimeSpan(DateTime.Parse("2001-01-01").Ticks), fieldGetter.Get(obj), "Get() for TimeSpan"); }
public void CamelCaseMUnderscoreNamingStrategy() { IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyFive", "field.camelcase-m-underscore"); Assert.IsNotNull(fieldGetter, "should have found getter"); Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field."); Assert.AreEqual(typeof(decimal), fieldGetter.ReturnType, "returns Decimal."); Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields."); Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields."); Assert.AreEqual(2.5m, fieldGetter.Get(obj), "Get() for Decimal"); }
public override void EntityChanged(System.Type entityClass, string entityName, object entityId, RevisionType revisionType, object revisionEntity) { base.EntityChanged(entityClass, entityName, entityId, revisionType, revisionEntity); var modifiedEntityNames = (ISet <string>)modifiedEntityTypesGetter.Get(revisionEntity); if (modifiedEntityNames == null) { modifiedEntityNames = new HashSet <string>(); modifiedEntityTypesSetter.Set(revisionEntity, modifiedEntityNames); } modifiedEntityNames.Add(entityName); }
public T Get() { if (GSRC != null) { SRC = GSRC.Get(); } if (SRC == null) { return(default(T)); } return(PRC(SRC)); }
/// <summary> /// Return an IdentifierValue for the specified unsaved-value. If none is specified, /// guess the unsaved value by instantiating a test instance of the class and /// reading it's id property, or if that is not possible, using the java default /// value for the type /// </summary> public static IdentifierValue GetUnsavedIdentifierValue( string unsavedValue, IGetter identifierGetter, IType identifierType, ConstructorInfo constructor) { if (unsavedValue == null) { if (identifierGetter != null && constructor != null) { // use the id value of a newly instantiated instance as the unsaved-value object defaultValue = identifierGetter.Get(Instantiate(constructor)); return(new IdentifierValue(defaultValue)); } var idTypeAsPrimitiveType = identifierType as PrimitiveType; if (identifierGetter != null && idTypeAsPrimitiveType != null) { object defaultValue = idTypeAsPrimitiveType.DefaultValue; return(new IdentifierValue(defaultValue)); } return(IdentifierValue.SaveNull); } if ("null" == unsavedValue) { return(IdentifierValue.SaveNull); } if ("undefined" == unsavedValue) { return(IdentifierValue.Undefined); } if ("none" == unsavedValue) { return(IdentifierValue.SaveNone); } if ("any" == unsavedValue) { return(IdentifierValue.SaveAny); } try { return(new IdentifierValue(((IIdentifierType)identifierType).StringToObject(unsavedValue))); } catch (InvalidCastException cce) { throw new MappingException("Bad identifier type: " + identifierType.Name, cce); } catch (Exception e) { throw new MappingException("Could not parse identifier unsaved-value: " + unsavedValue, e); } }
/// <summary> /// Return an IdentifierValue for the specified unsaved-value. If none is specified, /// guess the unsaved value by instantiating a test instance of the class and /// reading it's id property, or if that is not possible, using the java default /// value for the type /// </summary> public static IdentifierValue GetUnsavedIdentifierValue( string unsavedValue, IGetter identifierGetter, IType identifierType, ConstructorInfo constructor) { if (unsavedValue == null) { if (identifierGetter != null && constructor != null) { // use the id value of a newly instantiated instance as the unsaved-value object defaultValue = identifierGetter.Get(Instantiate(constructor)); return new IdentifierValue(defaultValue); } var idTypeAsPrimitiveType = identifierType as PrimitiveType; if (identifierGetter != null && idTypeAsPrimitiveType != null) { object defaultValue = idTypeAsPrimitiveType.DefaultValue; return new IdentifierValue(defaultValue); } return IdentifierValue.SaveNull; } if ("null" == unsavedValue) { return IdentifierValue.SaveNull; } if ("undefined" == unsavedValue) { return IdentifierValue.Undefined; } if ("none" == unsavedValue) { return IdentifierValue.SaveNone; } if ("any" == unsavedValue) { return IdentifierValue.SaveAny; } try { return new IdentifierValue(((IIdentifierType) identifierType).StringToObject(unsavedValue)); } catch (InvalidCastException cce) { throw new MappingException("Bad identifier type: " + identifierType.Name, cce); } catch (Exception e) { throw new MappingException("Could not parse identifier unsaved-value: " + unsavedValue, e); } }
public string Get() { if (GQST != null) { QST = GQST.Get(); } string msg = QST ?? GetterAskConsole.TextMessageDefault , err = WRN ?? GetterAskConsole.TextInvalidDefault ; retry: // Display a question if (Display != null) { Display.Write(this, new Messaging.EventArgsMessage(msg, Messaging.TMessage.UserInput)); } else { Console.Write(msg + " : "); } // read the answere var txt = Console.ReadLine(); // Validte the answer if needed if (this.VLD != null && !this.VLD(txt)) { if (Display != null) { Display.Write(this, new Messaging.EventArgsMessage(err, Messaging.TMessage.Warning)); } else { Console.WriteLine(err); } goto retry; } else if (string.IsNullOrEmpty(txt)) { throw new OperationCanceledException(); } return(txt); }
/// <summary> /// /// </summary> /// <param name="bean"></param> /// <returns></returns> public IQuery SetProperties(object bean) { System.Type clazz = bean.GetType(); foreach (string namedParam in actualNamedParameters) { try { IGetter getter = ReflectHelper.GetGetter(clazz, namedParam, "property"); SetParameter(namedParam, getter.Get(bean), GuessType(getter.ReturnType)); } catch (Exception) { } } return(this); }
public IBatch Parse(IGetter <string> source, string description = null) { SBD.Clear(); SINS.Clear(); CUR = new ins_variant(); var src = source.Get(); if (string.IsNullOrEmpty(src)) { goto finalize; } // This will store a filepath in order to prevent multiple calls for once-only files if (source is GetterTextFile) { FilesUsed.Add(((GetterTextFile)source).Filepath); } char c; var echr = src.AsEnumerable().GetEnumerator(); while (echr.MoveNext()) { c = echr.Current; this.append(c); } this.append('\r'); // this closes the current value-parsers and any other processing finalize: var ainp = SINS.Select(x => new Input(ref x)).ToArray(SINS.Count); var abab = ainp.Select(x => this.parse(x)).ToArrayR(ainp.Length); var bch = new BatchSequential() { Text = description }; return(bch.Append(abab)); }
public override ExecuteResult Execute(Context context) { string cmd, args = null; string pth = GPTH.Get(); if (string.IsNullOrEmpty(pth)) { throw new ExceptionRuntime("Ничего не запущено"); } if (File.Exists(pth)) { cmd = pth; } else if (Directory.Exists(pth)) { cmd = pth; } else { //throw new FileNotFoundException("Путь не найден: " + filepath); pth = pth.Trim(); int pos = pth.IndexOf(' '); if (pos < 1) { cmd = pth; } else { cmd = pth.Substring(0, pos); args = pth.Substring(pos); } } System.Diagnostics.Process.Start(cmd, args); return(new ExecuteResult(true)); }
public string Get() { string pth = Filepath; if (GPTH != null) { pth = GPTH.Get(); } else if (FPTH != null) { pth = FPTH.Create(pth); } var fil = new FileInfo(pth); if (!fil.Exists) { pth = modify(fil); } using (var stm = new StreamReader(pth, this.Encoding)) { return(stm.ReadToEnd()); } }
protected virtual object GetIdentifierPropertyValue(object entity) { return(idGetter.Get(entity)); }
public static Cascades.VersionValue GetUnsavedVersionValue( String versionUnsavedValue, IGetter versionGetter, IVersionType versionType, ConstructorInfo constructor) { if ( versionUnsavedValue == null ) { if ( constructor!=null ) { Object defaultValue = versionGetter.Get( Instantiate(constructor) ); // if the version of a newly instantiated object is not the same // as the version seed value, use that as the unsaved-value return versionType.Equals( versionType.Seed, defaultValue ) ? Cascades.VersionValue.VersionUndefined : new Cascades.VersionValue( defaultValue ); } else { return Cascades.VersionValue.VersionUndefined; } } else if ( "undefined" == versionUnsavedValue ) { return Cascades.VersionValue.VersionUndefined; } else if ( "null" == versionUnsavedValue ) { return Cascades.VersionValue.VersionSaveNull; } else if ( "negative" == versionUnsavedValue ) { return Cascades.VersionValue.VersionNegative; } else { // NHibernate-specific try { return new Cascades.VersionValue( versionType.StringToObject( versionUnsavedValue ) ); } catch( InvalidCastException ice ) { throw new MappingException( "Bad version type: " + versionType.Name, ice ); } catch( Exception e ) { throw new MappingException( "Could not parse version unsaved-value: " + versionUnsavedValue, e ); } } }
/// <summary> /// Return an IdentifierValue for the specified unsaved-value. If none is specified, /// guess the unsaved value by instantiating a test instance of the class and /// reading it's id property, or if that is not possible, using the java default /// value for the type /// </summary> public static Cascades.IdentifierValue GetUnsavedIdentifierValue( string unsavedValue, IGetter identifierGetter, IType identifierType, ConstructorInfo constructor ) { if( unsavedValue == null ) { if( identifierGetter != null && constructor != null ) { // use the id value of a newly instantiated instance as the unsaved-value object defaultValue = identifierGetter.Get( Instantiate( constructor ) ); return new Cascades.IdentifierValue( defaultValue ); } // TODO: NH - the branch below is actually never visited, so it's commented out /* else if( identifierGetter != null && ( identifierType is ValueTypeType ) ) { object defaultValue = ( ( ValueTypeType ) identifierType ).DefaultValue; return new Cascades.IdentifierValue( defaultValue ); } */ else { return Cascades.IdentifierValue.SaveNull; } } else if( "null" == unsavedValue ) { return Cascades.IdentifierValue.SaveNull; } // TODO: H3 only, IdentifierValue.IsUnsaved may return true/false/null in H3 // and SaveUndefined always returns null. /* else if( "undefined" == unsavedValue ) { return Cascades.IdentifierValue.SaveUndefined; } */ else if( "none" == unsavedValue ) { return Cascades.IdentifierValue.SaveNone; } else if( "any" == unsavedValue ) { return Cascades.IdentifierValue.SaveAny; } else { try { return new Cascades.IdentifierValue( ( ( IIdentifierType ) identifierType ).StringToObject( unsavedValue ) ); } catch( InvalidCastException cce ) { throw new MappingException( "Bad identifier type: " + identifierType.Name, cce ); } catch( Exception e ) { throw new MappingException( "Could not parse identifier unsaved-value: " + unsavedValue, e ); } } }
public override object GetParent(object component) { return(parentGetter.Get(component)); }