public ValueCollectionEntry(Arebis.CodeGeneration.IGenerationHost _host, IZetboxContext ctx, Property prop) : base(_host, ctx) { if (!(prop is ValueTypeProperty || prop is CompoundObjectProperty)) { throw new ArgumentOutOfRangeException("prop", String.Format("Property has to be either ValueTypeProperty or CompoundObjectProperty, but is {0}", prop.GetType().FullName)); } this.prop = prop; }
/// <summary> /// Builds object from property /// </summary> /// <param name = "property"></param> /// <returns></returns> public object CreateObject(Property property, object copyToObject = null) { if (property == null) { throw new ArgumentNullException("property"); } // Is it NullProperty? var nullProperty = property as NullProperty; if (nullProperty != null) { return null; } if (property.Type == null) { // there is no property type and no expected type defined. Give up! throw new InvalidOperationException(string.Format("Property type is not defined. Property: \"{0}\"", property.Name)); } // Is it SimpleProperty? var simpleProperty = property as SimpleProperty; if (simpleProperty != null) { return CreateObjectFromSimpleProperty(simpleProperty); } var referenceTarget = property as ReferenceTargetProperty; if (referenceTarget == null) { return null; } if (copyToObject != null) { return CreateObjectFromComplexProperty(referenceTarget as ComplexProperty, copyToObject); } if (referenceTarget.Reference != null) { if (!referenceTarget.Reference.IsProcessed) { // object was created already // get object from cache return _objectCache[referenceTarget.Reference.Id]; } } var value = CreateObjectCore(referenceTarget); if (value != null) { return value; } // No idea what it is throw new InvalidOperationException(string.Format("Unknown Property type: {0}", property.GetType().Name)); }
/// <summary> /// Builds object from property /// </summary> /// <param name="property"></param> /// <returns></returns> public object CreateObject(Property property) { if (property == null) throw new ArgumentNullException("property"); // Is it NullProperty? var nullProperty = property as NullProperty; if (nullProperty != null) { return null; } if (property.Type == null) { // there is no property type and no expected type defined. Give up! throw new InvalidOperationException(string.Format("Property type is not defined. Property: \"{0}\"", property.Name)); } // Is it SimpleProperty? var simpleProperty = property as SimpleProperty; if (simpleProperty != null) { return createObjectFromSimpleProperty(simpleProperty); } // Is it multidimensional array? var multiDimensionalArrayProperty = property as MultiDimensionalArrayProperty; if (multiDimensionalArrayProperty != null) { return createObjectFromMultidimensionalArrayProperty(multiDimensionalArrayProperty); } // Is it singledimensional array? var singleDimensionalArrayProperty = property as SingleDimensionalArrayProperty; if (singleDimensionalArrayProperty != null) { return createObjectFromSingleDimensionalArrayProperty(singleDimensionalArrayProperty); } // Is it dictionary? var dictionaryProperty = property as DictionaryProperty; if (dictionaryProperty != null) { return createObjectFromDictionaryProperty(dictionaryProperty); } // Is it collection? var collectionProperty = property as CollectionProperty; if (collectionProperty != null) { return createObjectFromCollectionProperty(collectionProperty); } // Is it complex type? Class? Structure? var complexProperty = property as ComplexProperty; if (complexProperty != null) { return createObjectFromComplexProperty(complexProperty); } // No idea what it is throw new InvalidOperationException(string.Format("Unknown Property type: {0}", property.GetType().Name)); }
public static string GetPropertyValue(Property prop, bool textValue) { Type propertyType = prop.GetType(); string propertyValue = null; if (propertyType == typeof(StringProperty)) { propertyValue = ((StringProperty)prop).Value; } else if (propertyType == typeof(CrmDateTimeProperty)) { propertyValue = ((CrmDateTimeProperty)prop).Value.Value; } else if (propertyType == typeof(KeyProperty)) { propertyValue = ((KeyProperty)prop).Value.Value.ToString("D"); } else if (propertyType == typeof(CustomerProperty)) { propertyValue = textValue ? ((CustomerProperty)prop).Value.name : ((CustomerProperty)prop).Value.Value.ToString(); } else if (propertyType == typeof(LookupProperty)) { propertyValue = textValue ? ((LookupProperty)prop).Value.name : ((LookupProperty)prop).Value.Value.ToString("D"); } else if (propertyType == typeof(StateProperty)) { propertyValue = ((StateProperty)prop).Value; } else if (propertyType == typeof(OwnerProperty)) { propertyValue = textValue ? ((OwnerProperty)prop).Value.name : ((OwnerProperty)prop).Value.Value.ToString("D"); } else if (propertyType == typeof(CrmBooleanProperty)) { propertyValue = ((CrmBooleanProperty)prop).Value.Value.ToString(); } else if (propertyType == typeof(PicklistProperty)) { propertyValue = textValue ? ((PicklistProperty)prop).Value.name : ((PicklistProperty)prop).Value.Value.ToString(CultureInfo.CurrentCulture); } else if (propertyType == typeof(CrmDecimalProperty)) { propertyValue = ((CrmDecimalProperty)prop).Value.Value.ToString(CultureInfo.CurrentCulture); } else if (propertyType == typeof(CrmFloatProperty)) { propertyValue = ((CrmFloatProperty)prop).Value.Value.ToString(CultureInfo.CurrentCulture); } else if (propertyType == typeof(CrmMoneyProperty)) { propertyValue = ((CrmMoneyProperty)prop).Value.Value.ToString(CultureInfo.CurrentCulture); } else if (propertyType == typeof(CrmNumberProperty)) { propertyValue = ((CrmNumberProperty)prop).Value.Value.ToString(CultureInfo.CurrentCulture); } return propertyValue; }
private PropertyControlInfo(Property property) : base() { this.property = property; PropertyControlType defaultControlType = propertyTypeToDefaultControlType[this.property.GetType()]; this.controlType = StaticListChoiceProperty.CreateForEnum<PropertyControlType>(ControlInfoPropertyNames.ControlType, defaultControlType, false); this.controlType.ValueChanged += new EventHandler(ControlType_ValueChanged); this.ControlProperties = controlTypeToProperties[Pair.Create(property.GetType(), (PropertyControlType)this.controlType.Value)].Clone(); }
protected virtual void ApplyPropertyTemplate(Property p) { if (p is EnumerationProperty) { if (((EnumerationProperty)p).IsList) { ApplyEnumerationListTemplate((EnumerationProperty)p); ApplyListChangedEvent(p); } else { ApplyEnumerationPropertyTemplate((EnumerationProperty)p); ApplyPropertyEvents(p, false); } } else if (p is ObjectReferenceProperty) { var orp = (ObjectReferenceProperty)p; if (orp.IsList()) { ApplyObjectReferenceListTemplate(orp); ApplyListChangedEvent(p); } else { ApplyObjectReferencePropertyTemplate(orp); ApplyPropertyEvents(p, false); } } else if (p is CalculatedObjectReferenceProperty) { ApplyCalculatedPropertyTemplate((CalculatedObjectReferenceProperty)p); ApplyPropertyEvents(p, true); } else if (p is CompoundObjectProperty) { if (((CompoundObjectProperty)p).IsList) { ApplyCompoundObjectListTemplate((CompoundObjectProperty)p); ApplyListChangedEvent(p); } else { ApplyCompoundObjectPropertyTemplate((CompoundObjectProperty)p); // no PropertyInvocationsTemplate for CompoundObject } } else if (p is ValueTypeProperty) { var vtp = (ValueTypeProperty)p; if (vtp.IsList) { ApplyValueTypeListTemplate(vtp); ApplyListChangedEvent(p); } else { ApplyValueTypePropertyTemplate(vtp); ApplyPropertyEvents(p, false); } } else { throw new ArgumentOutOfRangeException("p", String.Format("unknown property type '{0}'", p.GetType().ToString())); } ApplyPropertyIsValidEvent(p); }
private static string PropertyToClrType(Property prop) { return prop.GetType().Name; }
private static string GetStandInValue(Property p) { if (p is DecimalProperty) { return "Decimal.MinValue"; } else if (p is IntProperty) { return "Int32.MinValue"; } else if (p is DoubleProperty) { return "Double.MinValue"; } else if (p is StringProperty) { return "null"; } else if (p is DateTimeProperty) { return "DateTime.MinValue"; } else if (p is GuidProperty) { return "Guid.Empty"; } else if (p is BoolProperty) { return "false"; } else if (p is EnumerationProperty) { return "-1"; } else if (p is ObjectReferenceProperty) { return "-1"; } else if (p is CalculatedObjectReferenceProperty) { return "-1"; } else if (p is CompoundObjectProperty) { return "null"; } else { throw new NotSupportedException(string.Format("DynamicOrderByExpression for Property Type {0} are not supported yet", p.GetType().Name)); } }
protected virtual void ApplyPropertyTemplate(Property p) { if (p is EnumerationProperty) { if (((EnumerationProperty)p).IsList) { ApplyEnumerationListTemplate((EnumerationProperty)p); ApplyListChangedEvent(p); } else { ApplyEnumerationPropertyTemplate((EnumerationProperty)p); ApplyPropertyEvents(p, false); } } else if (p is ObjectReferenceProperty) { var orp = (ObjectReferenceProperty)p; if (orp.IsList()) { ApplyObjectReferenceListTemplate(orp); var rel = Zetbox.App.Extensions.RelationExtensions.Lookup(ctx, orp); if (rel.GetRelationType() == API.RelationType.one_n) { // TODO: No idea how to implement this for n:m Relations ApplyListChangedEvent(p); } } else { ApplyObjectReferencePropertyTemplate(orp); ApplyPropertyEvents(p, false); } } else if (p is CalculatedObjectReferenceProperty) { ApplyCalculatedPropertyTemplate((CalculatedObjectReferenceProperty)p); ApplyPropertyEvents(p, true); } else if (p is CompoundObjectProperty) { if (((CompoundObjectProperty)p).IsList) { ApplyCompoundObjectListTemplate((CompoundObjectProperty)p); ApplyListChangedEvent(p); } else { ApplyCompoundObjectPropertyTemplate((CompoundObjectProperty)p); // no PropertyInvocationsTemplate for CompoundObject } } else if (p is ValueTypeProperty) { var vtp = (ValueTypeProperty)p; if (vtp.IsList) { ApplyValueTypeListTemplate(vtp); ApplyListChangedEvent(p); } else { ApplyValueTypePropertyTemplate(vtp); ApplyPropertyEvents(p, false); } } else { throw new ArgumentOutOfRangeException("p", String.Format("unknown property type '{0}'", p.GetType().ToString())); } ApplyPropertyIsValidEvent(p); }
public void TestGetIntegerPerformance() { const int TEST_ITERATIONS = 1000000; Property prop = new Property(); int test = -1; Timer timer = new Timer(); #region Direct access (fastest) GC.Collect(); GC.WaitForPendingFinalizers(); timer.Start(); for (int i = 0; i < TEST_ITERATIONS; i++) { test = -1; test = prop.Int; Assert.AreEqual(int.MinValue, test); } timer.Stop(); double directAccessDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS); #endregion #region IL Property accessor GC.Collect(); GC.WaitForPendingFinalizers(); IGetAccessorFactory factory = new GetAccessorFactory(true); IGetAccessor propertyAccessor = factory.CreateGetAccessor(typeof(Property), "Int"); timer.Start(); for (int i = 0; i < TEST_ITERATIONS; i++) { test = -1; test = (int)propertyAccessor.Get(prop); Assert.AreEqual(int.MinValue, test); } timer.Stop(); double propertyAccessorDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS); double propertyAccessorRatio = propertyAccessorDuration / directAccessDuration; #endregion #region IBatisNet.Common.Utilities.Object.ReflectionInfo GC.Collect(); GC.WaitForPendingFinalizers(); ReflectionInfo reflectionInfo = ReflectionInfo.GetInstance(prop.GetType()); timer.Start(); for (int i = 0; i < TEST_ITERATIONS; i++) { test = -1; PropertyInfo propertyInfo = (PropertyInfo)reflectionInfo.GetGetter("Int"); test = (int)propertyInfo.GetValue(prop, null); Assert.AreEqual(int.MinValue, test); } timer.Stop(); double reflectionInfoDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS); double reflectionInfoRatio = (float)reflectionInfoDuration / directAccessDuration; #endregion #region Reflection GC.Collect(); GC.WaitForPendingFinalizers(); Type type = prop.GetType(); timer.Start(); for (int i = 0; i < TEST_ITERATIONS; i++) { test = -1; PropertyInfo propertyInfo = type.GetProperty("Int", BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance); test = (int)propertyInfo.GetValue(prop, null); Assert.AreEqual(int.MinValue, test); } timer.Stop(); double reflectionDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS); double reflectionRatio = reflectionDuration / directAccessDuration; #endregion #region ReflectionInvokeMember (slowest) GC.Collect(); GC.WaitForPendingFinalizers(); timer.Start(); for (int i = 0; i < TEST_ITERATIONS; i++) { test = -1; test = (int)type.InvokeMember("Int", BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Instance, null, prop, null); Assert.AreEqual(int.MinValue, test); } timer.Stop(); double reflectionInvokeMemberDuration = 1000000 * (timer.Duration / (double)TEST_ITERATIONS); double reflectionInvokeMemberRatio = reflectionInvokeMemberDuration / directAccessDuration; #endregion // Print results Console.WriteLine("{0} property gets on integer...", TEST_ITERATIONS); Console.WriteLine("Direct access: \t\t{0} ", directAccessDuration.ToString("F3")); Console.WriteLine("IMemberAccessor: \t\t{0} Ratio: {1}", propertyAccessorDuration.ToString("F3"), propertyAccessorRatio.ToString("F3")); Console.WriteLine("IBatisNet ReflectionInfo: \t{0} Ratio: {1}", reflectionInfoDuration.ToString("F3"), reflectionInfoRatio.ToString("F3")); Console.WriteLine("ReflectionInvokeMember: \t{0} Ratio: {1}", reflectionInvokeMemberDuration.ToString("F3"), reflectionInvokeMemberRatio.ToString("F3")); Console.WriteLine("Reflection: \t\t\t{0} Ratio: {1}", reflectionDuration.ToString("F3"), reflectionRatio.ToString("F3")); }