Beispiel #1
0
        public AssignmentEntry(string name, AssignmentMember @from, AssignmentMember to)
        {
            Name = name;
            From = @from;
            To   = to;

            GetValueFn     = From.CreateGetter();
            SetValueFn     = To.CreateSetter();
            ConvertValueFn = TypeConverter.CreateTypeConverter(From.Type, To.Type);
        }
Beispiel #2
0
        public AssignmentEntry(string name, AssignmentMember @from, AssignmentMember to)
        {
            this.Name = name;
            this.From = @from;
            this.To   = to;

            this.GetValueFn     = this.From.CreateGetter();
            this.SetValueFn     = this.To.CreateSetter();
            this.ConvertValueFn = TypeConverter.CreateTypeConverter(this.From.Type, this.To.Type);
        }
 public FieldAccessor(
     FieldInfo fieldInfo,
     GetMemberDelegate publicGetter,
     SetMemberDelegate publicSetter,
     SetMemberRefDelegate publicSetterRef)
 {
     FieldInfo       = fieldInfo;
     PublicGetter    = publicGetter;
     PublicSetter    = publicSetter;
     PublicSetterRef = publicSetterRef;
 }
        static IdUtils()
        {
#if !SL5 && !IOS && !XBOX
#if NETSTANDARD2_0
            var hasIdInterfaces = typeof(T).GetTypeInfo().ImplementedInterfaces.Where(t => t.GetTypeInfo().IsGenericType &&
                                                                                      t.GetTypeInfo().GetGenericTypeDefinition() == typeof(IHasId <>)).ToArray();
#else
            var hasIdInterfaces = typeof(T).FindInterfaces(
                (t, critera) => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IHasId <>), null);
#endif
            if (hasIdInterfaces.Length > 0)
            {
                CanGetId = HasId <T> .GetId;
                return;
            }
#endif

            if (typeof(T).IsClass || typeof(T).IsInterface)
            {
                foreach (var pi in typeof(T).GetPublicProperties()
                         .Where(pi => pi.AllAttributes <Attribute>()
                                .Any(attr => attr.GetType().Name == "PrimaryKeyAttribute")))
                {
                    CanGetId = pi.CreateGetter <T>();
                    return;
                }

                var piId = typeof(T).GetIdProperty();
                if (piId?.GetGetMethod(nonPublic: true) != null)
                {
                    CanGetId = HasPropertyId <T> .GetId;
                    return;
                }
            }

            if (typeof(T) == typeof(object))
            {
                CanGetId = x =>
                {
                    var piId = x.GetType().GetIdProperty();
                    if (piId?.GetGetMethod(nonPublic: true) != null)
                    {
                        return(x.GetObjectId());
                    }

                    return(x.GetHashCode());
                };
                return;
            }

            CanGetId = x => x.GetHashCode();
        }
Beispiel #5
0
        public EntityPropertyAccessor()
        {
            var allProperties  = typeof(T).GetAllProperties();
            var nodeIdProperty = allProperties.SingleOrDefault(p => p.HasAttributeNamed(nameof(NodeIdAttribute)));

            if (nodeIdProperty == null)
            {
                return;
            }

            nodeIdPropertySetter = nodeIdProperty.CreateSetter();
            nodeIdPropertyGetter = nodeIdProperty.CreateGetter();
        }
Beispiel #6
0
        public PocoDataSource(IEnumerable <T> items, long nextIdSequence = 0)
        {
            this.items      = new List <T>(items);
            this.idSequence = nextIdSequence;

            var checkPropExists = typeof(T).GetProperty("Id");

            if (checkPropExists == null)
            {
                throw new ArgumentException($@"{typeof(T).Name} does not have an Id property", nameof(items));
            }

            idProp       = checkPropExists;
            idGetter     = idProp.CreateGetter <T>();
            idSetter     = idProp.CreateSetter <T>();
            defaultValue = idProp.PropertyType.GetDefaultValue();
        }
Beispiel #7
0
            public void SetValue(object instance, object value)
            {
                if (SetValueFn == null)
                {
                    return;
                }

                if (Type != typeof(object))
                {
                    if (value is IEnumerable <KeyValuePair <string, object> > dictionary)
                    {
                        value = dictionary.FromObjectDictionary(Type);
                    }

                    if (!Type.IsInstanceOfType(value))
                    {
                        lock (this)
                        {
                            //Only caches object converter used on first use
                            if (ConvertType == null)
                            {
                                ConvertType    = value.GetType();
                                ConvertValueFn = TypeConverter.CreateTypeConverter(ConvertType, Type);
                            }
                        }

                        if (ConvertType.IsInstanceOfType(value))
                        {
                            value = ConvertValueFn(value);
                        }
                        else
                        {
                            var tempConvertFn = TypeConverter.CreateTypeConverter(value.GetType(), Type);
                            value = tempConvertFn(value);
                        }
                    }
                }

                SetValueFn(instance, value);
            }
