Exemple #1
0
        //TODO: make this class internal (update all references in mobileezy)!!!

        public DelegateMemberAccessor(string memberName, bool readOnly = false, IObjectCache <string> memberCache = null)
            : base(
                RuntimeDelegateFactory.RetrieveMemberGetValueDelegate <TObjectType, TMemberType>(memberName, memberCache),
                readOnly ? null : RuntimeDelegateFactory.RetrieveMemberSetValueDelegate <TObjectType, TMemberType>(memberName, memberCache),
                true)
        {
            MemberName = memberName;
        }
        private static void InitPropertyAccessors()
        {
            var members = GetOrderedMembers();

            s_getters = new Func <T, object> [members.Length];
            s_setters = new Action <T, object> [members.Length];
            s_nameIdx = new Dictionary <string, int>();

            for (int i = 0; i < members.Length; i++)
            {
                s_getters[i] = RuntimeDelegateFactory.RetrieveMemberGetValueDelegate <T, object>(members[i].Name, EmptyObjectCache <string> .Instance);
                s_setters[i] = RuntimeDelegateFactory.RetrieveMemberSetValueDelegate <T, object>(members[i].Name, EmptyObjectCache <string> .Instance);
                s_nameIdx.Add(members[i].Name, i);
            }
        }
Exemple #3
0
        public static dynamic Compile(CotMethod cotMethod, CancellationToken token = default)
        {
            var rndClass   = CodeSnippet.RandomString();
            var pageOfCode = CodeSnippet.GeneratePage(rndClass, new[] { cotMethod.ToString() }, out var refs);

            var errors = Roslyn.Compile(pageOfCode, refs, out var asm, token);

            if (errors.Length == 0)
            {
                var t = asm.GetType(rndClass);
                try
                {
                    var mn = cotMethod.Info.Name.ValueText;
                    var d  = RuntimeDelegateFactory.StaticMethod(t, mn);
                    return(d);
                }
                catch (ArgumentException)
                {
                    throw;
                }
            }
            throw new CompilationException(errors);
        }