本文整理汇总了C#中Binder类的典型用法代码示例。如果您正苦于以下问题:C# Binder类的具体用法?C# Binder怎么用?C# Binder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Binder类属于命名空间,在下文中一共展示了Binder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldBindBetweenIndexedObjects
public void ShouldBindBetweenIndexedObjects()
{
var binder = new Binder<ObservableDictionary<UniversalStub>>();
var dict= new ObservableDictionary<UniversalStub>();
binder.BindIf(x => x.ContainsKey("first") && x.ContainsKey("second"), x => x["first"].String).To(x => x["second"].String);
using (binder.Attach(dict))
{
var first = new UniversalStub();
var second = new UniversalStub { String = "a" };
dict.Add("second", second);
second.String.ShouldBe("a");
using (second.VerifyChangedOnce("String"))
{
dict.Add("first", first);
}
second.String.ShouldBe(null);
using (second.VerifyChangedOnce("String"))
{
first.String = "b";
}
second.String.ShouldBe("b");
}
}
示例2: InvokeMember
public Object InvokeMember(String name, BindingFlags flags, Binder binder, Object target,
Object[] args, ParameterModifier[] modifiers, CultureInfo locale, String[] namedParameters){
if ((flags & BindingFlags.CreateInstance) == 0)
//Try to create an instance of the array
return LateBinding.CallValue(this.elementType, args, true, true, null, null, binder, locale, namedParameters);
return Typeob.Array.InvokeMember(name, flags, binder, target, args, modifiers, locale, namedParameters);
}
示例3: WithTypeArgumentsBinder
internal WithTypeArgumentsBinder(ImmutableArray<TypeSymbol> typeArguments, Binder next)
: base(next)
{
Debug.Assert(!typeArguments.IsDefaultOrEmpty);
Debug.Assert(typeArguments.All(ta => ta.Kind == SymbolKind.TypeParameter));
_typeArguments = typeArguments;
}
示例4: Invoke
public override object Invoke(object obj, BindingFlags options, Binder binder, object[] parameters, CultureInfo culture)
{
MethodInfo method = TypeReferences.ToExecutionContext(this.method);
if (binder != null)
{
try
{
return method.Invoke(obj, options, binder, parameters, culture);
}
catch (TargetInvocationException exception)
{
throw exception.InnerException;
}
}
MethodInvoker methodInvoker = this.methodInvoker;
if ((methodInvoker == null) && ((this.methodInvoker = MethodInvoker.GetInvokerFor(method)) == null))
{
try
{
return method.Invoke(obj, options, binder, parameters, culture);
}
catch (TargetInvocationException exception2)
{
throw exception2.InnerException;
}
}
return methodInvoker.Invoke(obj, parameters);
}
示例5: SourceStrictComplexParameterSymbol
internal SourceStrictComplexParameterSymbol(
DiagnosticBag diagnostics,
Binder binder,
Symbol owner,
int ordinal,
TypeSymbol parameterType,
RefKind refKind,
string name,
ImmutableArray<Location> locations,
SyntaxReference syntaxRef,
ConstantValue defaultSyntaxValue,
bool isParams,
bool isExtensionMethodThis)
: base(
owner: owner,
ordinal: ordinal,
parameterType: parameterType,
refKind: refKind,
name: name,
locations: locations,
syntaxRef: syntaxRef,
defaultSyntaxValue: defaultSyntaxValue,
isParams: isParams,
isExtensionMethodThis: isExtensionMethodThis)
{
_tempBinder = binder;
var unused = GetAttributesBag(diagnostics);
_lazyDefaultSyntaxValue = MakeDefaultExpression(diagnostics, binder);
_tempBinder = null; // no need to keep it around anymore, just uses up a lot of memory
}
示例6: TestAfterInject
public void TestAfterInject()
{
var eventCalled = false;
IReflectionCache cache = new ReflectionCache();
IBinder binder = new Binder();
IInjector injector = new Injector(cache, binder);
var instanceToInject = new MockClassVerySimple();
injector.afterInject += delegate(IInjector source, ref object instance, ReflectedClass reflectedClass) {
//The if below is just to avoid checking when injecting on MockIClass.
if (reflectedClass.type != typeof(MockClassVerySimple)) return;
Assert.AreEqual(injector, source);
Assert.AreEqual(instanceToInject, instance);
Assert.AreEqual(typeof(MockIClass), instanceToInject.field.GetType());
eventCalled = true;
};
binder.Bind<IMockInterface>().To<MockIClass>();
injector.Inject(instanceToInject);
Assert.IsTrue(eventCalled);
}
示例7: PlaceholderLocalBinder
internal PlaceholderLocalBinder(
CSharpSyntaxNode syntax,
ImmutableArray<Alias> aliases,
MethodSymbol containingMethod,
EETypeNameDecoder typeNameDecoder,
Binder next) :
base(next)
{
_syntax = syntax;
_containingMethod = containingMethod;
var compilation = next.Compilation;
var sourceAssembly = compilation.SourceAssembly;
var aliasesBuilder = ArrayBuilder<LocalSymbol>.GetInstance(aliases.Length);
var lowercaseBuilder = ImmutableDictionary.CreateBuilder<string, LocalSymbol>();
foreach (Alias alias in aliases)
{
var local = PlaceholderLocalSymbol.Create(
typeNameDecoder,
containingMethod,
sourceAssembly,
alias);
aliasesBuilder.Add(local);
if (alias.Kind == DkmClrAliasKind.ReturnValue)
{
lowercaseBuilder.Add(local.Name.ToLower(), local);
}
}
_lowercaseReturnValueAliases = lowercaseBuilder.ToImmutableDictionary();
_aliases = aliasesBuilder.ToImmutableAndFree();
}
示例8: LookupSymbolsInSingleBinder
internal sealed override void LookupSymbolsInSingleBinder(
LookupResult result,
string name,
int arity,
ConsList<Symbol> basesBeingResolved,
LookupOptions options,
Binder originalBinder,
bool diagnose,
ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
if ((options & (LookupOptions.NamespaceAliasesOnly | LookupOptions.NamespacesOrTypesOnly | LookupOptions.LabelsOnly)) != 0)
{
return;
}
var local = this.LookupPlaceholder(name);
if ((object)local == null)
{
base.LookupSymbolsInSingleBinder(result, name, arity, basesBeingResolved, options, originalBinder, diagnose, ref useSiteDiagnostics);
}
else
{
result.MergeEqual(this.CheckViability(local, arity, options, null, diagnose, ref useSiteDiagnostics, basesBeingResolved));
}
}
示例9: TestBinding
public void TestBinding()
{
Binder binder = new Binder();
var equivalent = new EventEquivalent();
binder.Bind(new SampleEvent1(), new MethodHandler<SampleEvent1>(OnSampleEvent1));
var e1 = new SampleEvent1();
var e2 = new SampleEvent1 { Foo = 1 };
var e3 = new SampleEvent1 { Foo = 1, Bar = "bar" };
List<Handler> handlerChain = new List<Handler>();
handlerChain.Clear();
Assert.AreEqual(1, binder.BuildHandlerChain(e1, equivalent, handlerChain));
Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSampleEvent1), handlerChain[0]);
handlerChain.Clear();
Assert.AreEqual(1, binder.BuildHandlerChain(e2, equivalent, handlerChain));
Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSampleEvent1), handlerChain[0]);
handlerChain.Clear();
Assert.AreEqual(1, binder.BuildHandlerChain(e3, equivalent, handlerChain));
Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSampleEvent1), handlerChain[0]);
binder.Unbind(new SampleEvent1(), new MethodHandler<SampleEvent1>(OnSampleEvent1));
handlerChain.Clear();
Assert.AreEqual(0, binder.BuildHandlerChain(e1, equivalent, handlerChain));
handlerChain.Clear();
Assert.AreEqual(0, binder.BuildHandlerChain(e2, equivalent, handlerChain));
handlerChain.Clear();
Assert.AreEqual(0, binder.BuildHandlerChain(e3, equivalent, handlerChain));
}
示例10: TestDuplicateUnbinding
public void TestDuplicateUnbinding()
{
Binder binder = new Binder();
var equivalent = new EventEquivalent();
List<Handler> handlerChain = new List<Handler>();
binder.Bind(new SampleEvent1 { Foo = 1 }, new MethodHandler<SampleEvent1>(OnSampleEvent1));
binder.Bind(new SampleEvent1 { Foo = 2 }, new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1));
binder.Unbind(new SampleEvent1 { Foo = 1 }, new MethodHandler<SampleEvent1>(OnSampleEvent1));
binder.Unbind(new SampleEvent1 { Foo = 1 }, new MethodHandler<SampleEvent1>(OnSampleEvent1));
handlerChain.Clear();
Assert.AreEqual(0, binder.BuildHandlerChain(new SampleEvent1 { Foo = 1 }, equivalent, handlerChain));
Assert.AreEqual(1, binder.BuildHandlerChain(new SampleEvent1 { Foo = 2 }, equivalent, handlerChain));
Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1), handlerChain[0]);
// with EventSink
var sink = new SampleEventSink();
sink.Bind(new SampleEvent1 { Foo = 1 }, sink.OnSampleEvent1);
sink.Unbind(new SampleEvent1 { Foo = 1 }, sink.OnSampleEvent1);
sink.Bind(new SampleEvent1 { Foo = 1 }, sink.OnSampleEvent1);
handlerChain.Clear();
Assert.AreEqual(0, binder.BuildHandlerChain(new SampleEvent1 { Foo = 1 }, equivalent, handlerChain));
Assert.AreEqual(1, binder.BuildHandlerChain(new SampleEvent1 { Foo = 2 }, equivalent, handlerChain));
Assert.AreEqual(new MethodHandler<SampleEvent1>(OnSpecificSampleEvent1), handlerChain[0]);
}
示例11: Call
internal override object Call(object[] args, object thisob, Binder binder, CultureInfo culture)
{
if (this.func.isExpandoMethod)
{
((Microsoft.JScript.StackFrame) this.enclosing_scope).thisObject = thisob;
}
else if ((this.declaringObject != null) && !(this.declaringObject is ClassScope))
{
thisob = this.declaringObject;
}
if (thisob == null)
{
thisob = ((IActivationObject) base.engine.ScriptObjectStackTop()).GetDefaultThisObject();
}
if ((this.enclosing_scope is ClassScope) && (this.declaringObject == null))
{
if (thisob is Microsoft.JScript.StackFrame)
{
thisob = ((Microsoft.JScript.StackFrame) thisob).closureInstance;
}
if (!this.func.isStatic && !((ClassScope) this.enclosing_scope).HasInstance(thisob))
{
throw new JScriptException(JSError.InvalidCall);
}
}
return this.func.Call(args, thisob, this.enclosing_scope, this, binder, culture);
}
示例12: TestAfterResolve
public void TestAfterResolve()
{
var eventCalled = false;
IReflectionCache cache = new ReflectionCache();
IBinder binder = new Binder();
IInjector injector = new Injector(cache, binder);
IMockInterface resolvedInstance = null;
injector.afterResolve += delegate(IInjector source,
Type type,
InjectionMember member,
object parentInstance,
object identifier,
ref object resolutionInstance) {
Assert.AreEqual(injector, source);
Assert.AreEqual(typeof(IMockInterface), type);
Assert.AreEqual(InjectionMember.None, member);
Assert.IsNull(parentInstance);
Assert.IsNull(identifier);
Assert.IsNotNull(resolutionInstance);
resolvedInstance = (IMockInterface)resolutionInstance;
eventCalled = true;
return false;
};
binder.Bind<IMockInterface>().To<MockIClass>();
var instance = injector.Resolve<IMockInterface>();
Assert.IsTrue(eventCalled);
Assert.AreEqual(typeof(MockIClass), instance.GetType());
Assert.AreEqual(resolvedInstance, instance);
}
示例13: GetPropertyImpl
protected sealed override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
{
Debug.Assert(name != null);
if (!OnlySearchRelatedBitsSet(bindingAttr)) // We don't yet have proper handling for BindingFlags not related to search so throw rather return a wrong result.
throw new NotImplementedException();
// GetPropertyImpl() is a funnel for two groups of api. We can distinguish by comparing "types" to null.
if (types == null && returnType == null)
{
// Group #1: This group of api accept only a name and BindingFlags. The other parameters are hard-wired by the non-virtual api entrypoints.
Debug.Assert(binder == null);
Debug.Assert(modifiers == null);
return LowLevelTypeExtensions.GetProperty(this, name, bindingAttr);
}
else
{
if (!OnlySearchRelatedBitsSet(bindingAttr)) // We don't yet have proper handling for BindingFlags not related to search so throw rather return a wrong result.
throw new NotImplementedException();
// Group #2: This group of api takes a set of parameter types, a return type (both cannot be null) and an optional binder.
if (binder == null)
binder = Type.DefaultBinder;
PropertyInfo[] candidates = LowLevelTypeExtensions.GetProperties(this, name, bindingAttr);
return binder.SelectProperty(bindingAttr, candidates, returnType, types, modifiers);
}
}
示例14: TestBindNotAssignableKeyTypeToInstance
public void TestBindNotAssignableKeyTypeToInstance()
{
var binder = new Binder();
var instance = new MockClassToDepend();
binder.Bind<IMockInterface>().To<MockClassToDepend>(instance);
}
示例15: TestBindNotAssignableInstanceTypeToInstance
public void TestBindNotAssignableInstanceTypeToInstance()
{
var binder = new Binder();
var instance = new MockClassToDepend();
binder.Bind<MockClassToDepend>().To(typeof(MockClassVerySimple), instance);
}