Beispiel #8
0
 public TypePropertyWriter(Type propertyType, string propertyName, string propertyDeclaredTypeName, string propertyNameCLSFriendly,
                           string propertyNameLowercaseUnderscore, int propertyOrder, bool propertySuppressDefaultConfig, bool propertySuppressDefaultAttribute,
                           GetMemberDelegate <T> getterFn, WriteObjectDelegate writeFn, object defaultValue,
                           Func <T, bool> shouldSerialize,
                           Func <T, string, bool?> shouldSerializeDynamic,
                           bool isEnum)
 {
     this.PropertyType  = propertyType;
     this.propertyName  = propertyName;
     this.propertyOrder = propertyOrder;
     this.propertySuppressDefaultConfig    = propertySuppressDefaultConfig;
     this.propertySuppressDefaultAttribute = propertySuppressDefaultAttribute;
     this.propertyReferenceName            = propertyDeclaredTypeName + "." + propertyName;
     this.propertyNameCLSFriendly          = propertyNameCLSFriendly;
     this.propertyNameLowercaseUnderscore  = propertyNameLowercaseUnderscore;
     this.GetterFn               = getterFn;
     this.WriteFn                = writeFn;
     this.DefaultValue           = defaultValue;
     this.shouldSerialize        = shouldSerialize;
     this.shouldSerializeDynamic = shouldSerializeDynamic;
     this.isEnum = isEnum;
 }
Beispiel #9
0
        static IdUtils()
        {
            var memberInfo      = typeof(T);
            var hasIdInterfaces =
                memberInfo.FindInterfaces((t, criteria) => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IHasRedisId <>), null);

            if (hasIdInterfaces.Length > 0)
            {
                CanGetId = HasId <T> .GetId;
                return;
            }

            if (memberInfo.IsClass || memberInfo.IsInterface)
            {
                var piId = memberInfo.GetIdProperty();
                if (piId?.GetGetMethod(true) != null)
                {
                    CanGetId = HasPropertyId <T> .GetId;
                    return;
                }
            }

            if (memberInfo == typeof(object))
            {
                CanGetId = x => {
                    var piId = x.GetType().GetIdProperty();
                    if (piId?.GetGetMethod(true) != null)
                    {
                        return(x.GetObjectId());
                    }

                    return(x.GetHashCode());
                };
                return;
            }

            CanGetId = x => x.GetHashCode();
        }
Beispiel #10
0
        static IdUtils()
        {
            if (typeof(T).IsClass || typeof(T).IsInterface)
            {
                foreach (var pi in typeof(T).GetPublicProperties()
                         .Where(pi => pi.AllAttributes <Attribute>()
                                .Any(attr => attr.GetType().Name == "PrimaryKeyAttribute")))
                {
                    CanGetId = pi.CreateGetter <T>();
                    return;
                }

                var piId = typeof(T).GetIdProperty();
                if (piId?.GetGetMethod(nonPublic: true) != null)
                {
                    CanGetId = HasPropertyId <T> .GetId;
                    return;
                }
            }

            if (typeof(T) == typeof(object))
            {
                CanGetId = x =>
                {
                    var piId = x.GetType().GetIdProperty();
                    if (piId?.GetGetMethod(nonPublic: true) != null)
                    {
                        return(x.GetObjectId());
                    }

                    return(x.GetHashCode());
                };
                return;
            }

            CanGetId = x => x.GetHashCode();
        }
Beispiel #11
0
        static HasPropertyId()
        {
            var pi = typeof(TEntity).GetIdProperty();

            GetIdFn = pi.CreateGetter <TEntity>();
        }
 public OrderByExpression(string fieldName, GetMemberDelegate fieldGetter, bool orderAsc = true)
     : this(new[] { fieldName }, new[] { fieldGetter }, new[] { orderAsc })
 {
 }
Beispiel #13
0
        static HasPropertyId()
        {
            var pi = typeof(TEntity).GetIdProperty();

            _getIdFn = CreateGetter <TEntity>(pi);
        }
        private void combobox_team_SelectedValueChangedAll(object sender, EventArgs e) {
        
            try {
            
                AddMemberForm addMemberForm = ChatUtils.GetParentAddMemberForm((ComboBox)sender);
                ComboBox box = addMemberForm.combobox_team;
                ListBox addbox = addMemberForm.AddListBox;
                string teamname = (String)box.SelectedItem;
                if (teamname == "기타") teamname = "";
                GetMemberDelegate getmember = new GetMemberDelegate(ChatUtils.GetMember);
                Hashtable memTable = (Hashtable)Invoke(getmember, new object[] { treesource, teamname });
                int num = box.Parent.Controls.Count;

                ListBox listbox = addMemberForm.CurrInListBox;

                listbox.Items.Clear();
                foreach (DictionaryEntry de in memTable) {

                    string tempid = (String)de.Key;
                    
                    UserObject userObj = ChatUtils.FindUserObjectTagFromTreeNodes(memTree.Nodes, tempid);
                    ListBoxItem item = new ListBoxItem(userObj);
                    
                    if (ListBox.NoMatches == addbox.FindStringExact(item.Text)) {
                        listbox.Items.Add(item);
                    }
                }
            } catch (Exception exception) {
                logWrite(exception.ToString());
            }
        }
Beispiel #15
0
 public static void Id(GetMemberDelegate <T> getIdFn)
 {
     IdUtils <T> .CanGetId = getIdFn;
 }