Metaprogramming in C#: Automate your .NET development and simplify overcomplicated code 1st Edition Einar Ingebrigtsen pdf download
Metaprogramming in C#: Automate your .NET development and simplify overcomplicated code 1st Edition Einar Ingebrigtsen pdf download
NET
development and simplify overcomplicated code
1st Edition Einar Ingebrigtsen pdf download
https://ebookmeta.com/product/metaprogramming-in-c-automate-your-
net-development-and-simplify-overcomplicated-code-1st-edition-
einar-ingebrigtsen/
https://ebookmeta.com/product/boost-c-application-development-
cookbook-second-edition-recipes-to-simplify-your-application-
development-antony-polukhin/
https://ebookmeta.com/product/the-art-of-clean-code-best-
practices-to-eliminate-complexity-and-simplify-your-life-1st-
edition-christian-mayer/
https://ebookmeta.com/product/tableau-for-business-users-learn-
to-automate-and-simplify-dashboards-for-better-decision-making-
shankar-arul/
https://ebookmeta.com/product/the-safety-professionals-handbook-
second-edition-volume-2-technical-applications-joel-m-haight/
Resisting the Rule of Law in Nineteenth-Century Ceylon:
Colonialism and the Negotiation of Bureaucratic
Boundaries 1st Edition James S. Duncan
https://ebookmeta.com/product/resisting-the-rule-of-law-in-
nineteenth-century-ceylon-colonialism-and-the-negotiation-of-
bureaucratic-boundaries-1st-edition-james-s-duncan/
https://ebookmeta.com/product/snow-storm-winter-warmers-1st-
edition-cassie-mint/
https://ebookmeta.com/product/antjie-krog-and-the-post-apartheid-
public-sphere-speaking-poetry-to-power-1st-edition-anthea-garman/
https://ebookmeta.com/product/tokyo-travel-guide-lonely-planet-
rebecca-milner-simon-richmond/
https://ebookmeta.com/product/stereochemistry-a-three-
dimensional-insight-1st-edition-anil-v-karnik/
Achieving Procreation 1st Edition Merve Demircio■lu
Göknar
https://ebookmeta.com/product/achieving-procreation-1st-edition-
merve-demircioglu-goknar/
Metaprogramming in C#
Einar Ingebrigtsen
BIRMINGHAM—MUMBAI
Metaprogramming in C#
Copyright © 2023 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted
in any form or by any means, without the prior written permission of the publisher, except in the case
of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express
or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable
for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and
products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot
guarantee the accuracy of this information.
ISBN 978-1-83763-542-9
www.packtpub.com
Contributors
I want to thank everyone who has been patient with me while writing this book, especially my wife,
Anne Grethe, and my two kids, Mia and Herman. It has taken up a lot of my spare time to get this
done. I also want to thank everyone at Packt who has been part of the project, giving me pointers and
guidance throughout the process. It’s been absolutely invaluable.
About the reviewer
Marius Iulian Mihailescu is an associate lecturer at Spiru Haret University and co-founder/chief
research officer at Dapyx Solution, Bucharest, Romania. His work is focused on applied/theoretical
cryptography and information security, dealing with the identification process of threats and
vulnerabilities using artificial intelligence and machine learning. He is currently also working as an IT
project manager at the Institute for Computers, Romania, where he is responsible for the development
process of several projects.
His research interests are extended to areas such as computer vision, biometrics, machine learning,
artificial intelligence, and deep learning. The goal of his research is focused on understanding the
real requirements of complex systems (cloud computing, big data, IoT, etc.) and their applications in
different domains (such as computer forensics, behavioral psychology, and financial derivatives), and
to provide real and practical solutions for guaranteeing the Confidentiality, Integrity, and Availability
(CIA) of the processes.
Marius completed his Ph.D. studies in computer science on improving the security techniques for
guaranteeing the confidentiality and integrity of the biometrics data at the Faculty of Mathematics
and Computer Science at the University of Bucharest, Romania. During this time, he was also a part-
time research associate for the ATHOS (short for, Automated System of Authentication through
Biometric Signature) project from S.C. Softwin S.R.L., where he worked on improving the load
balancing mechanisms in a parallel computing system.
Table of Contents
Prefacexi
2
Metaprogramming Concepts 13
Technical requirements 13 Creating custom attributes 19
Implicit – using what is already there 14 Domain-specific languages 21
Leveraging the power of reflection 15 Gherkin – technical sample 22
Explicit – additional adornment Summary24
of code 18
3
Demystifying through Existing Real-World Examples 25
Technical requirements 25 Prerequisites for your system 26
vi Table of Contents
5
Leveraging Attributes 55
Technical requirements 55 Finding types with specific attributes 60
What is an attribute and how can it be Personal Identifiable Information (PII) 60
applied?55 Generic attributes 64
Limiting attribute usage 57
Summary66
Sealing your attribute class 59
6
Dynamic Proxy Generation 67
Technical requirements 67 Virtual members and overrides 74
An introduction to IL and Implementing an interface 75
Reflection.Emit67 NotifyObjectWeaver class 77
Creating a dynamic assembly Summary88
and module 68
Table of Contents vii
7
Reasoning about Expressions 89
Technical requirements 89 Traversing an expression tree 95
What are expressions? 90 Using expressions as descriptors of
Expression92 members on types 98
Lambda expression 94 Summary101
8
Building and Executing Expressions 103
Technical requirements 103 Creating a query engine 106
Creating your own expressions 104 A MongoDB-like database 107
Creating expressions as delegates and Building a simple query engine 108
executing them 105 Summary115
9
Taking Advantage of the Dynamic Language Runtime 117
Technical requirements 117 Reasoning about a dynamic type 121
Understanding the DLR 118 Creating DynamicObject and
The CLR at a glance 118 providing metadata 124
The DLR building blocks 119 Building a JSON schema type 125
Call sites and binders 121
Summary133
11
Applying the Open-Closed Principle 161
Technical requirements 162 Practical use case 167
Encapsulating type discovery 163 Helping the developer 170
Encapsulating the discovery of Supporting properties 172
instances165 Using the GDPR infrastructure 174
Adding more providers 178
Hooking up with the service collection 166
Summary180
12
Go Beyond Inheritance 181
Technical requirements 181 Using the infrastructure 194
Method signature conventions 181 Summary198
Infrastructure185
13
Applying Cross-Cutting Concerns 199
Technical requirements 199 CommandResult203
What are cross-cutting concerns? 200 Authorization based on metadata or
Leveraging the ASP.NET pipeline 201 structure212
Building consistent result objects 201 Summary223
14
Aspect-Oriented Programming 225
Technical requirements 225 What is AOP? 225
Table of Contents ix
16
Generating Code 269
Technical requirements 270 not just C# code 288
Generating additional code for the Building the generator 289
Roslyn compiler 270 Improving the developer experience 294
ASTs270
Debugging294
Application metrics 271
Optimization295
Improving the developer experience 275
Summary295
(Ab)using the compiler to generate
x Table of Contents
17
Static Code Analysis 297
Technical requirements 298 Trying out the analyzer 305
What is static code analysis? 298 How to write a code fix for an analyzer307
How to write an analyzer 299 How to write automated tests 310
Fleshing out an analyzer 299 Analyzer tests 311
Handling the syntax nodes 302
Release tracking 303
Code fix tests 313
Summary315
18
Caveats and Final Words 317
Performance implications 317 When to use what 319
Hidden magic – handle with care 318 Summary320
Index321
– Martin Golding
In the world of software, there are so many things that can go wrong and often do go wrong. We’re
a relatively young industry that is in an ever-changing state. Things haven’t settled and innovation
happens at lightning speed. It’s not like carpentry, which has had a few thousand years of experience
of what works and what doesn’t. In software, we’re still inventing the tools and reinventing them as
we go. The business benefit and the possibility to increase productivity for our end users sets the
expectations high and in an increasingly competitive market, time to market is of the essence.
At the level we write our software today, we have a huge potential to leverage the metadata surrounding
our own code to ensure the quality and maintainability of the software we write. This is where the
metaprogramming journey starts.
Metaprogramming can be really fun to work with, but it represents true opportunities for developers and
businesses to set themselves apart. Things that metaprogramming can do for you include the following:
There are technical reasons to dive into metaprogramming, as with any other technique, but I think
there is true value to be discovered in leveraging it to help you and your team become more productive
and, at the end of the day, deliver more business-critical features that are easier to change and maintain
over the years.
• Developers who are familiar with C# and .NET as a runtime looking to expand their horizons
and learn in more depth about the .NET runtime and compiler capabilities
• Software architects familiar with C# and .NET and looking for inspiration on how to improve
their architecture
xii Preface
• CTOs or development managers with either a developer background or who understand software
development and want inspiration to potentially grease the wheels of the developer organization
Chapter 13, Applying Cross-Cutting Concerns, unlocks the concept of applying code consistently across
an entire code base without having to revert to manual recipes.
Chapter 14, Aspect-Oriented Programming, provides details on the formalization of aspect-oriented
programming and how this can help you provide cross-cutting concerns as a more formal technique.
Chapter 15, Roslyn Compiler Extensions, details the basics of what the .NET compiler SDK offers and
how to get started with it, serving as the basis for the following chapters.
Chapter 16, Generating Code, provides an introduction to how you can generate code using code
at the compiler level before you enter runtime – yet another great way to improve your developers’
productivity and provide consistency in your code base.
Chapter 17, Static Code Analysis, provides an introduction to how you can build your own rules that
perform analysis on any code being added to your project, helping you create consistent, uniform,
and more maintainable code.
Chapter 18, Caveats and Final Words, looks into what the book has covered, what benefits there are,
and what caveats there are. As with anything, you have to strike the right balance and know what to
use when.
If you are using the digital version of this book, we advise you to type the code yourself or access
the code from the book’s GitHub repository (a link is available in the next section). Doing so will
help you avoid any potential errors related to the copying and pasting of code.
Conventions used
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file
extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “The
provider looks for ConfidentialAttribute to decide whether it can provide.”
A block of code is set as follows:
namespace Fundamentals.Compliance;
public interface ICanProvideComplianceMetadataForType
{
bool CanProvide(Type type);
ComplianceMetadata Provide(Type type);
}
Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words
in menus or dialog boxes appear in bold. Here is an example: “Then select JSON in the Body tab, add
an empty JSON document, and click Send.”
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at customercare@
packtpub.com and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen.
If you have found a mistake in this book, we would be grateful if you would report this to us. Please
visit www.packtpub.com/support/errata and fill in the form.
Exploring the Variety of Random
Documents with Different Content
ARCHAG’S FIRST TROUSERS
For several weeks the boys talked of nothing but the arrival of Monsieur
Bernier, their future French teacher. One morning the president received a
telegram from Aleppo announcing the arrival of the young man that same
evening, and by way of doing him honor, Dr. Mills gave all the classes a
half-holiday. The Sophomores were talking of their new professor:
“You little fool,” muttered Dikran, “you may depend upon it that no man of
experience would leave Europe to come out and bury himself in a hole like
this; I bet he’s a greenhorn with just five hairs on his chin.”
“I’ve seen his photograph,” announced Aram, with the air of a judge
revealing a state secret.
“This morning I was in the president’s office to show him the pensum he
gave me yesterday; I was looking around at his books and his desk, and
there I stopped, as I noticed a photograph half hidden by a pile of letters. I
peeped, I stood an tiptoe, but couldn’t manage to see a thing. All at once
Mrs. Mills called out, ‘Dearie, come and get a piece of cake.’ Dearie didn’t
wait to be called twice. ‘Wait here for me a moment,’ said he, ‘some one is
calling me,’ and as soon as he had closed the door I pounced on the
photograph. It was the picture of a nice, slender young man, and he had
written at the top: Henri Bernier. I had barely time to put it back before the
president came back.”
The boys quite envied Aram for having seen the new master before his
arrival, and since they had the afternoon free they decided to go out and
meet him in a body. Aram was the only dissenter:
“Oh, no! I shan’t go; I shall see him soon enough. I haven’t time, anyhow;
Garabed and I are going to town with Archag to help him choose a suit of
clothes.”
“Do you hear that?” whispered Dikran in his cousin’s ear. “The young
savage is getting civilized; not a bad idea. He won’t disgrace us all, next
time we are invited to the president’s house.”
Aram and his two friends went to ask Badvili Melikian for passes (the boys
were not allowed to leave the campus without a written permission); then
they went off whistling, on their way to the bazaar.
First they went into a haberdasher’s shop to buy stiff collars and a necktie.
“The green one,” he said, “is very distingué; but Dikran has a red one that
his brother brought home from Beyrout, and he’s just stuck on it. He
declares you can’t find anything like it here; it will be an awful blow to him
if you buy one.”
“If I were you, I should take this pale blue one, then you will be wearing the
Armenian color,” and he pointed to a cravat of coarse silk and cotton.
Before the beauty of this sky-blue tie, the charms of the two others paled.
“It’s that or none,” said Archag to himself.
But unfortunately, the shopkeeper asked a mejidieh (ninety cents) for it, a
fabulous price for a necktie. The three boys simultaneously uttered cries of
indignation, and turned to leave the shop.
“Eh, lá, lá, Effendis, not so fast! How much do you offer me?” It was now
the shopkeeper’s turn to be alarmed.
“Twelve piastres! you wish to ruin me then? A cravat that comes straight
from Vienna, and cost me three piastres duty! I will let you have it for
eighteen piastres.”
Finally, after twenty minutes of haggling and excited talk, Archag got his
famous necktie for fifteen piastres, and our three friends left the shop
radiant, escorted by the merchant, cringing and bowing repeatedly.
The tailor’s shop was only a few steps away. Archag, acting on his friend’s
advice, bought a suit of serge. He tried it on at once, and then looked at
himself in a mirror, surveying with great satisfaction his slender figure, his
snow-white collar and blue cravat, and as a finishing touch, a scarf-pin in
the shape of a four-leaf clover, the gift of his two friends. The merchant, his
clerks, Garabed and Aram all declared that the suit fitted him like a glove.
Archag, however, felt very much hampered by his trousers, which hit
against his legs at every step; his suspenders pulled, and his stiff collar
choked him, and he gave a sigh of envy as he looked at his flannel robe
lying on a chair. But he paid his bill of two pounds and a half, took his
zouboun on his arm, and went back to college with his companions.
THE ARABA
A party of students had gone out to meet Monsieur Bernier, and the others
were waiting for him on the campus. About fifteen minutes after Archag
and his friends had rejoined their mates, the sound of a carriage was heard
in the distance. “They are coming, they are coming!” called a voice, and
they all ran to the foot of the hill. Dr. Mills and Dr. Spencer, on horseback,
were at the head of the party; the boys, a few of them on bicycles, the
greater number on donkeys or walking, were crowding about the araba, a
peculiar sort of Turkish carriage used by travelers in the interior of Asia
Minor. It is a wagon without springs, having a hood of gray cloth; trunks
are fastened on anywhere, underneath, or at the sides of the vehicle. The
traveler lies on a mattress; he has a basket of provisions at hand, in which
he is likely to forage very often, to beguile the length of the journey.
Consider, dear reader, that the carriage-roads in Turkey are often little better
than country lanes, that it is sometimes necessary to drive across rivers and
marshes, or again, to follow rough, stony roads, and run the risk of being
attacked by brigands, and you will realize that a journey in an araba is no
pleasure trip. Monsieur Bernier had come from Alexandretta, and had spent
three days in his araba; he had been obliged to stay each night at a khan,
where he had been almost devoured by vermin; it was therefore a great
relief to him to find himself at last at his journey’s end.
As he got out of the araba he was hailed with shouts of welcome by the
boys:
“Hip, hip, hip, ra, ra, ra, hip ra ré, bomba, bomba, C. T. C. (Central Turkey
College).”
Monsieur Bernier had a passion for travel, and after pocketing his
university diploma, had set out for distant lands. He was very young, so
young that some of his own pupils, great bearded fellows of twenty, looked
older than he. He thanked the boys for their kind reception, and then
followed President Mills to the house in which he was to live. For a long
time he could hear from his room the “hip, hip, hip, ra, ra, ra,” shouted in
his honor, and these expressions of welcome so cheered him up that from
that first evening he felt a warm attachment for his pupils, which never
altered.
That evening, the Sophomores were in their study-hall as usual, in charge of
Mihran hodja, but as they had had a holiday in the afternoon, they were free
to do as they pleased. Most of them were reading. Archag, Aram, and two
of the Urfali were playing chess. Archag kept losing, and after a while gave
up, tired of his bad luck.
“I’ve had enough of that,” said he; “ask Samouīl to take my place.” Samouīl
agreed; he was a good player, but he found a formidable opponent in Aram,
and the group soon became very much excited. Archag watched them for a
moment, then went off to chat with Garabed in another corner of the room.
Nejib was sitting near them, absorbed in a book.
“Hi, there,” said Archag, “what are you buried in so deep? You haven’t
taken your eyes off your old book for the last hour.”
He drew near without ceremony, and read out the title of the book at the top
of his voice: “The Arabian Nights!”
If a thunderbolt had fallen in the hall the boys could hardly have been more
startled; they knew how severe Dr. Mills was upon any who read improper
stories; and “The Arabian Nights” had a terrible reputation at Aintab.
Profound silence followed Archag’s imprudent words; the boys dared not
breathe a syllable. Mihran hodja turned pale, went to Nejib and asked for
his book. The boy handed it to him without a word, but he was as white as a
ghost. The master turned over the leaves, hoping the book might prove to be
an expurgated edition, put it in his pocket with a sigh, and left the room.
When he had closed the door, Nejib flung himself upon Archag and gave
him a vigorous box on the ear.
Our friend tripped him up, and when his opponent was on the floor,
punched his chest. The boys had hard work to separate them, for they were
both very angry.
“As if I knew ‘The Arabian Nights’ was a forbidden book!” said Archag. “I
simply asked him what he was reading. Don’t be worried; I shan’t speak
another word to him.”
Nejib, for his part, insisted that Archag had done it on purpose, that he was
a spy and ought to be expelled from college.
Finally, peace was restored after a fashion. Archag’s anger cooled quickly,
and he thought no more about the matter. But Nejib did not forget. President
Mills gave him a punishment of three days on bounds, on bread and water,
together with a very bad conduct mark, and also wrote a letter of complaint
to Dr. Rossinian. The young fellow, who was quarrelsome by nature, then
merely waited for an opportunity to take his revenge.
CHAPTER VIII
AN ACCIDENT
Archag worked at his lessons with enthusiasm, and the days and weeks
passed very quickly. Most of the professors admired his earnestness and
intelligence, and were pleased with the progress he made, but unfortunately
he had failed to win the favor of Mr. Piralian, who continued to dislike him.
It must be confessed that Archag showed little interest in his English
lessons; he had never been willing to alter his pronunciation, for he
considered Miss Dobbie an excellent teacher, and since she said “auld” and
“gir-r-l”, of course that must be right. Therefore, he argued, Professor
Piralian was in the wrong and spoke incorrectly; he did not know how to
teach, and it was not worth while to work very hard. Our friend thus drew a
quantity of false conclusions, with the superb recklessness of youth. In his
Christmas reports he was marked “good,” and “very good” in everything
except English, in which he had only “medium”; but this made very little
impression upon him; he knew that he had not done good work, and did not
expect anything better. Garabed stood first in the class, then came Dikran
and Archag. Aram was fifth. Nejib, who had always been among the first,
stood only eighth because of his bad conduct mark.
The advent of the Christmas holidays was, of course, hailed by the boys
with shouts of joy. What great games they would play! What a jolly time
they were going to have during those two weeks! On New Year’s Day, the
Sophomores were invited to the house of Hosep Paelian, one of the day
pupils, and they had a delightful time with him.
At this point I hear my readers exclaim, “What! Christmas after New Year’s
Day? The world must certainly be upside-down over there!”
It does indeed seem odd to us to celebrate the birth of Jesus Christ in the
month of January. But the Gregorians use the Greek calendar, which is
twelve days later than ours. They keep Christmas on the Feast of the Three
Kings, the sixth day of January, that is, the eighteenth, New Style.
President Mills had a pine tree brought from Amanus, a mountain to the
west of Aintab. For several days the sun was hidden by snow-storms, and
this Oriental Christmas differed little from the same season in the North. In
the afternoon of Christmas Day, Professor Pagratian conducted a service in
the college chapel, after which masters and pupils gathered together for
dinner in the great dining-room.
The menu consisted of turkey with chestnuts, and a dessert of grapes and
oranges. The boys were little used to delicacies, especially to meat, and
their eyes shone with eagerness in anticipation of this feast of good things.
The professors were seated at different tables; Mihran hodja and Monsieur
Bernier sat with the Sophomores, one at either end of the table. The young
Swiss smiled as he looked at his plate, on which were large slices of turkey,
pilaaf (rice), and chestnuts, arranged in the form of a tower. Oriental usage
requires that the plates be filled to the extent of their capacity, but it is very
bad form not to leave a considerable part of what has been given, or one is
set down as a gourmand.
The tree had been lighted in the study hall; the Seniors had decorated it with
cotton-wool, oranges, apples and gilded nuts, and had laid out the presents
on tables. The boys sang a hymn in English; then they made haste to open
their parcels, and before long every one was engrossed with his own gifts.
Archag received one Turkish pound (about four dollars and a half) from his
parents, a book from his sister and another from Garabed, and Aram’s
photograph. Dikran was manipulating a microscope which his brother had
sent him from New York. Boghos had a kodak from America, which he was
showing with pride to his friend Soghomon. No one had been forgotten; for
the less fortunate boys whose parents had not been able to send them
anything, Mrs. Mills had provided remembrances. After all the presents had
been duly admired, the boys put them aside, to play games. At ten o’clock,
tea and caghkés (little cakes) were served, and at length the boys went off to
their dormitories, very happy after their festival.
The next day, the weather was so cold that every one stayed indoors, and
Archag, after reading a little while, took a fancy to go upstairs to the
museum, which contained good specimens of the flora and fauna of the
country.
As the thermometer registered several degrees below zero, the furnace fire
was burning at full blast, and the air in the museum, already impregnated
with camphor and naphtha, was suffocating. Before long, Archag’s head
was burning; he threw open one of the windows near the door, and took a
good breath of fresh air. Then he returned to the cabinet and took out a glass
box containing the finest specimen of the Piralian collection. It was
beginning to grow dark, so he took the box to the window, which he had left
open. He stood looking at the marvelous insects with their iridescent wings
of blue and green and gold, and was amusing himself by trying to decipher
the Latin names, when he felt a smart blow on his arm. The force of the
sudden jar made him let go of the box, and down it fell with a crash, on the
stone pavement of the courtyard. For an instant Archag stood motionless
with fright; then he rushed into the corridor, where he heard a sound of
retreating footsteps. He went back to the museum, and looking from the
window he could see the shapeless fragments of the box down below. A ray
of hope flashed across his mind; could it be, perhaps, that the precious
insects had not been injured?
Running downstairs two steps at a time, the next moment he was in the
courtyard. Alas! the butterflies were ruined; most of them were reduced to
powder. In the face of this disaster Archag felt powerless, constrained by an
agony of fear. He could not bring himself to think of the thing he ought to
do, to go at once to Professor Piralian and tell him frankly what had
happened. His only thought was that he should be expelled from the
college. How dreadful, oh, how very dreadful!
He took up a book, but the words danced before his eyes, without
conveying the slightest meaning to his mind.
Garabed, seeing that he did not want to talk, asked no more questions.
Every time the door was opened, the culprit trembled: now, his misdeed had
been discovered, he thought, and some one was coming to question the
boys. His heart beat like a trip-hammer, and he felt as if he must suffocate.
The evening passed without any disturbance, but Archag had a restless
night; he kept dreaming that he had been sent away in disgrace, and his
classmates’ shouts of derisive laughter seemed to ring in his ears. Several
times he woke up with a start, to hear Garabed anxiously asking if he were
ill, and if he would like to have Badvili Melikian called. He would reply
impatiently that he did not need anything, and turn over on the other side.
The next morning, Dr. Mills came into the schoolroom before prayers,
looking very grave.
The president told them what had happened, and made the misdeed appear
very disgraceful. When he called on the guilty one to come forward and
acknowledge his fault, our friend rose mechanically and went to the desk.
“You! you!” repeated Dr. Mills. “A boy whom we have all loved! How can
you have done a thing like that? It can’t be possible!”
However, he led the culprit away to his office, and questioned him closely.
Archag confessed to opening the cabinet and taking the box of butterflies to
the window in order to see them better, but when he said that some one had
pushed him, his judge smiled incredulously. He called Badvili Melikian,
who assured him that, with the exception of Nejib who was in the city, none
of the Sophomores had left the study-hall that afternoon.
Archag had always been on good terms with his classmates, and it seemed
impossible that any one of them should have wanted to play him such a
trick. Dr. Mills questioned the boys again, but each gave the same reply: not
one of them had gone up to the museum that day. Indeed, the president
asked these questions merely to satisfy his own conscience; he was quite
convinced of Archag’s guilt. Professor Piralian had often complained of his
bad conduct and lack of application; he had just given him a “medium”
mark in English. It seemed therefore quite probable that Archag had
deliberately taken revenge on his teacher by destroying his collection.
All the professors assembled in the president’s room to talk the matter over,
and Dr. Mills laid Archag’s case before them at some length, and then
waited for their counsel. A painful silence followed; Armenians hate to give
an opinion outright; they prefer to evade the main question, and to prolong
their discussions without coming to any decision.
“I must say, that for my part, I have always found Archag loyal and
truthful.” A murmur of assent was heard from the other masters. “I have
watched him both in and out of study-hours, and it is my private opinion
that one of his classmates really did give him a push by way of revenge. I
have my own suspicions, too, as to that, which I shall do my utmost to
verify. The lad is diffident and awkward; he did wrong not to confess his
fault at once, but he made up for that by admitting his guilt before the
whole college. You will reply that he could not do otherwise, since Badvili
Melikian knew he was in the museum that afternoon. I do not admit that
argument; if he had meant to lie about it all, he would have denied the
whole or nothing. Let us punish him for his disobedience in handling the
collection; that was his only fault, and does not deserve expulsion from the
college.”
The professors discussed the matter at length; Monsieur Bernier and Badvili
Melikian agreed with Professor Pagratian; the others wished Archag to be
expelled.
“I don’t believe,” said the president, at last, “that we shall ever come to an
agreement. I suggest therefore that we leave the decision to Professor
Piralian, who is better able to judge than we.”
Meanwhile our friend was wandering about the campus like a lost soul. He
had gone off by himself, ashamed to let his grief be seen. Was he really
going to be expelled? All his pride revolted at the thought. He would
cheerfully take any punishment if only he might be spared this disgrace.
“Archag, Archag!”
“What is it?”
Archag entered the room where all the professors were seated around the
table.
“My friend,” said the president to him, “you have committed a serious fault
in touching the collection of butterflies after having been told not to do so.
The loss you have occasioned to our museum is irreparable. We are willing,
however, to take into consideration your youth and inexperience, as
extenuating circumstances, since you are just at the beginning of your
college career. You will have five days on bounds, and be marked zero for
conduct in your next report.”
“Oh! thank you, thank you, Machallah!” cried Archag. He kissed the
president’s hand again and again, then fled precipitately to hide the sobs
that stifled him.
CHAPTER IX
FRIENDS IN NEED
After the affair of the butterflies, the Sophomores held themselves
somewhat aloof from Archag, for they could not forgive him for saying that
one of them had pushed him. They all felt insulted by this accusation, and
believed him to be a hypocrite and a liar. One day, when Archag was about
to join a group at cards, Dikran got up, refusing to play with him. Garabed
was the only one who remained unchanged; he was firmly persuaded of his
friend’s innocence, and was always ready to cheer him up with a kind word
or look of sympathy. And indeed, Archag had need of it; he felt terribly
isolated, and was hurt by the silent condemnation of his classmates and
some of the professors. Up to this time he had been petted and flattered by
every one; now, fallen thus abruptly from his pedestal, he could not
accustom himself to his unhappy circumstances.
“I was just wondering what had become of you; it is a long time since I
have seen you. I am going to the hospital, and you must walk on a little way
with me; you will tell me what is weighing on your heart, won’t you?”
Archag could not refuse; his questioner looked at him with such a kind
smile.
“You have had a hard trial,” she continued, “but still, you mustn’t lose
courage; you will see that everything will be cleared up by and by; as for
me, I have never believed you guilty of a falsehood. Don’t let yourself be
crushed by misfortune; this is probably your first experience. Ah, well! Bear
it like a man. Redouble your efforts to do away with the bad impression you
have made on some of your teachers; above all, show yourself obedient and
docile toward Professor Piralian; make an extra effort to please him.”
“He hates me,” Archag could not help saying, “he shows it in all sorts of
ways.”
“What nonsense you are talking! If he had hated you, would he have asked
Dr. Mills to let you stay here? You have him to thank for not being
expelled.”
Archag was dumb with astonishment; the iron vise which had gripped his
heart for the last three weeks, was relaxing its hold; he was finding once
more a little of that sympathy in which he had no longer dared to believe.
With a lighter heart he took leave of the doctor’s wife, and went back to the
college whistling.
“You are entirely changed,” said Garabed on his return; “what has come
over you?”
“I’m happy to-day.” And he told his friend about the conversation with Mrs.
Spencer.
“You see,” replied Garabed, “the best people have kept their friendship for
you.”
Professor Pagratian also took a great interest in Archag, and often invited
him to his house with Garabed. What happy evenings those were for our
two friends! Mrs. Pagratian and her two daughters would mend a great pile
of linen, while the professor smoked his narguileh, and talked about his
youthful days of poverty and hardship. He did not remember his father; the
eldest of six children, he had been obliged to go to work while still very
young, in order to help his mother. At the age of eighteen he was a
journeyman weaver, earning a mejidié (ninety cents) a week. An American
missionary whom he met occasionally, gave him a copy of the New
Testament, and he used to read it privately with a companion of his named
Krikorian. The Epistles of Saint Paul made a deep impression upon these
young men, and then Dr. Trowbridge became interested in the two friends,
and used to pray with them and explain the Holy Scriptures.
“When he talked to us,” said the professor, “it was as if scales fell from our
eyes; we felt a horror of our sins, and a thirst for truth and righteousness....
One Christmas evening when Krikorian and I had been praying with more
than ordinary fervor, we seemed to hear Jesus Christ calling us. Our hearts
leaped for joy; that was the most beautiful day of our life, and we always
think of it with tears of gratitude. Dr. Trowbridge was at that time engaged
in laying the foundations of the college, and he proposed that we should fit
ourselves to become teachers in his school. I needn’t tell you how glad we
were to act on his suggestion. We spent four years in America, and then we
returned to work with our benefactor. Alas! God called him suddenly to
Himself. Such men are rare indeed, and his death was a very great loss to
Aintab.”
“In Switzerland,” he would say, “the people enjoy life; in America they do
business.”
When Monsieur Bernier spoke of the liberty of his compatriots, the poor
Armenians could not suppress a sigh of envy, and Mrs. Pagratian would
wipe away a secret tear, for she lived in constant dread of a fresh massacre.
These evenings were a blessed influence for Archag; he threw himself into
his work with new ardor.
“Something seems to have changed that boy entirely,” said Mr. Piralian to
Professor Pagratian. “I never could do anything with him before, but since
that famous affair of the butterflies he has grown polite, studious, and
attentive in class, whereas formerly he was always thinking about
something else. I actually believe I shall succeed in correcting his horrible
accent.”
“That would almost make up for the loss of your collection,” replied his
colleague, laughing.
“Yes; only if I had to gain the progress of each of my pupils at the cost of
one of my collections, I should soon be ruined!”
Archag, for his part, saw that Mr. Piralian no longer retained his former
prejudice against him, and he even came to like the English lessons. His
classmates, seeing that he was reinstated in the good graces of the masters,
left off tormenting him. But Archag still avoided them; he was constantly
with Garabed; they prepared their lessons together, and then went off on
long walks, exchanging ideas about every subject that came into their
heads. But their favorite topic of conversation was Armenia, so cruelly
oppressed and tried.
Archag had never thought very much about his country. He loved it, to be
sure, and pitied it, but that was all. Garabed, who was older and more
reflective by nature, made him feel ashamed of his ignorance. He showed
him Armenia, wasted by continual massacres, but yet alive; he described the
deplorable condition of their fellow-countrymen, the better and more
intelligent of whom had fled to America; he told him the story of the heroic
siege of Zeitoun—how the town held out for seven months against the
Turkish forces which had come to exterminate it; or again, of the great
achievements of Andranick1 the revolutionary leader, who had dared resist
the Kurds, and had been victorious.
Archag’s eyes were opened; as his love of country increased, it became the
central force in his life. Together the two boys studied the history of their
country, and took pleasure in speaking Armenian, although Garabed insisted
that they must always speak Turkish in the presence of the other boys. The
reason for this we shall see presently.
1 Andranick, a popular hero of song and story, and a revolutionary leader in Armenia
for the past thirty years. During the Great War, he organized Armenian troops and led them
against the Turks. Knowing the topography of the country so well, his troops were always
in the advance parties of the Russians with whom they were fighting. Andranick was
commissioned Major-General by the Russians and was six times decorated by them for
gallantry. He rescued and cared for thousands of Armenian refugees, who clung to his army
for months for protection; though they impeded his progress, he could not forsake them.
His career has been one of remarkable romance and adventure. At the present time,
January, 1920, it is said that he is the only person on whose head the Turks have set a price.
It is interesting to know that the hero of Archag and Aram is a real person of flesh and
blood, and has recently been here in the United States. He came as a member of the
Armenian Military Mission to plead with the American Government for help for stricken
Armenia, asking for military, financial and economic assistance, that his people might be
enabled to help themselves in the future.
An article about Andranick, with a photograph, appeared in the New York Evening Post,
November 29, 1919. ↑
CHAPTER X
THE ARMENIAN NATION
On half-holidays the boys were in the habit of going to town, to shop or to
visit their friends, and on a certain Saturday, in the month of February, they
had all gone off in various groups, and the college was deserted. Garabed
and Archag took advantage of the warm spring sunshine to climb one of the
hills which rise above the city toward the south. Here, seated on a
tombstone—these hills are covered with graves—they ate their frugal
luncheon of bread and cheese and olives, and when they had finished,
Garabed wiped his oily fingers, and drew from his zouboun a book wrapped
in newspaper.
“Djelaleddin!”
“Oh, Garabed, how splendid! How did you ever get hold of it? I’ve been
nearly wild myself, thinking I could never get a chance to read our great
Raffi.1
“Yes, the book has been forbidden by our Padishah (sultan) on pain of
imprisonment for life, and if Dr. Mills were to know that you had read it, he
would send you packing this very day. Are you surprised? You see Dr. Mills
has had to take oath before the Vali (governor) that he will not disseminate
the new ideas among us. Ali Pasha keeps watch, and if he should ever
discover that our college was a center of liberalism he would close it the
very next day. Now our president knows that, and he is very careful.”
“Listen to this passage, where Sarkat, returning from the towns, finds his
own village in flames: ‘After a march of several hours he perceived a red
light in the distance, becoming alternately brighter and fainter; now
shooting up in writhing flames, now motionless, the stream of fire, fed by
fresh fuel, spreading farther and farther.’ And this other bit: ‘When,’ thought
he, ‘the lamb is obliged to live near the wolf, it must try to make wolf’s
teeth of its own, that it may not become the other’s prey.’”
“Yes, Sarkat is right,” said he. “Why don’t we defend ourselves? Why don’t
we make a struggle for our independence? Look at the Serbians, the
Bulgarians, the Greeks; they have been fighting the Turks for years; Europe
has been thrilled with joy at the noble deeds of Canaris, and Kolokotronis
and Botsaris,2 and at last sent effective aid to the Hellenes. Let us do the
same.”
“But our people are ignorant, and stagnating in servitude; few of them know
the use of arms.”
“We, the young men, who have the strength and the faith for it.”
“Ah, my dear friend! I knew you would say that!” and Garabed grasped his
hand warmly.... “You are worthy of becoming one of us. Listen: other men
have had your thoughts. They have longed to arouse our people from their
lethargy, to teach them their duty and their value, so that when the accursed
Kurd shall sound the tocsin for fresh massacres, we shall not be taken
unaware as formerly, but be ready to conquer or die. Secret societies have
been formed; revolutionary groups have been organized in our towns, and
they get recruits among all classes of society. You will find fédaī
(revolutionaries) in the bazaar, in the fields, even in the serail, and in our
schools.”
“It’s a fact, though, and you can understand how cautious we have had to
be, to keep from being discovered. It has been so hard for me not to speak
of it to you, my best friend, but our chief forbade it; to-day he has given me
leave, and I’m going to ask you to join our group of fédaī.”
“With all my heart, my dear Garabed, and as soon as possible.”
“What time?”
Archag was full of enthusiasm; he felt that he had become a man, and a
worker for the good of his country. He hid the book under his zouboun, and
the two friends went down the hill, and made their way back to the college.
During study-hour Archag looked at the clock very often; he had equations
to solve, but the work did not go on well, for all the time he was thinking
over what Garabed had said. At last he closed his copy-book in vexation,
counting on finishing his task in the morning. It was only eight o’clock, and
he opened his English reading-book for the sake of appearances, for Badvili
Melikian had spoken to him several times already. At last the clock struck
the half-hour. The boys always had an hour for recreation before going to
bed, and most of them went to the library to read the newspapers and the
American magazines. Archag and Garabed ran downstairs to the hall where
Ghevont, president of the fédaī, was waiting for them. He was a silent,
reserved boy, but very intelligent, and always among the first in his class.
He came from Brousa, had lived in Cyprus and Jerusalem, and was
considered a person of consequence by his fellow students, because of his
numerous journeys by ship and rail.
The three boys went out of the building without saying a word. They went
toward the enclosure at the end of the campus, which was the burial-place
of missionaries who had died at Aintab, and there they sat down on an old
tombstone which had fallen over during the winter. Garabed kept watch,
while Ghevont read to Archag the demands of the society:
Archag repeated the oath in a low voice, kissed the crucifix, and made the
sign of the cross three times.
“Garabed,” said Ghevont, “will you admit Archag to our society? Will you
guarantee his good faith?”
“Yes.”
“Very well then, that being so, I dedicate you, Archag, a fédaī, by this
brotherly kiss.”
The first duty of the fédaī being to help their compatriots, according to their
means and ability, it was decided that Archag should go to town every
Saturday to conduct a class in Armenian for illiterate adults, at the school of
Sourp Nersès. Garabed himself was giving free instruction in English to
members of the Gregorian union.
The three boys were stirred by their common enthusiasm. Armenia seemed
to them like a bride, very fair and very pure, to whose service they were
dedicated in knightly fashion. Gazing into the starlit night, they saw their
country transformed and their people happy. Garabed began to sing softly
the March of the Dachnaktzoutioun (revolutionary society), and the voices
of the others joined him:
About six o’clock in the morning, one day toward the end of March, the
masters gave the signal for the start, and the boys sprang to their saddles.
They rode horses or donkeys. These donkeys of the East are strong,
vigorous animals, with bright eyes and glossy skin, and often rival the
horses in speed.
The sky was cloudless, the air pure, and fragrant with a thousand odors
from the plain; the fields, so bare in autumn, when parched by heat and
drought, had put on their bridal array of grass and flowers. The road ran
beside a stream bordered with laurel, roses and eglantine. After a ride of
three hours, the party came to the lower foothills of the mountain. The good
beasts went on bravely, picking their way among the rough stones and
fallen débris, never stumbling. The vegetation was marvelous; as far as eye
could see, stretched fields of narcissus, hyacinths, tulips and gladiolas.
Monsieur Bernier kept jumping off his horse every few moments to gather a
fresh handful of flowers.
The riders stopped near a well, to eat their luncheon; after tethering the
donkeys and horses to some plane-trees, every one proceeded to unpack his
food.
The gluttony of the fat boy was notorious; he now had twelve eggs spread
out on his knees, the sight of which sent his companions into fits of
laughter.
“Are you going to hatch them, or what?” asked the merciless Aram.
“Vaī bana (worse luck), I’m hungry,” he stammered at last, “and I always
have a good appetite.”
“Right you are, old man,” said Aram, “it seems to me you’ve been getting
thin lately.”
“Why not?” said Soghomon pettishly. “My father ate thirteen once.”
Soghomon was nettled by the jesting. He ate eight eggs easily, but the ninth
had a queer taste. At the tenth his stomach seemed to close; he stuck to it
however. Orientals adore betting, and his comrades put him on his mettle.
He ate the eleventh, then the twelfth! Nejib had lost.
It was so hot that the company unanimously agreed to take a siesta, and not
start on their way until four o’clock.... The muezzin was just telling the hour
of sunset as our cavalcade drew up at the village of Ibrahamli, where they
were to spend the night. Dr. Spencer had given Monsieur Bernier a letter of