-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathActivityXamlServices.cs
692 lines (593 loc) · 28 KB
/
ActivityXamlServices.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.XamlIntegration
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Xaml;
using System.Xml;
using System.Security;
using System.Security.Permissions;
using System.Xaml.Permissions;
using System.Activities.Expressions;
using System.Activities.Validation;
using System.Runtime;
using System.Diagnostics.CodeAnalysis;
using System.Text;
public static class ActivityXamlServices
{
static readonly XamlSchemaContext dynamicActivityReaderSchemaContext = new DynamicActivityReaderSchemaContext();
public static Activity Load(Stream stream)
{
if (stream == null)
{
throw FxTrace.Exception.ArgumentNull("stream");
}
return Load(stream, new ActivityXamlServicesSettings());
}
[SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver",
Justification = @"For the call to XmlReader.Create() below, CA3053 recommends setting the
XmlReaderSettings.XmlResolver property to either null or an instance of XmlSecureResolver.
But after setting this property to null, a warning of CA3053 still shows up in FxCop.
So we suppress this error until the reporting for CA3053 has been updated to fix this issue.")]
public static Activity Load(Stream stream, ActivityXamlServicesSettings settings)
{
if (stream == null)
{
throw FxTrace.Exception.ArgumentNull("stream");
}
if (settings == null)
{
throw FxTrace.Exception.ArgumentNull("settings");
}
using (XmlReader xmlReader = XmlReader.Create(stream, new XmlReaderSettings { XmlResolver = null }))
{
return Load(xmlReader, settings);
}
}
public static Activity Load(string fileName)
{
if (fileName == null)
{
throw FxTrace.Exception.ArgumentNull("fileName");
}
return Load(fileName, new ActivityXamlServicesSettings());
}
[SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver",
Justification = @"For the call to XmlReader.Create() below, CA3053 recommends setting the
XmlReaderSettings.XmlResolver property to either null or an instance of XmlSecureResolver.
But after setting this property to null, a warning of CA3053 still shows up in FxCop.
So we suppress this error until the reporting for CA3053 has been updated to fix this issue.")]
public static Activity Load(string fileName, ActivityXamlServicesSettings settings)
{
if (fileName == null)
{
throw FxTrace.Exception.ArgumentNull("fileName");
}
if (settings == null)
{
throw FxTrace.Exception.ArgumentNull("settings");
}
using (XmlReader xmlReader = XmlReader.Create(fileName, new XmlReaderSettings { XmlResolver = null }))
{
return Load(xmlReader, settings);
}
}
public static Activity Load(TextReader textReader)
{
if (textReader == null)
{
throw FxTrace.Exception.ArgumentNull("textReader");
}
return Load(textReader, new ActivityXamlServicesSettings());
}
[SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver",
Justification = @"For the call to XmlReader.Create() below, CA3053 recommends setting the
XmlReaderSettings.XmlResolver property to either null or an instance of XmlSecureResolver.
But after setting this property to null, a warning of CA3053 still shows up in FxCop.
So we suppress this error until the reporting for CA3053 has been updated to fix this issue.")]
public static Activity Load(TextReader textReader, ActivityXamlServicesSettings settings)
{
if (textReader == null)
{
throw FxTrace.Exception.ArgumentNull("textReader");
}
if (settings == null)
{
throw FxTrace.Exception.ArgumentNull("settings");
}
using (XmlReader xmlReader = XmlReader.Create(textReader, new XmlReaderSettings { XmlResolver = null }))
{
return Load(xmlReader, settings);
}
}
public static Activity Load(XmlReader xmlReader)
{
if (xmlReader == null)
{
throw FxTrace.Exception.ArgumentNull("xmlReader");
}
return Load(xmlReader, new ActivityXamlServicesSettings());
}
public static Activity Load(XmlReader xmlReader, ActivityXamlServicesSettings settings)
{
if (xmlReader == null)
{
throw FxTrace.Exception.ArgumentNull("xmlReader");
}
if (settings == null)
{
throw FxTrace.Exception.ArgumentNull("settings");
}
using (XamlXmlReader xamlReader = new XamlXmlReader(xmlReader, dynamicActivityReaderSchemaContext))
{
return Load(xamlReader, settings);
}
}
public static Activity Load(XamlReader xamlReader)
{
if (xamlReader == null)
{
throw FxTrace.Exception.ArgumentNull("xamlReader");
}
return Load(xamlReader, new ActivityXamlServicesSettings());
}
public static Activity Load(XamlReader xamlReader, ActivityXamlServicesSettings settings)
{
if (xamlReader == null)
{
throw FxTrace.Exception.ArgumentNull("xamlReader");
}
if (settings == null)
{
throw FxTrace.Exception.ArgumentNull("settings");
}
DynamicActivityXamlReader dynamicActivityReader = new DynamicActivityXamlReader(xamlReader);
object xamlObject = XamlServices.Load(dynamicActivityReader);
Activity result = xamlObject as Activity;
if (result == null)
{
throw FxTrace.Exception.Argument("reader", SR.ActivityXamlServicesRequiresActivity(
xamlObject != null ? xamlObject.GetType().FullName : string.Empty));
}
IDynamicActivity dynamicActivity = result as IDynamicActivity;
if (dynamicActivity != null && settings.CompileExpressions)
{
Compile(dynamicActivity, settings.LocationReferenceEnvironment);
}
return result;
}
[SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver",
Justification = @"For the call to XmlReader.Create() below, CA3053 recommends setting the
XmlReaderSettings.XmlResolver property to either null or an instance of XmlSecureResolver.
But after setting this property to null, a warning of CA3053 still shows up in FxCop.
So we suppress this error until the reporting for CA3053 has been updated to fix this issue.")]
public static XamlReader CreateReader(Stream stream)
{
if (stream == null)
{
throw FxTrace.Exception.ArgumentNull("stream");
}
return CreateReader(new XamlXmlReader(XmlReader.Create(stream, new XmlReaderSettings { XmlResolver = null }), dynamicActivityReaderSchemaContext), dynamicActivityReaderSchemaContext);
}
public static XamlReader CreateReader(XamlReader innerReader)
{
if (innerReader == null)
{
throw FxTrace.Exception.ArgumentNull("innerReader");
}
return new DynamicActivityXamlReader(innerReader);
}
public static XamlReader CreateReader(XamlReader innerReader, XamlSchemaContext schemaContext)
{
if (innerReader == null)
{
throw FxTrace.Exception.ArgumentNull("innerReader");
}
if (schemaContext == null)
{
throw FxTrace.Exception.ArgumentNull("schemaContext");
}
return new DynamicActivityXamlReader(innerReader, schemaContext);
}
public static XamlReader CreateBuilderReader(XamlReader innerReader)
{
if (innerReader == null)
{
throw FxTrace.Exception.ArgumentNull("innerReader");
}
return new DynamicActivityXamlReader(true, innerReader, null);
}
public static XamlReader CreateBuilderReader(XamlReader innerReader, XamlSchemaContext schemaContext)
{
if (innerReader == null)
{
throw FxTrace.Exception.ArgumentNull("innerReader");
}
if (schemaContext == null)
{
throw FxTrace.Exception.ArgumentNull("schemaContext");
}
return new DynamicActivityXamlReader(true, innerReader, schemaContext);
}
public static XamlWriter CreateBuilderWriter(XamlWriter innerWriter)
{
if (innerWriter == null)
{
throw FxTrace.Exception.ArgumentNull("innerWriter");
}
return new ActivityBuilderXamlWriter(innerWriter);
}
public static Func<object> CreateFactory(XamlReader reader, Type resultType)
{
if (reader == null)
{
throw FxTrace.Exception.ArgumentNull("reader");
}
if (resultType == null)
{
throw FxTrace.Exception.ArgumentNull("resultType");
}
return FuncFactory.CreateFunc(reader, resultType);
}
public static Func<T> CreateFactory<T>(XamlReader reader) where T : class
{
if (reader == null)
{
throw FxTrace.Exception.ArgumentNull("reader");
}
return FuncFactory.CreateFunc<T>(reader);
}
static void Compile(IDynamicActivity dynamicActivity, LocationReferenceEnvironment environment)
{
string language = null;
if (RequiresCompilation(dynamicActivity, environment, out language))
{
TextExpressionCompiler compiler = new TextExpressionCompiler(GetCompilerSettings(dynamicActivity, language));
TextExpressionCompilerResults results = compiler.Compile();
if (results.HasErrors)
{
StringBuilder messages = new StringBuilder();
messages.Append("\r\n");
messages.Append("\r\n");
foreach (TextExpressionCompilerError message in results.CompilerMessages)
{
messages.Append("\t");
if (results.HasSourceInfo)
{
messages.Append(string.Concat(" ", SR.ActivityXamlServiceLineString, " ", message.SourceLineNumber, ": "));
}
messages.Append(message.Message);
}
messages.Append("\r\n");
messages.Append("\r\n");
InvalidOperationException exception = new InvalidOperationException(SR.ActivityXamlServicesCompilationFailed(messages.ToString()));
foreach (TextExpressionCompilerError message in results.CompilerMessages)
{
exception.Data.Add(message, message.Message);
}
throw FxTrace.Exception.AsError(exception);
}
Type compiledExpressionRootType = results.ResultType;
ICompiledExpressionRoot compiledExpressionRoot = Activator.CreateInstance(compiledExpressionRootType, new object[] { dynamicActivity }) as ICompiledExpressionRoot;
CompiledExpressionInvoker.SetCompiledExpressionRootForImplementation(dynamicActivity, compiledExpressionRoot);
}
}
static bool RequiresCompilation(IDynamicActivity dynamicActivity, LocationReferenceEnvironment environment, out string language)
{
language = null;
if (!((Activity)dynamicActivity).IsMetadataCached)
{
IList<ValidationError> validationErrors = null;
if (environment == null)
{
environment = new ActivityLocationReferenceEnvironment();
}
try
{
ActivityUtilities.CacheRootMetadata((Activity)dynamicActivity, environment, ProcessActivityTreeOptions.FullCachingOptions, null, ref validationErrors);
}
catch (Exception e)
{
if (Fx.IsFatal(e))
{
throw;
}
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CompiledExpressionsCacheMetadataException(dynamicActivity.Name, e.ToString())));
}
}
DynamicActivityVisitor vistor = new DynamicActivityVisitor();
vistor.Visit((Activity)dynamicActivity, true);
if (!vistor.RequiresCompilation)
{
return false;
}
if (vistor.HasLanguageConflict)
{
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.DynamicActivityMultipleExpressionLanguages(vistor.GetConflictingLanguages().AsCommaSeparatedValues())));
}
language = vistor.Language;
return true;
}
static TextExpressionCompilerSettings GetCompilerSettings(IDynamicActivity dynamicActivity, string language)
{
int lastIndexOfDot = dynamicActivity.Name.LastIndexOf('.');
int lengthOfName = dynamicActivity.Name.Length;
string activityName = lastIndexOfDot > 0 ? dynamicActivity.Name.Substring(lastIndexOfDot + 1) : dynamicActivity.Name;
activityName += "_CompiledExpressionRoot";
string activityNamespace = lastIndexOfDot > 0 ? dynamicActivity.Name.Substring(0, lastIndexOfDot) : null;
return new TextExpressionCompilerSettings()
{
Activity = (Activity)dynamicActivity,
ActivityName = activityName,
ActivityNamespace = activityNamespace,
RootNamespace = null,
GenerateAsPartialClass = false,
AlwaysGenerateSource = true,
Language = language
};
}
[Fx.Tag.SecurityNote(Critical = "Critical because we use SecurityCritical methods that do Asserts.",
Safe = "Safe because no critical resources are leaked. And we guarantee that the XAML we are accessing is coming from the assembly to which we are asserting access.")]
[SecuritySafeCritical]
public static void InitializeComponent(
Type componentType,
Object componentInstance
)
{
if (componentType == null)
{
throw FxTrace.Exception.AsError(new ArgumentNullException("componentType"));
}
if (componentInstance == null)
{
throw FxTrace.Exception.AsError(new ArgumentNullException("componentInstance"));
}
Assembly typesAssembly = componentType.Assembly;
// Get the set of resources from the type's assembly.
string typeName = componentType.Name;
string typeNamespace = componentType.Namespace;
string[] resources = typesAssembly.GetManifestResourceNames();
// Look for the special resource that is generated by the BeforeInitializeComponentExtension.
string beforeInitializeResourceName;
if (string.IsNullOrWhiteSpace(typeNamespace))
{
beforeInitializeResourceName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}.{2}", typeName, "BeforeInitializeComponentHelper", "txt");
}
else
{
beforeInitializeResourceName = string.Format(CultureInfo.InvariantCulture, "{0}_{1}_{2}.{3}", typeNamespace, typeName, "BeforeInitializeComponentHelper", "txt");
}
string beforeInitializeResource = FindResource(resources, beforeInitializeResourceName);
if (beforeInitializeResource == null)
{
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.BeforeInitializeComponentXBTExtensionResourceNotFound));
}
// Get the name of the XAML resource from the BeforeInitializeComponentHelper resource.
string xamlResourceName = null;
string helperClassName = null;
GetContentsOfBeforeInitializeExtensionResource(typesAssembly, beforeInitializeResource, out xamlResourceName, out helperClassName);
// Now look for the resource containing the XAML.
string fullXamlResourceName = FindResource(resources, xamlResourceName);
if (fullXamlResourceName == null)
{
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.XamlBuildTaskResourceNotFound(xamlResourceName)));
}
// Get the schema context for the type.
XamlSchemaContext typeSchemaContext = GetXamlSchemaContext(typesAssembly, helperClassName);
InitializeComponentFromXamlResource(componentType, fullXamlResourceName, componentInstance, typeSchemaContext);
}
static string FindResource(string[] resources, string partialResourceName)
{
bool foundResourceString = false;
int resourceIndex;
for (resourceIndex = 0; (resourceIndex < resources.Length); resourceIndex = (resourceIndex + 1))
{
string resource = resources[resourceIndex];
if ((resource.Contains("." + partialResourceName) || resource.Equals(partialResourceName)))
{
foundResourceString = true;
break;
}
}
if (!foundResourceString)
{
return null;
}
return resources[resourceIndex];
}
static void GetContentsOfBeforeInitializeExtensionResource(Assembly assembly, string resource, out string xamlResourceName, out string helperClassName)
{
Stream beforeInitializeStream = assembly.GetManifestResourceStream(resource);
using (StreamReader beforeInitializeReader = new StreamReader(beforeInitializeStream))
{
xamlResourceName = beforeInitializeReader.ReadLine();
helperClassName = beforeInitializeReader.ReadLine();
}
}
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.SecureAsserts,
Justification = "The schema context is not critical data because it is exposed through the assembly manifest and we are asserting to go get that data.")]
[Fx.Tag.SecurityNote(Critical = "Critical because it Asserts ReflectionPermission(MemberAccess) to the calling assembly.")]
[SecurityCritical]
static XamlSchemaContext GetXamlSchemaContext(Assembly assembly, string helperClassName)
{
XamlSchemaContext typeSchemaContext = null;
ReflectionPermission reflectionPerm = new ReflectionPermission(ReflectionPermissionFlag.MemberAccess);
reflectionPerm.Assert();
try
{
Type schemaContextType = assembly.GetType(helperClassName);
if (schemaContextType == null)
{
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.SchemaContextFromBeforeInitializeComponentXBTExtensionNotFound(helperClassName)));
}
// The "official" BeforeInitializeComponent XBT Extension will not create a generic type for this helper class.
// This check is here so that the assembly manifest can't lure us into creating a type with a generic argument from a different assembly.
if (schemaContextType.IsGenericType || schemaContextType.IsGenericTypeDefinition)
{
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.SchemaContextFromBeforeInitializeComponentXBTExtensionCannotBeGeneric(helperClassName)));
}
PropertyInfo schemaContextPropertyInfo = schemaContextType.GetProperty("SchemaContext",
BindingFlags.NonPublic | BindingFlags.Static);
typeSchemaContext = (XamlSchemaContext)schemaContextPropertyInfo.GetValue(null,
BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetProperty, null, null, null);
}
finally
{
CodeAccessPermission.RevertAssert();
}
return typeSchemaContext;
}
[SuppressMessage(FxCop.Category.Security, "CA2103:ReviewImperativeSecurity",
Justification = "Passing XamlAccessLevel to XamlLoadPermission is okay.")]
[SuppressMessage(FxCop.Category.Security, FxCop.Rule.SecureAsserts,
Justification = "We are asserting to get private access to the componentType only so that we can initialize it.")]
[SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver",
Justification = @"For the call to XmlReader.Create() below, CA3053 recommends setting the
XmlReaderSettings.XmlResolver property to either null or an instance of XmlSecureResolver.
But after setting this property to null, a warning of CA3053 still shows up in FxCop.
So we suppress this error until the reporting for CA3053 has been updated to fix this issue.")]
[Fx.Tag.SecurityNote(Critical = "Critical because it Asserts XamlLoadPermission(XamlAccessLevel.PrivateAccessTo(type).")]
[SecurityCritical]
static void InitializeComponentFromXamlResource(Type componentType, string resource, object componentInstance, XamlSchemaContext schemaContext)
{
Stream initializeXaml = componentType.Assembly.GetManifestResourceStream(resource);
XmlReader xmlReader = null;
XamlReader reader = null;
XamlObjectWriter objectWriter = null;
try
{
xmlReader = XmlReader.Create(initializeXaml, new XmlReaderSettings { XmlResolver = null });
XamlXmlReaderSettings readerSettings = new XamlXmlReaderSettings();
readerSettings.LocalAssembly = componentType.Assembly;
readerSettings.AllowProtectedMembersOnRoot = true;
reader = new XamlXmlReader(xmlReader, schemaContext, readerSettings);
XamlObjectWriterSettings writerSettings = new XamlObjectWriterSettings();
writerSettings.RootObjectInstance = componentInstance;
writerSettings.AccessLevel = XamlAccessLevel.PrivateAccessTo(componentType);
objectWriter = new XamlObjectWriter(schemaContext, writerSettings);
// We need the XamlLoadPermission for the assembly we are dealing with.
XamlLoadPermission perm = new XamlLoadPermission(XamlAccessLevel.PrivateAccessTo(componentType));
perm.Assert();
try
{
XamlServices.Transform(reader, objectWriter);
}
finally
{
CodeAccessPermission.RevertAssert();
}
}
finally
{
if ((xmlReader != null))
{
((IDisposable)(xmlReader)).Dispose();
}
if ((reader != null))
{
((IDisposable)(reader)).Dispose();
}
if ((objectWriter != null))
{
((IDisposable)(objectWriter)).Dispose();
}
}
}
class DynamicActivityReaderSchemaContext : XamlSchemaContext
{
static bool serviceModelLoaded;
const string serviceModelDll = "System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
const string serviceModelActivitiesDll = "System.ServiceModel.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
const string serviceModelNamespace = "http://schemas.microsoft.com/netfx/2009/xaml/servicemodel";
// Eventually this will be unnecessary since XAML team has changed the default behavior
public DynamicActivityReaderSchemaContext()
: base(new XamlSchemaContextSettings())
{
}
protected override XamlType GetXamlType(string xamlNamespace, string name, params XamlType[] typeArguments)
{
XamlType xamlType = base.GetXamlType(xamlNamespace, name, typeArguments);
if (xamlType == null)
{
if (xamlNamespace == serviceModelNamespace && !serviceModelLoaded)
{
Assembly.Load(serviceModelDll);
Assembly.Load(serviceModelActivitiesDll);
serviceModelLoaded = true;
xamlType = base.GetXamlType(xamlNamespace, name, typeArguments);
}
}
return xamlType;
}
}
class DynamicActivityVisitor : CompiledExpressionActivityVisitor
{
ISet<string> languages;
public string Language
{
get
{
if (this.languages == null || this.languages.Count == 0 || this.languages.Count > 1)
{
return null;
}
IEnumerator<string> languagesEnumerator = this.languages.GetEnumerator();
if (languagesEnumerator.MoveNext())
{
return languagesEnumerator.Current;
}
return null;
}
}
public bool RequiresCompilation
{
get;
private set;
}
public bool HasLanguageConflict
{
get
{
return this.languages != null && this.languages.Count > 1;
}
}
public IEnumerable<string> GetConflictingLanguages()
{
if (this.languages.Count > 1)
{
return this.languages;
}
else
{
return null;
}
}
protected override void VisitITextExpression(Activity activity, out bool exit)
{
ITextExpression textExpression = activity as ITextExpression;
if (textExpression != null)
{
if (textExpression.RequiresCompilation)
{
this.RequiresCompilation = true;
if (this.languages == null)
{
this.languages = new HashSet<string>();
}
if (!this.languages.Contains(textExpression.Language))
{
this.languages.Add(textExpression.Language);
}
}
}
base.VisitITextExpression(activity, out exit);
}
}
}
}