本文整理汇总了C#中MockMetadataImporter类的典型用法代码示例。如果您正苦于以下问题:C# MockMetadataImporter类的具体用法?C# MockMetadataImporter怎么用?C# MockMetadataImporter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockMetadataImporter类属于命名空间,在下文中一共展示了MockMetadataImporter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StaticManualEventsWithAddRemoveMethodsAreCorrectlyImported
public void StaticManualEventsWithAddRemoveMethodsAreCorrectlyImported() {
var metadataImporter = new MockMetadataImporter { GetEventSemantics = f => EventScriptSemantics.AddAndRemoveMethods(MethodScriptSemantics.NormalMethod("add_" + f.Name), MethodScriptSemantics.NormalMethod("remove_" + f.Name)) };
Compile(new[] { "class C { public static event System.EventHandler SomeProp { add {} remove{} } }" }, metadataImporter: metadataImporter);
FindStaticMethod("C.add_SomeProp").Should().NotBeNull();
FindStaticMethod("C.remove_SomeProp").Should().NotBeNull();
}
示例2: ShadowingMethodsAreIncluded
public void ShadowingMethodsAreIncluded() {
var metadataImporter = new MockMetadataImporter { GetMethodSemantics = m => MethodScriptSemantics.NormalMethod(m.DeclaringType.Name == "C" ? "XDerived" : m.Name) };
Compile(new[] { "class B { public void X(); } class C : B { public new void X() {} }" }, metadataImporter: metadataImporter);
var cls = FindClass("C");
cls.InstanceMethods.Should().HaveCount(1);
cls.InstanceMethods[0].Name.Should().Be("XDerived");
}
示例3: ReadOnlyNativeIndexerIsCorrectlyImported
public void ReadOnlyNativeIndexerIsCorrectlyImported()
{
var metadataImporter = new MockMetadataImporter { GetPropertySemantics = p => PropertyScriptSemantics.NativeIndexer() };
Compile(new[] { "class C { public int this[int i] { get { return 0; } } }" }, metadataImporter: metadataImporter);
FindClass("C").InstanceMethods.Should().BeEmpty();
FindClass("C").StaticMethods.Should().BeEmpty();
}
示例4: InstanceAutoPropertiesThatShouldBeInstanceFieldsAreCorrectlyImported
public void InstanceAutoPropertiesThatShouldBeInstanceFieldsAreCorrectlyImported() {
var metadataImporter = new MockMetadataImporter { GetPropertySemantics = p => PropertyScriptSemantics.Field("$" + p.Name) };
Compile(new[] { "class C { public string SomeProp { get; set; } }" }, metadataImporter: metadataImporter);
FindClass("C").InstanceMethods.Should().BeEmpty();
FindClass("C").StaticMethods.Should().BeEmpty();
FindInstanceFieldInitializer("C.$SomeProp").Should().NotBeNull();
}
示例5: CannotUseNotUsableTypeAsAGenericArgument
public void CannotUseNotUsableTypeAsAGenericArgument()
{
var nc = new MockMetadataImporter { GetTypeSemantics = t => t.Name == "C1" ? TypeScriptSemantics.NotUsableFromScript() : TypeScriptSemantics.NormalType(t.Name) };
var er = new MockErrorReporter(false);
Compile(new[] {
@"class C1 {}
class C {
public void F1<T>() {}
public void M() {
F1<C1>();
}
}" }, metadataImporter: nc, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText[0].Contains("not usable from script") && er.AllMessagesText[0].Contains("generic argument") && er.AllMessagesText[0].Contains("C1") && er.AllMessagesText[0].Contains("F1"));
er = new MockErrorReporter(false);
Compile(new[] {
@"class C1 {}
interface I1<T> {}
class C {
public void F1<T>() {}
public void M() {
F1<I1<I1<C1>>>();
}
}" }, metadataImporter: nc, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText[0].Contains("not usable from script") && er.AllMessagesText[0].Contains("generic argument") && er.AllMessagesText[0].Contains("C1") && er.AllMessagesText[0].Contains("F1"));
}
示例6: IndexerWithGetAndSetMethodsWithNoCodeIsCorrectlyImported
public void IndexerWithGetAndSetMethodsWithNoCodeIsCorrectlyImported() {
var metadataImporter = new MockMetadataImporter { GetPropertySemantics = p => PropertyScriptSemantics.GetAndSetMethods(MethodScriptSemantics.NormalMethod("get_Item", generateCode: false), MethodScriptSemantics.NormalMethod("set_Item", generateCode: false)) };
Compile(new[] { "class C { public int this[int i] { get { return 0; } set {} } }" }, metadataImporter: metadataImporter);
FindInstanceMethod("C.get_Item").Should().BeNull();
FindInstanceMethod("C.set_Item").Should().BeNull();
FindClass("C").StaticMethods.Should().BeEmpty();
}
示例7: GenericMethodTypeArgumentsAreIgnoredForStaticMethodsIfTheMethodImplOptionsSaySo
public void GenericMethodTypeArgumentsAreIgnoredForStaticMethodsIfTheMethodImplOptionsSaySo()
{
var metadataImporter = new MockMetadataImporter { GetMethodSemantics = m => MethodScriptSemantics.NormalMethod("X", ignoreGenericArguments: true) };
var namer = new MockNamer { GetTypeParameterName = tp => "$$" + tp.Name };
Compile(new[] { "class C { public static void X<U, V>() {} }" }, metadataImporter: metadataImporter, namer: namer);
FindStaticMethod("C.X").TypeParameterNames.Should().BeEmpty();
}
示例8: IndexerThatIsNotUsableFromScriptIsNotImported
public void IndexerThatIsNotUsableFromScriptIsNotImported()
{
var metadataImporter = new MockMetadataImporter { GetPropertySemantics = p => PropertyScriptSemantics.NotUsableFromScript() };
Compile(new[] { "class C { public int this[int i] { get {} set {} } }" }, metadataImporter: metadataImporter);
FindClass("C").InstanceMethods.Should().BeEmpty();
FindClass("C").StaticMethods.Should().BeEmpty();
}
示例9: CannotUseNotUsableTypeInATypeOfExpression
public void CannotUseNotUsableTypeInATypeOfExpression()
{
var metadataImporter = new MockMetadataImporter { GetTypeSemantics = t => t.Name == "C1" ? TypeScriptSemantics.NotUsableFromScript() : TypeScriptSemantics.NormalType(t.Name) };
var er = new MockErrorReporter(false);
Compile(new[] {
@"class C1 {}
class C {
public void M() {
var t = typeof(C1);
}
}" }, metadataImporter: metadataImporter, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText[0].Contains("not usable from script") && er.AllMessagesText[0].Contains("typeof") && er.AllMessagesText[0].Contains("C1"));
er = new MockErrorReporter(false);
Compile(new[] {
@"class C1 {}
interface I1<T> {}
class C {
public void M() {
var t= typeof(I1<I1<C1>>);
}
}" }, metadataImporter: metadataImporter, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText[0].Contains("not usable from script") && er.AllMessagesText[0].Contains("typeof") && er.AllMessagesText[0].Contains("C1"));
}
示例10: IndexerAccessorsInInterfaceHaveNullDefinition
public void IndexerAccessorsInInterfaceHaveNullDefinition()
{
var metadataImporter = new MockMetadataImporter { GetPropertySemantics = p => PropertyScriptSemantics.GetAndSetMethods(MethodScriptSemantics.NormalMethod("get_Item"), MethodScriptSemantics.NormalMethod("set_Item")) };
Compile(new[] { "interface I { int this[int i] { get { return 0; } set {} } }" }, metadataImporter: metadataImporter);
FindInstanceMethod("I.get_Item").Should().NotBeNull();
FindInstanceMethod("I.set_Item").Should().NotBeNull();
}
示例11: AbstractIndexerHasANullDefinition
public void AbstractIndexerHasANullDefinition()
{
var metadataImporter = new MockMetadataImporter { GetPropertySemantics = p => PropertyScriptSemantics.GetAndSetMethods(MethodScriptSemantics.NormalMethod("get_Item"), MethodScriptSemantics.NormalMethod("set_Item")) };
Compile(new[] { "abstract class C { public abstract int this[int i] { get; set; } }" }, metadataImporter: metadataImporter);
FindInstanceMethod("C.get_Item").Definition.Should().BeNull();
FindInstanceMethod("C.set_Item").Definition.Should().BeNull();
}
示例12: WriteOnlyIndexerWithGetAndSetMethodsIsCorrectlyImported
public void WriteOnlyIndexerWithGetAndSetMethodsIsCorrectlyImported() {
var metadataImporter = new MockMetadataImporter { GetPropertySemantics = p => PropertyScriptSemantics.GetAndSetMethods(MethodScriptSemantics.NormalMethod("get_Item"), MethodScriptSemantics.NormalMethod("set_Item")) };
Compile(new[] { "class C { public int this[int i] { set {} } }" }, metadataImporter: metadataImporter);
FindInstanceMethod("C.get_Item").Should().BeNull();
FindInstanceMethod("C.set_Item").Should().NotBeNull();
FindClass("C").StaticMethods.Should().BeEmpty();
}
示例13: InstanceFieldsAreCorrectlyImported
public void InstanceFieldsAreCorrectlyImported() {
var metadataImporter = new MockMetadataImporter { GetFieldSemantics = f => FieldScriptSemantics.Field("$SomeProp") };
Compile(new[] { "class C { public int SomeField; }" }, metadataImporter: metadataImporter);
FindInstanceFieldInitializer("C.$SomeProp").Should().NotBeNull();
FindClass("C").StaticInitStatements.Should().BeEmpty();
FindClass("C").InstanceMethods.Should().BeEmpty();
FindClass("C").StaticMethods.Should().BeEmpty();
}
示例14: StaticFieldsAreCorrectlyImported
public void StaticFieldsAreCorrectlyImported() {
var metadataImporter = new MockMetadataImporter { GetConstructorSemantics = c => ConstructorScriptSemantics.Unnamed(skipInInitializer: c.DeclaringType.IsKnownType(KnownTypeCode.Object)) };
Compile(new[] { "class C { public static int SomeField; }" }, metadataImporter: metadataImporter);
FindStaticFieldInitializer("C.$SomeField").Should().NotBeNull();
FindClass("C").UnnamedConstructor.Body.Statements.Should().BeEmpty();
FindClass("C").InstanceMethods.Should().BeEmpty();
FindClass("C").StaticMethods.Should().BeEmpty();
}
示例15: InstanceAutoEventsWithAddRemoveMethodsWithNoCodeAreCorrectlyImported
public void InstanceAutoEventsWithAddRemoveMethodsWithNoCodeAreCorrectlyImported() {
var metadataImporter = new MockMetadataImporter { GetConstructorSemantics = c => ConstructorScriptSemantics.Unnamed(skipInInitializer: c.DeclaringType.IsKnownType(KnownTypeCode.Object)),
GetEventSemantics = e => EventScriptSemantics.AddAndRemoveMethods(MethodScriptSemantics.NormalMethod("add_" + e.Name, generateCode: false), MethodScriptSemantics.NormalMethod("remove_" + e.Name, generateCode: false)),
};
Compile(new[] { "class C { public event System.EventHandler SomeProp; }" }, metadataImporter: metadataImporter);
FindClass("C").InstanceMethods.Should().BeEmpty();
FindInstanceFieldInitializer("C.$SomeProp").Should().NotBeNull();
}