Пример #1
0
        protected virtual void ApplyProvider(object value, TypeProvider typeProvider)
        {
            if (typeProvider.Parent != null)
            {
                ApplyProvider(value, typeProvider.Parent);
            }

            var members = typeProvider.GetByAttribute <InjectAttribute>(true);

            if (members != null)
            {
                foreach (var member in members)
                {
                    var kind = member.Kind;
                    if ((kind & MemberKind.Field) == MemberKind.Field ||
                        (kind & MemberKind.Property) == MemberKind.Property)
                    {
                        var provider = GetProvider(member.ProviderType, true);
                        if (provider != null)
                        {
                            if (member.ProviderType != member.Type)
                            {
                                member.SetValue(value, CreateLazy(provider, member.Type, member.ProviderType));
                            }
                            else
                            {
                                member.SetValue(value, provider.Apply(this, member.Type));
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void ApplyPostInject(object target, TypeProvider provider)
        {
            var methods = provider.GetByAttribute <PostInjectAttribute>(MemberKind.Method, true);

            if (methods != null)
            {
                foreach (var method in methods)
                {
                    method.Apply(target, target.GetType(), this);
                }
            }
        }