예제 #1
0
        internal static object ProcessRecord(RecordOperationType operation, IRecordOperationContext context)
        {
            var key = new RecordProcessKey(context.RecordName, operation);

            if (!RecordProcessingDefinitions.ContainsKey(key))
            {
                throw new ArgumentException($"Unrecognized record operation: {key}");
            }

            return(RecordProcessingDefinitions[key].Invoke(null, new object[] { context }));
        }
예제 #2
0
        static RawUtils()
        {
            var types = typeof(RawUtils).Assembly.GetTypes();

            {
                var q = from type in types
                        let typeAttribute = (HandlesSubRecord)Attribute.GetCustomAttribute(type, typeof(HandlesSubRecord))
                                            where typeAttribute != null

                                            from method in type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic)
                                            let methodAttribute = (HandlesOperation)Attribute.GetCustomAttribute(method, typeof(HandlesOperation))
                                                                  where methodAttribute != null
                                                                  select new { typeAttribute, methodAttribute, method }
                ;

                foreach (var val in q)
                {
                    var key = new SubRecordProcessKey(val.typeAttribute.RecordName, val.typeAttribute.SubRecordName, val.methodAttribute.SubRecordOperation);
                    if (SubRecordProcessingDefinitions.ContainsKey(key))
                    {
                        throw new InvalidOperationException($"Ambiguous Handler: {key}");
                    }

                    SubRecordProcessingDefinitions.Add(key, val.method);
                }
            }

            {
                var q = from type in types
                        let typeAttribute = (HandlesRecord)Attribute.GetCustomAttribute(type, typeof(HandlesRecord))
                                            where typeAttribute != null

                                            from method in type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic)
                                            let methodAttribute = (HandlesOperation)Attribute.GetCustomAttribute(method, typeof(HandlesOperation))
                                                                  where methodAttribute != null
                                                                  select new { typeAttribute, methodAttribute, method }
                ;

                foreach (var val in q)
                {
                    var key = new RecordProcessKey(val.typeAttribute.RecordName, val.methodAttribute.RecordOperation);
                    if (RecordProcessingDefinitions.ContainsKey(key))
                    {
                        throw new InvalidOperationException($"Ambiguous Handler: {key}");
                    }

                    RecordProcessingDefinitions.Add(key, val.method);
                }
            }
        }